8
public abstract class BaseAspectAttribute : Attribute
{    
    protected internal virtual void OnMethodBeforeExecuting(object args)
    {
        Console.WriteLine("Base Attribute OnMethodBeforeExecuting Work");
    }
}

public class LogAttribute : BaseAspectAttribute
{
    protected override void OnMethodBeforeExecuting(object args)
    {
        Console.WriteLine("Log Attribute OnMethodBeforeExecuting Work");
    }
}

我尝试在 LogAttribute => 中获取方法

object[] customAttributesOnMethod  = methodInfo.GetCustomAttributes(typeof (BaseAspectAttribute), true);
foreach (object attribute in customAttributesOnMethod)
{
    MethodInfo[] methodsInSelectedAttribute = attribute.GetType().GetMethods();
}

如何在 LogAttribute 中获取受保护的覆盖方法?

4

1 回答 1

17

调用GetMethods接受的重载BindingFlags。尝试这样的事情:

attribute.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic);

请参阅http://msdn.microsoft.com/en-us/library/4d848zkb.aspx

于 2014-07-29T17:03:32.877 回答