Skip to content

Commit

Permalink
include type forwarders when looking for components (.NET Core only)
Browse files Browse the repository at this point in the history
  • Loading branch information
IS4Code committed Jun 11, 2023
1 parent 4885a89 commit 83e96bb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion SFI.Application/ComponentInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ protected virtual async ValueTask<int> LoadIntoCollections(ComponentType compone
/// <returns>The collection of all applicable component types.</returns>
protected virtual IEnumerable<ComponentType> OpenAssembly(Assembly assembly, IServiceProvider serviceProvider)
{
foreach(var type in assembly.ExportedTypes)
foreach(var type in assembly.ExportedTypes.Concat(assembly.GetForwardedTypes().Where(t => t.IsPublic)))
{
// Only yield concrete instantiable browsable types
if(!type.IsAbstract && !type.IsGenericTypeDefinition && IsTypeLoadable(type))
Expand Down
34 changes: 34 additions & 0 deletions SFI.Application/Tools/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Reflection;

namespace IS4.SFI.Application.Tools
{
/// <summary>
/// Provides extension methods for application-related classes.
/// </summary>
public static class Extensions
{
static readonly Func<Assembly, Type[]> getForwardedTypes;

static Extensions()
{
var forwardedTypesMethod = typeof(Assembly).GetMethod("GetForwardedTypes", Type.EmptyTypes);
if(forwardedTypesMethod != null)
{
getForwardedTypes = (Func<Assembly, Type[]>)Delegate.CreateDelegate(typeof(Func<Assembly, Type[]>), forwardedTypesMethod);
}else{
getForwardedTypes = _ => Array.Empty<Type>();
}
}

/// <summary>
/// Retrieves the collection of forwarded types in <paramref name="assembly"/>.
/// </summary>
/// <param name="assembly">The assembly to browse.</param>
/// <returns>The array of types forwarded to another assembly.</returns>
public static Type[] GetForwardedTypes(this Assembly assembly)
{
return getForwardedTypes(assembly);
}
}
}

0 comments on commit 83e96bb

Please sign in to comment.