Files
Pilz/Pilz.Plugins.Advanced/PluginFunction.cs

68 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telerik.WinControls;
namespace Pilz.Plugins.Advanced
{
public abstract class PluginFunction
{
public string Type { get; init; }
public string? Name { get; init; }
public RadSvgImage? Icon { get; set; }
public bool Enabled { get; set; } = true;
protected PluginFunction(string functionType)
{
Type = functionType;
}
protected PluginFunction(string functionType, string functionName) : this(functionType)
{
Name = functionName;
}
public object? Execute()
{
return Execute((PluginFunctionParameter?)null);
}
public T? Execute<T>(params object?[]? @params)
{
return Execute<T>(new PluginFunctionSimpleParamter(@params));
}
public object? Execute(params object?[]? @params)
{
return Execute(new PluginFunctionSimpleParamter(@params));
}
public T? Execute<T>(PluginFunctionSimpleParamter? @params)
{
if (Execute(@params) is T result)
return result;
return default;
}
public object? Execute(PluginFunctionParameter? @params)
{
#if !DEBUG
try
{
#endif
return ExecuteFunction(@params);
#if !DEBUG
}
catch (Exception)
{
return null;
}
#endif
}
protected abstract object? ExecuteFunction(PluginFunctionParameter? @params);
}
}