从Action <t> </t>获取事件名称

时间:2014-02-03 09:00:05

标签: c# events reflection action

我希望能够做到这一点:

Verify.EventIsHooked(a => a.Event1 += null);

有这种情况:

class A
{
    public event EventHandler Event1;
}

class static Verify
{
    public static void EventIsHooked<T>(Action<T> action)
    {
        // What comes here to extract the event name?
    }
}

如何从表达式中提取Event1名称?

由于

PD:我知道如何检查某个事件是否被挂钩。我只需要提取事件名称。

修改

背后的想法是能够让代表附加到事件,以确定事件是否已在单元测试中挂钩/取消挂钩,而不将事件名称作为字符串传递给反射调用。

Moq在引发事件时使用a => a.Event1 += null之类的lambdas,因为它看起来像是在表达式中传递事件的唯一方法。

0 个答案:

没有答案
相关问题