是否可以从事件中获取自定义属性?
public class TestClass
{
[Test()]
public event EventHandler TestEvent;
public void RunTest()
{
//Get attributes from TestEvent
}
}
[AttributeUsage(AttributeTargets.Event)]
public class TestAttribute : Attribute
{
}
我尝试了以下内容,但两者都没有结果:
Console.WriteLine("Attr: {0}", Attribute.GetCustomAttribute(TestEvent.GetMethodInfo(), typeof (TestAttribute)) != null);
Console.WriteLine("Attr: {0}", Attribute.GetCustomAttribute(TestEvent.Method, typeof (TestAttribute)) != null);