From 83e96bb2e385e43bc46decbdbdfec9da5c943dd4 Mon Sep 17 00:00:00 2001 From: IS4 Date: Sun, 11 Jun 2023 19:53:17 +0200 Subject: [PATCH] include type forwarders when looking for components (.NET Core only) --- SFI.Application/ComponentInspector.cs | 2 +- SFI.Application/Tools/Extensions.cs | 34 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 SFI.Application/Tools/Extensions.cs diff --git a/SFI.Application/ComponentInspector.cs b/SFI.Application/ComponentInspector.cs index 43927dcc..5d7a5011 100644 --- a/SFI.Application/ComponentInspector.cs +++ b/SFI.Application/ComponentInspector.cs @@ -203,7 +203,7 @@ protected virtual async ValueTask LoadIntoCollections(ComponentType compone /// The collection of all applicable component types. protected virtual IEnumerable 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)) diff --git a/SFI.Application/Tools/Extensions.cs b/SFI.Application/Tools/Extensions.cs new file mode 100644 index 00000000..59e112cd --- /dev/null +++ b/SFI.Application/Tools/Extensions.cs @@ -0,0 +1,34 @@ +using System; +using System.Reflection; + +namespace IS4.SFI.Application.Tools +{ + /// + /// Provides extension methods for application-related classes. + /// + public static class Extensions + { + static readonly Func getForwardedTypes; + + static Extensions() + { + var forwardedTypesMethod = typeof(Assembly).GetMethod("GetForwardedTypes", Type.EmptyTypes); + if(forwardedTypesMethod != null) + { + getForwardedTypes = (Func)Delegate.CreateDelegate(typeof(Func), forwardedTypesMethod); + }else{ + getForwardedTypes = _ => Array.Empty(); + } + } + + /// + /// Retrieves the collection of forwarded types in . + /// + /// The assembly to browse. + /// The array of types forwarded to another assembly. + public static Type[] GetForwardedTypes(this Assembly assembly) + { + return getForwardedTypes(assembly); + } + } +}