simplify PluginManager a bit more

This commit is contained in:
Pilzinsel64
2024-11-11 08:46:24 +01:00
parent 9b7c38ea85
commit eca1a4c7ca
7 changed files with 28 additions and 19 deletions

View File

@@ -2,10 +2,10 @@
namespace Pilz.Plugins;
public class PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo> where TPluginInterface : class where TPluginRuntimeInfo : PluginRuntimeInfo<TPluginInterface>
public class PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo> where TPluginInterface : class where TPluginRuntimeInfo : PluginRuntimeInfo
{
internal List<TPluginRuntimeInfo> PluginsInternal { get; } = [];
public Assembly Assembly { get; internal set; }
public Assembly? Assembly { get; internal set; }
public PluginLoadStatus Status { get; internal set; }
public IEnumerable<TPluginRuntimeInfo> Plugins => PluginsInternal.AsReadOnly();
}

View File

@@ -1,6 +1,6 @@
namespace Pilz.Plugins;
public class PluginManager : PluginManager<IPlugin, PluginRuntimeInfo>
public class PluginManager : PluginManager<IPlugin>
{
public static PluginManager Instance { get; private set; } = new();
}

View File

@@ -2,7 +2,7 @@
namespace Pilz.Plugins;
public class PluginManager<TPluginInterface, TPluginRuntimeInfo> where TPluginInterface : class where TPluginRuntimeInfo : PluginRuntimeInfo<TPluginInterface>
public class PluginManager<TPluginInterface, TPluginRuntimeInfo> where TPluginInterface : class where TPluginRuntimeInfo : PluginRuntimeInfo
{
protected readonly List<TPluginRuntimeInfo> loadedPlugins = [];
@@ -40,7 +40,7 @@ public class PluginManager<TPluginInterface, TPluginRuntimeInfo> where TPluginIn
/// <summary>
/// Loads plugins from the given assemblies.
/// </summary>
/// <param name="paths"></param>
/// <param name="assemblies"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public virtual IEnumerable<PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo>> LoadPlugins(Assembly[] assemblies, params object?[]? parameters)
@@ -65,7 +65,8 @@ public class PluginManager<TPluginInterface, TPluginRuntimeInfo> where TPluginIn
/// <summary>
/// Loads plugins from already loaded assemblies for the current <see cref="AppDomain.CurrentDomain"/>.
/// </summary>
/// <param name="listenAssemblyLoadContext">Do also load plugins from all yet not loaded assemblies by listening the event <see cref="AppDomain.AssemblyLoad"/>.
/// <param name="listenAssemblyLoadContext">Do also load plugins from all yet not loaded assemblies by listening the event <see cref="AppDomain.AssemblyLoad"/></param>
/// <param name="parameters"></param>>.
/// <returns></returns>
public virtual IEnumerable<PluginLoadInfo<TPluginInterface, TPluginRuntimeInfo>> LoadOwnPlugins(bool listenAssemblyLoadContext, params object?[]? parameters)
{

View File

@@ -0,0 +1,3 @@
namespace Pilz.Plugins;
public class PluginManager<TPluginInterface> : PluginManager<TPluginInterface, PluginRuntimeInfo> where TPluginInterface : class;

View File

@@ -1,5 +1,11 @@
namespace Pilz.Plugins;
using System.Reflection;
public class PluginRuntimeInfo : PluginRuntimeInfo<IPlugin>
namespace Pilz.Plugins;
public class PluginRuntimeInfo
{
public object? Plugin { get; internal set; }
public PluginStatus Status { get; internal set; }
public Assembly? Assembly { get; internal set; }
public Exception? Exception { get; internal set; }
}

View File

@@ -1,11 +0,0 @@
using System.Reflection;
namespace Pilz.Plugins;
public class PluginRuntimeInfo<T> where T : class
{
public T? Plugin { get; internal set; }
public PluginStatus Status { get; internal set; }
public Assembly? Assembly { get; internal set; }
public Exception? Exception { get; internal set; }
}

View File

@@ -0,0 +1,10 @@
namespace Pilz.Plugins;
public class PluginRuntimeInfo<T> : PluginRuntimeInfo where T : class
{
public new T? Plugin
{
get => base.Plugin as T;
set => base.Plugin = value;
}
}