如何从一个Action委托创建的MethodInfo [英] How can I create a MethodInfo from an Action delegate

查看:119
本文介绍了如何从一个Action委托创建的MethodInfo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开发一个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;
}

这篇关于如何从一个Action委托创建的MethodInfo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆