c# - Using a lambda expression to specify parameter of method -
given methodinfo
of method how can use lambda expression specify parameter (parameterinfo
)?
for example, given following method signature:
public string dosomething(int id, int count);
i have method:
withparameter(methodinfo info, expression<???> expression);
which invoked so:
withparameter(dosomethingmethodinfo, x => x.id)
is possible?
if want specify parameter name in statically safe way, not possible.
2 reasons:
- c# not support parameters
methodinfo
had lost static type information
alternative approaches different depending on final goal.
Comments
Post a Comment