add optional namespace filter

This commit is contained in:
Pilzinsel64
2024-11-11 08:17:59 +01:00
parent 8e9314365e
commit b9c390f645

View File

@@ -62,7 +62,7 @@ public class PluginFeatureController
/// Registers all features found in the currently executing Assembly via <see cref="IPluginFeatureProvider"/>, <see cref="IPluginFeatureProvider{T}"/> and <see cref="IPluginFeaturesProvider"/>. /// Registers all features found in the currently executing Assembly via <see cref="IPluginFeatureProvider"/>, <see cref="IPluginFeatureProvider{T}"/> and <see cref="IPluginFeaturesProvider"/>.
/// <para><b>Note:</b><br/>Explicit implementations of <see cref="IPluginFeatureProvider{T}.Instance"/> can not be detected. For this case just implement <see cref="IPluginFeatureProvider.Instance"/> instead.</para> /// <para><b>Note:</b><br/>Explicit implementations of <see cref="IPluginFeatureProvider{T}.Instance"/> can not be detected. For this case just implement <see cref="IPluginFeatureProvider.Instance"/> instead.</para>
/// </summary> /// </summary>
public void RegisterAllOwn() public void RegisterAllOwn(string? @namespace = null)
{ {
RegisterAll(Assembly.GetCallingAssembly()); RegisterAll(Assembly.GetCallingAssembly());
} }
@@ -71,8 +71,9 @@ public class PluginFeatureController
/// Registers all features found in the given <see cref="Assembly[]"/> via <see cref="IPluginFeatureProvider"/>, <see cref="IPluginFeatureProvider{T}"/> and <see cref="IPluginFeaturesProvider"/>. /// Registers all features found in the given <see cref="Assembly[]"/> via <see cref="IPluginFeatureProvider"/>, <see cref="IPluginFeatureProvider{T}"/> and <see cref="IPluginFeaturesProvider"/>.
/// <para><b>Note:</b><br/>Explicit implementations of <see cref="IPluginFeatureProvider{T}.Instance"/> can not be detected. For this case just implement <see cref="IPluginFeatureProvider.Instance"/> instead.</para> /// <para><b>Note:</b><br/>Explicit implementations of <see cref="IPluginFeatureProvider{T}.Instance"/> can not be detected. For this case just implement <see cref="IPluginFeatureProvider.Instance"/> instead.</para>
/// </summary> /// </summary>
/// <param name="assemblies"></param> /// <param name="assemblies">The assemblies to query for types.</param>
public void RegisterAll(Assembly[] assemblies) /// <param name="namespace">If not null, only types within the given namespace will be registered.</param>
public void RegisterAll(Assembly[] assemblies, string? @namespace = null)
{ {
foreach (var assembly in assemblies) foreach (var assembly in assemblies)
RegisterAll(assembly); RegisterAll(assembly);
@@ -82,8 +83,9 @@ public class PluginFeatureController
/// Registers all features found in the given <see cref="Assembly"/> via <see cref="IPluginFeatureProvider"/>, <see cref="IPluginFeatureProvider{T}"/> and <see cref="IPluginFeaturesProvider"/>. /// Registers all features found in the given <see cref="Assembly"/> via <see cref="IPluginFeatureProvider"/>, <see cref="IPluginFeatureProvider{T}"/> and <see cref="IPluginFeaturesProvider"/>.
/// <para><b>Note:</b><br/>Explicit implementations of <see cref="IPluginFeatureProvider{T}.Instance"/> can not be detected. For this case just implement <see cref="IPluginFeatureProvider.Instance"/> instead.</para> /// <para><b>Note:</b><br/>Explicit implementations of <see cref="IPluginFeatureProvider{T}.Instance"/> can not be detected. For this case just implement <see cref="IPluginFeatureProvider.Instance"/> instead.</para>
/// </summary> /// </summary>
/// <param name="assembly"></param> /// <param name="assembly">The assembly to query for types.</param>
public void RegisterAll(Assembly assembly) /// <param name="namespace">If not null, only types within the given namespace will be registered.</param>
public void RegisterAll(Assembly assembly, string? @namespace = null)
{ {
RegisterAll(assembly.GetTypes()); RegisterAll(assembly.GetTypes());
} }
@@ -92,8 +94,9 @@ public class PluginFeatureController
/// Registers all features found from the given <see cref="Type[]"/> via <see cref="IPluginFeatureProvider"/>, <see cref="IPluginFeatureProvider{T}"/> and <see cref="IPluginFeaturesProvider"/>. /// Registers all features found from the given <see cref="Type[]"/> via <see cref="IPluginFeatureProvider"/>, <see cref="IPluginFeatureProvider{T}"/> and <see cref="IPluginFeaturesProvider"/>.
/// <para><b>Note:</b><br/>Explicit implementations of <see cref="IPluginFeatureProvider{T}.Instance"/> can not be detected. For this case just implement <see cref="IPluginFeatureProvider.Instance"/> instead.</para> /// <para><b>Note:</b><br/>Explicit implementations of <see cref="IPluginFeatureProvider{T}.Instance"/> can not be detected. For this case just implement <see cref="IPluginFeatureProvider.Instance"/> instead.</para>
/// </summary> /// </summary>
/// <param name="types"></param> /// <param name="types">The types to query for providers.</param>
public void RegisterAll(Type[] types) /// <param name="namespace">If not null, the types will only be processed if they're within the given namespace.</param>
public void RegisterAll(Type[] types, string? @namespace = null)
{ {
foreach (var type in types) foreach (var type in types)
RegisterAll(type); RegisterAll(type);
@@ -103,9 +106,13 @@ public class PluginFeatureController
/// Registers all features found from the given <see cref="Type"/> via <see cref="IPluginFeatureProvider"/>, <see cref="IPluginFeatureProvider{T}"/> and <see cref="IPluginFeaturesProvider"/>. /// Registers all features found from the given <see cref="Type"/> via <see cref="IPluginFeatureProvider"/>, <see cref="IPluginFeatureProvider{T}"/> and <see cref="IPluginFeaturesProvider"/>.
/// <para><b>Note:</b><br/>Explicit implementations of <see cref="IPluginFeatureProvider{T}.Instance"/> can not be detected. For this case just implement <see cref="IPluginFeatureProvider.Instance"/> instead.</para> /// <para><b>Note:</b><br/>Explicit implementations of <see cref="IPluginFeatureProvider{T}.Instance"/> can not be detected. For this case just implement <see cref="IPluginFeatureProvider.Instance"/> instead.</para>
/// </summary> /// </summary>
/// <param name="type"></param> /// <param name="type">The type to query for providers.</param>
public void RegisterAll(Type type) /// <param name="namespace">If not null, the type will only be processed if it's within the given namespace.</param>
public void RegisterAll(Type type, string? @namespace = null)
{ {
if (@namespace != null && type.Namespace != null && type.Namespace != @namespace && !type.Namespace.StartsWith(@namespace + "."))
return;
if (type.IsAssignableTo(typeof(IPluginFeaturesProvider))) if (type.IsAssignableTo(typeof(IPluginFeaturesProvider)))
{ {
var methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); var methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);