You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/3rd/StompyRobot/SRF/Scripts/Helpers/MethodReference.cs

38 lines
825 B
C#

2 months ago
using System;
namespace SRF.Helpers
{
using System.Reflection;
public sealed class MethodReference
{
private readonly Func<object[], object> _method;
public MethodReference(object target, MethodInfo method)
{
SRDebugUtil.AssertNotNull(target);
_method = o => method.Invoke(target, o);
}
public MethodReference(Func<object[], object> method)
{
_method = method;
}
public object Invoke(object[] parameters)
{
return _method.Invoke(parameters);
}
public static implicit operator MethodReference(Action action)
{
return new MethodReference(args =>
{
action();
return null;
});
}
}
}