C# 如何使用反射获取受保护的内部方法

C# 如何使用反射获取受保护的内部方法,c#,reflection,system.reflection,aop,methodinfo,C#,Reflection,System.reflection,Aop,Methodinfo,我尝试在LogAttribute=> public abstract class BaseAspectAttribute : Attribute { protected internal virtual void OnMethodBeforeExecuting(object args) { Console.WriteLine("Base Attribute OnMethodBeforeExecuting Work"); } } public cl

我尝试在LogAttribute=>

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中获取受保护的重写方法?

调用接受
BindingFlags
GetMethods
重载。试着这样做:

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

谢谢:)我尝试了其他bindingFlags技术,但没有使用bindingFlags。实例:/
attribute.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic);