Given the MethodInfo
of a method how can I use a lambda expression to specify a parameter (ParameterInfo
)?
For example, given the following method signature:
public string DoSomething(int id, int count);
I would like to have a method:
WithParameter(MethodInfo info, Expression<???> expression);
Which would be invoked like so:
WithParameter(doSomethingMethodInfo, x => x.id)
Is this possible?
If you want to specify the parameter name in statically safe way, this is not possible.
Two reasons:
MethodInfo
had already lost all static type informationAlternative approaches are different depending on your final goal.