Skip to content

Commit

Permalink
Added a LoadBatchCompilation override that accepts a list of types
Browse files Browse the repository at this point in the history
  • Loading branch information
bounav committed Jul 10, 2024
1 parent 452fa92 commit d2f57e3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
2 changes: 0 additions & 2 deletions src/Spark/Compiler/BatchCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,6 @@ public Assembly Compile(bool debug, string languageOrExtension, string outputAss
this.AddNetCoreDefaultReferences();
#endif

// TODO: Is this needed?
//this.AddAssembly(typeof(System.Drawing.Color));
foreach(var assemblyLocation in settings.UseAssemblies)
{
// Assumes full path to assemblies
Expand Down
16 changes: 16 additions & 0 deletions src/Spark/ISparkViewEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//

using System;
using System.Collections.Generic;
using System.Reflection;
using Spark.FileSystem;
Expand All @@ -34,6 +36,20 @@ public interface ISparkViewEngine

Assembly BatchCompilation(IList<SparkViewDescriptor> descriptors);
Assembly BatchCompilation(string outputAssembly, IList<SparkViewDescriptor> descriptors);

/// <summary>
/// Get all the exported types in the assembly and loads the ones assignable from <see cref="ISparkView"/>.
/// </summary>
/// <param name="assembly"></param>
/// <seealso cref="LoadBatchCompilation(Type[])"/>
/// <returns>A list of <see cref="SparkViewDescriptor"/> for every loaded type.</returns>
IList<SparkViewDescriptor> LoadBatchCompilation(Assembly assembly);

/// <summary>
/// Loads the specified types (when assignable from <see cref="ISparkView"/>) into the <see cref="ICompiledViewHolder"/> implemenation.
/// </summary>
/// <param name="types"></param>
/// <returns>A list of <see cref="SparkViewDescriptor"/> for every loaded type.</returns>
IList<SparkViewDescriptor> LoadBatchCompilation(Type[] assembly);
}
}
20 changes: 19 additions & 1 deletion src/Spark/SparkViewEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,29 @@ public Assembly BatchCompilation(string outputAssembly, IList<SparkViewDescripto
return assembly;
}

/// <summary>
/// Get all the exported types in the assembly and loads the ones assignable from <see cref="ISparkView"/>.
/// </summary>
/// <param name="assembly"></param>
/// <seealso cref="LoadBatchCompilation(Type[])"/>
/// <returns>A list of <see cref="SparkViewDescriptor"/> for every loaded type.</returns>
public IList<SparkViewDescriptor> LoadBatchCompilation(Assembly assembly)
{
var exportedTypes = assembly.GetExportedTypes();

return LoadBatchCompilation(exportedTypes);
}

/// <summary>
/// Loads the specified types (when assignable from <see cref="ISparkView"/>) into the <see cref="ICompiledViewHolder"/> implemenation.
/// </summary>
/// <param name="types"></param>
/// <returns>A list of <see cref="SparkViewDescriptor"/> for every loaded type.</returns>
public IList<SparkViewDescriptor> LoadBatchCompilation(Type[] types)
{
var descriptors = new List<SparkViewDescriptor>();

foreach (var type in assembly.GetExportedTypes())
foreach (var type in types)
{
if (!typeof(ISparkView).IsAssignableFrom(type))
{
Expand Down

0 comments on commit d2f57e3

Please sign in to comment.