Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a MethodInfo from an Action delegate

I am trying to develop an NUnit addin that dynamically adds test methods to a suite from an object that contains a list of Action delegates. The problem is that NUnit appears to be leaning heavily on reflection to get the job done. Consequently, it looks like there's no simple way to add my Actions directly to the suite.

I must, instead, add MethodInfo objects. This would normally work, but the Action delegates are anonymous, so I would have to build the types and methods to accomplish this. I need to find an easier way to do this, without resorting to using Emit. Does anyone know how to easily create MethodInfo instances from Action delegates?

like image 387
Michael Meadows Avatar asked Apr 05 '10 02:04

Michael Meadows


1 Answers

Have you tried Action's Method property? I mean something like:

MethodInfo GetMI(Action a)
{
    return a.Method;
}
like image 166
Fede Avatar answered Sep 17 '22 23:09

Fede