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中获取受保护的覆盖方法?
调用接受GetMethods
的BindingFlags
的重载。尝试这样的事情:
attribute.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic);