diff --git a/Pilz.Plugins.Advanced/Exceptions/PluginFeatureExceptions.cs b/Pilz.Plugins.Advanced/Exceptions/PluginFeatureExceptions.cs new file mode 100644 index 0000000..df882a1 --- /dev/null +++ b/Pilz.Plugins.Advanced/Exceptions/PluginFeatureExceptions.cs @@ -0,0 +1,5 @@ +namespace Pilz.Plugins.Advanced.Exceptions; + +public class PluginFeatureException : Exception; + +public class PluginFeatureNotFoundException : PluginFeatureException; diff --git a/Pilz.Plugins.Advanced/Pilz.Plugins.Advanced.csproj b/Pilz.Plugins.Advanced/Pilz.Plugins.Advanced.csproj index d407958..f8f6737 100644 --- a/Pilz.Plugins.Advanced/Pilz.Plugins.Advanced.csproj +++ b/Pilz.Plugins.Advanced/Pilz.Plugins.Advanced.csproj @@ -8,7 +8,7 @@ - 2.10.6 + 2.10.7 \ No newline at end of file diff --git a/Pilz.Plugins.Advanced/PluginFeatureController.cs b/Pilz.Plugins.Advanced/PluginFeatureController.cs index 024cd56..18f5ffb 100644 --- a/Pilz.Plugins.Advanced/PluginFeatureController.cs +++ b/Pilz.Plugins.Advanced/PluginFeatureController.cs @@ -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 GetAll() { - return controller.features.ToArray(); + return [.. controller.features]; + } + + public virtual IEnumerable GetAll() where T : PluginFeature + { + return controller.features.OfType(); + } + + public virtual T? Get() where T : PluginFeature + { + return GetAll().FirstOrDefault(); + } + + public virtual T? Get(bool throwIfNull) where T : PluginFeature + { + if (Get() is T feature) + return feature; + throw new PluginFeatureNotFoundException(); } public virtual IEnumerable Get(string featureType) @@ -221,7 +239,7 @@ public class PluginFeatureController { public override IEnumerable GetAll() { - return controller.features.OfType(); + return GetAll(); } public override IEnumerable Get(string moduleType)