80 lines
2.6 KiB
C#
80 lines
2.6 KiB
C#
using global::System.Reflection;
|
|
|
|
namespace Pilz.Reflection.PluginSystem
|
|
{
|
|
public class PluginFunction
|
|
{
|
|
|
|
/// <summary>
|
|
/// Gets the method to invoke when invoking this PluginFunction.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public MethodInfo Method { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Gets the refered Plugin for this PluginFunction, if it has one.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public Plugin Plugin { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Gets the Parameters that was given by the attribute.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public object[] Params { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Gets the function code for this PluginFunction.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string FunctionCode { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Creates a new instance of a PluginFunction.
|
|
/// </summary>
|
|
/// <param name="method">The Method to invoke when invoking this PluginFunction.</param>
|
|
/// <param name="plugin">The Plugin that is the Parent of this PluginFunction. This value can be NULL.</param>
|
|
public PluginFunction(MethodInfo method, Plugin plugin)
|
|
{
|
|
Method = method;
|
|
Plugin = plugin;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a new instance of a PluginFunction.
|
|
/// </summary>
|
|
/// <param name="method">The Method to invoke when invoking this PluginFunction..</param>
|
|
/// <param name="plugin">The Plugin that is the Parent of this PluginFunction. This value can be NULL.</param>
|
|
/// <param name="params">The Parameters that was given by the attribute.</param>
|
|
/// <param name="funcCode">The function code for this PluginFunction.</param>
|
|
public PluginFunction(MethodInfo method, Plugin plugin, object[] @params, string funcCode) : this(method, plugin)
|
|
{
|
|
Params = @params;
|
|
FunctionCode = funcCode;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Invokes the Method of the PluginFunction.
|
|
/// </summary>
|
|
public void Invoke()
|
|
{
|
|
Method.Invoke(null, null);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Invokes the Method of the PluginFunction.
|
|
/// </summary>
|
|
public void Invoke(params object[] @params)
|
|
{
|
|
Method.Invoke(null, @params);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Invokes the Method of the PluginFunction and returns the return value.
|
|
/// </summary>
|
|
public object InvokeGet(params object[] @params)
|
|
{
|
|
return Method.Invoke(null, @params);
|
|
}
|
|
}
|
|
} |