Execute method with Action<T> argument using Reflection
Posted
by JGr
on Stack Overflow
See other posts from Stack Overflow
or by JGr
Published on 2010-04-01T09:26:38Z
Indexed on
2010/04/01
9:33 UTC
Read the original article
Hit count: 313
c#
|reflection
How can i create a Action method to use as a argument to the following function?
public void When(Action<T> action)
{
if (internalValue != null)
action(internalValue);
}
I have the MethodInfo on the method, and the parameter type like so:
var methods = value.GetType().GetMethods();
MethodInfo mInfo = methods.First(method => method.Name == "When");
Type parameterType = (mInfo.GetParameters()[0]).ParameterType;
But after that i have no idea how to make the actual Action method to pass as argument, i also do not know how to define the Action method body.
© Stack Overflow or respective owner