Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to gets protected internal methods with reflection

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");
    }
}

I try get methods in LogAttribute =>

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

How to gets protected override methods in LogAttribute?

like image 896
Salih KARAHAN Avatar asked Jul 29 '14 17:07

Salih KARAHAN


1 Answers

Call the overload of GetMethods which accepts BindingFlags. Try something like this:

attribute.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic);

See http://msdn.microsoft.com/en-us/library/4d848zkb.aspx

like image 196
AlexD Avatar answered Nov 04 '22 18:11

AlexD