simplify PluginManager a bit more
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
3
Pilz.Plugins/PluginManager{T}.cs
Normal file
3
Pilz.Plugins/PluginManager{T}.cs
Normal file
@@ -0,0 +1,3 @@
|
||||
namespace Pilz.Plugins;
|
||||
|
||||
public class PluginManager<TPluginInterface> : PluginManager<TPluginInterface, PluginRuntimeInfo> where TPluginInterface : class;
|
||||
@@ -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; }
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
10
Pilz.Plugins/PluginRuntimeInfo{T}.cs
Normal file
10
Pilz.Plugins/PluginRuntimeInfo{T}.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user