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 中获取 protected 覆盖方法?
最佳答案
调用 GetMethods
的重载,它接受 BindingFlags
。尝试这样的事情:
attribute.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic);
关于c# - 如何通过反射获得 protected 内部方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25020966/