如何从一个Action委托创建的MethodInfoAction、MethodInfo

由网友(梅花落白雪)分享简介:我想开发一个NUnit的插件,可以动态增加的测试方法,以一组从一个对象,包含动作代表的名单。问题是,NUnit的似乎是对严重倾斜的反射,把工作完成。因此,它看起来像有没有简单的方法可以直接加我的动作 s到套件。I am trying to develop an NUnit addin that dynamically...

我想开发一个NUnit的插件,可以动态增加的测试方法,以一组从一个对象,包含动作代表的名单。问题是,NUnit的似乎是对严重倾斜的反射,把工作完成。因此,它看起来像有没有简单的方法可以直接加我的动作 s到套件。

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.

我必须,而不是添加的MethodInfo 的对象。这将正常工作,但动作代表是匿名的,所以我也要建造的类型和方法来实现这一目标。我需要找到一个更简单的方法来做到这一点,而不诉诸使用的Emit 。有谁知道如何轻松地从行动代表创建的MethodInfo实例?

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?

推荐答案

您是否尝试过操作的方法的财产?我的意思是这样的:

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

MethodInfo GetMI(Action a)
{
    return a.Method;
}
阅读全文

相关推荐

最新文章