namespace Pilz.Plugins.Advanced { public sealed class PluginFunctionController { public static PluginFunctionController Instance { get; private set; } = new(); private readonly List functions = new(); public IReadOnlyCollection Functions => functions.AsReadOnly(); public void RegisterFunction(PluginFunction function) { if (!functions.Contains(function)) functions.Add(function); } public void UnregisterFunction(PluginFunction function) { functions.Remove(function); } public IEnumerable GetFunctions(string functionType) { return functions.Where(n => n.Type == functionType); } public void ExecuteAll(string functionType) { foreach (var function in GetFunctions(functionType)) function.Execute(); } public void ExecuteAll(string functionType, params object?[]? @params) { foreach (var function in GetFunctions(functionType)) function.Execute(@params); } public void ExecuteAll(string functionType, PluginFunctionParameter @params) { foreach (var function in GetFunctions(functionType)) function.Execute(@params); } public IEnumerable ExcuteAndGetResults(string functionType) { return GetFunctions(functionType).Select(n => n.Execute()); } public IEnumerable ExcuteAndGetResults(string functionType, params object?[]? @params) { return GetFunctions(functionType).Select(n => n.Execute(@params)); } public IEnumerable ExcuteAndGetResults(string functionType, PluginFunctionParameter @params) { return GetFunctions(functionType).Select(n => n.Execute(@params)); } } }