add generic Get and GetAll methods
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Reflection;
|
||||
using Pilz.Plugins.Advanced.Exceptions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Pilz.Plugins.Advanced;
|
||||
|
||||
@@ -193,7 +194,24 @@ public class PluginFeatureController
|
||||
|
||||
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)
|
||||
@@ -221,7 +239,7 @@ public class PluginFeatureController
|
||||
{
|
||||
public override IEnumerable<T> GetAll()
|
||||
{
|
||||
return controller.features.OfType<T>();
|
||||
return GetAll<T>();
|
||||
}
|
||||
|
||||
public override IEnumerable<T> Get(string moduleType)
|
||||
|
||||
Reference in New Issue
Block a user