add generic Get and GetAll methods
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
namespace Pilz.Plugins.Advanced.Exceptions;
|
||||||
|
|
||||||
|
public class PluginFeatureException : Exception;
|
||||||
|
|
||||||
|
public class PluginFeatureNotFoundException : PluginFeatureException;
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>2.10.6</Version>
|
<Version>2.10.7</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Reflection;
|
using Pilz.Plugins.Advanced.Exceptions;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace Pilz.Plugins.Advanced;
|
namespace Pilz.Plugins.Advanced;
|
||||||
|
|
||||||
@@ -193,7 +194,24 @@ public class PluginFeatureController
|
|||||||
|
|
||||||
public virtual IEnumerable<PluginFeature> GetAll()
|
public virtual IEnumerable<PluginFeature> GetAll()
|
||||||
{
|
{
|
||||||
return controller.features.ToArray();
|
return [.. controller.features];
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual IEnumerable<T> GetAll<T>() where T : PluginFeature
|
||||||
|
{
|
||||||
|
return controller.features.OfType<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual T? Get<T>() where T : PluginFeature
|
||||||
|
{
|
||||||
|
return GetAll<T>().FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual T? Get<T>(bool throwIfNull) where T : PluginFeature
|
||||||
|
{
|
||||||
|
if (Get<T>() is T feature)
|
||||||
|
return feature;
|
||||||
|
throw new PluginFeatureNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual IEnumerable<PluginFeature> Get(string featureType)
|
public virtual IEnumerable<PluginFeature> Get(string featureType)
|
||||||
@@ -221,7 +239,7 @@ public class PluginFeatureController
|
|||||||
{
|
{
|
||||||
public override IEnumerable<T> GetAll()
|
public override IEnumerable<T> GetAll()
|
||||||
{
|
{
|
||||||
return controller.features.OfType<T>();
|
return GetAll<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IEnumerable<T> Get(string moduleType)
|
public override IEnumerable<T> Get(string moduleType)
|
||||||
|
|||||||
Reference in New Issue
Block a user