小编Sal*_*HAN的帖子

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

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");
    }
}
Run Code Online (Sandbox Code Playgroud)

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

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

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

c# reflection aop system.reflection methodinfo

5
推荐指数
1
解决办法
6855
查看次数

标签 统计

aop ×1

c# ×1

methodinfo ×1

reflection ×1

system.reflection ×1