Tales from the Evil Empire

Bertrand Le Roy's blog

News


Bertrand Le Roy


Add to Technorati Favorites Tales from the Evil Empire - Blogged

Blogs I read

My other stuff

Archives

How to reflect over a delegate’s signature

I’ve done some tricky work with delegates recently and I’ve had a hard time trying to reflect over the signature of a delegate type. I feel a little silly now that the solution to this has been provided to me by Eric Lippert. It’s actually quite simple, just reflect over the Invoke method:

MethodInfo invoke = typeof(Func<string, bool>).GetMethod("Invoke");
Console.WriteLine(invoke.ReturnType.Name);

I hope this helps others…

Posted: Jan 23 2009, 02:41 PM by Bertrand Le Roy | with 2 comment(s)
Filed under: ,

Comments

David Maltby said:

Thanks!  That was helpful.

# April 3, 2009 3:50 PM

Abel Braaksma said:

Very simple and just brilliant. Couldn't have though of this myself. I used it in <a href="stackoverflow.com/.../parameterising-dllimport-for-use-in-a-c-application">this generic-delegate-to-pinvoke approach</a> where it seemed the only way out and it works like a charm.

# November 2, 2009 9:55 AM