wrapper for features & reduce dup code
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||||
<Version>2.1.0</Version>
|
<Version>2.2.0</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -17,14 +17,15 @@ namespace Pilz.Plugins.Advanced
|
|||||||
private readonly List<PluginFeature> features = new();
|
private readonly List<PluginFeature> features = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a collection of all registred <see cref="PluginFeature"/> instances.
|
/// A wrapper of all registred <see cref="PluginFeature"/> instances.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IReadOnlyList<PluginFeature> Features => features.AsReadOnly();
|
public FeatureController Features { get; init; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A wrapper for all registred <see cref="PluginModule"/> instances.
|
/// A wrapper for all registred <see cref="PluginModule"/> instances.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ModuleController Modules { get; init; }
|
public ModuleController Modules { get; init; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A wrapper for all registred <see cref="PluginFunction"/> instances.
|
/// A wrapper for all registred <see cref="PluginFunction"/> instances.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -32,6 +33,7 @@ namespace Pilz.Plugins.Advanced
|
|||||||
|
|
||||||
public PluginFeatureController()
|
public PluginFeatureController()
|
||||||
{
|
{
|
||||||
|
Features = new(this);
|
||||||
Functions = new(this);
|
Functions = new(this);
|
||||||
Modules = new(this);
|
Modules = new(this);
|
||||||
}
|
}
|
||||||
@@ -47,43 +49,64 @@ namespace Pilz.Plugins.Advanced
|
|||||||
features.Remove(module);
|
features.Remove(module);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ModuleController
|
public class FeatureController
|
||||||
{
|
{
|
||||||
private readonly PluginFeatureController controller;
|
protected readonly PluginFeatureController controller;
|
||||||
|
|
||||||
public ModuleController(PluginFeatureController controller)
|
public FeatureController(PluginFeatureController controller)
|
||||||
{
|
{
|
||||||
this.controller = controller;
|
this.controller = controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<PluginModule> GetAll()
|
public virtual IEnumerable<PluginFeature> GetAll()
|
||||||
{
|
{
|
||||||
return controller.features.OfType<PluginModule>();
|
return controller.features.AsReadOnly();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<PluginModule> Get(string moduleType)
|
public virtual IEnumerable<PluginFeature> Get(string moduleType)
|
||||||
{
|
{
|
||||||
return GetAll().Where(n => n.Type == moduleType);
|
return controller.features.Where(n => n.Type == moduleType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual PluginFeature? GetFirst(string moduleType)
|
||||||
|
{
|
||||||
|
return controller.features.FirstOrDefault(n => n.Type == moduleType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class FunctionController
|
public class FeatureController<T> : FeatureController where T : PluginFeature
|
||||||
{
|
{
|
||||||
private readonly PluginFeatureController controller;
|
public FeatureController(PluginFeatureController controller) : base(controller)
|
||||||
|
|
||||||
public FunctionController(PluginFeatureController controller)
|
|
||||||
{
|
{
|
||||||
this.controller = controller;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<PluginFunction> GetAll()
|
public override IEnumerable<T> GetAll()
|
||||||
{
|
{
|
||||||
return controller.features.OfType<PluginFunction>();
|
return controller.features.OfType<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<PluginFunction> Get(string functionType)
|
public override IEnumerable<T> Get(string moduleType)
|
||||||
|
{
|
||||||
|
return GetAll().Where(n => n.Type == moduleType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override T? GetFirst(string moduleType)
|
||||||
|
{
|
||||||
|
return GetAll().FirstOrDefault(n => n.Type == moduleType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ModuleController : FeatureController<PluginModule>
|
||||||
|
{
|
||||||
|
public ModuleController(PluginFeatureController controller) : base(controller)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FunctionController : FeatureController<PluginFunction>
|
||||||
|
{
|
||||||
|
public FunctionController(PluginFeatureController controller) : base(controller)
|
||||||
{
|
{
|
||||||
return GetAll().Where(n => n.Type == functionType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ExecuteAll(string functionType)
|
public void ExecuteAll(string functionType)
|
||||||
|
|||||||
Reference in New Issue
Block a user