Sal*_*HAN 5 c# reflection aop system.reflection methodinfo
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中获取受保护的覆盖方法?
Ale*_*exD 12
调用GetMethods其接受的重载BindingFlags.尝试这样的事情:
attribute.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic);
Run Code Online (Sandbox Code Playgroud)
请参阅http://msdn.microsoft.com/en-us/library/4d848zkb.aspx