Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invoke Func<T, TResult> from Reflection

Tags:

c#

Finally, I have been able to get through reflection, a member of type Func<T, TResult>, now, how do I invoke it?

When I retrieve it, I do it through the Type.GetMembers method, and that returns a MemberInfo type that does not have a Invoke method; how can I invoke it?

Again people, thanks in advance! =)

like image 824
Hugo Avatar asked Dec 21 '10 17:12

Hugo


1 Answers

Once you've got an instance of Func<T, TResult>, you can cast it to a Delegate, and call the DynamicInvoke method on it which allows you to call the delegate in a reflection scenario (as long as the argument types match!)

like image 155
thecoop Avatar answered Nov 18 '22 06:11

thecoop