If I have a method name, and the parameters for the method, how can I create a MethodCallExpression
for the method?
Here is an example method:
public void HandleEventWithArg(int arg)
{
}
Here is the code that I have:
var methodInfo = obj.GetType().GetMethod("HandleEventWithArg");
var body = Expression.Call(Expression.Constant(methodInfo), methodInfo.GetType().GetMethod("Invoke"), argExpression);
Here is the exception:
An unhandled exception of type 'System.Reflection.AmbiguousMatchException' occurred in mscorlib.dll
Additional information: Ambiguous match found.