我正在使用自定义TriggerHandler
属性修饰类方法。
public class TriggerHandlerAttribute : Attribute
{
#region Data Members
public readonly Type EntityType;
public readonly TriggerType TriggerType;
#endregion
#region Constructor
// Current constructor
public TriggerHandlerAttribute( Type entityType, TriggerType eventType )
{
EntityType = entityType;
EventType = eventType;
}
// Example of the desired implementation
public TriggerHandlerAttribute()
{
// 1. Somehow obtain MethodInfo
// 2. Configure attribute based on MethodInfo's parameters (already implemented)
}
#endregion
}
[TriggerHandler(typeof(SomeType), TriggerType.Basic)]
private void SomeMethod( ITriggerBasic<SomeType> triggerContext )
{
...
}
我希望能够为此属性定义一个无参数的构造函数,并使用反射来填充字段,但是要做到这一点,我需要能够访问该方法的MethodInfo
装饰有此属性。
是否有一种方法可以获取分配给特定MethodInfo
的方法的TriggerHandlerAttribute
?如果是这样,我该怎么做?