BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.DeclaredOnly : BindingFlags « Reflection « C# / C Sharp






BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.DeclaredOnly

 

using System;
using System.Reflection;
using System.Reflection.Emit;

public class MyTypeClass
{
    public void MyMethods()
    {
    }
    public int MyMethods1() 
    {
        return 3;
    }
    protected String MyMethods2()
    {
        return "hello";
    }
}
public class TypeMain
{
    public static void Main() 
    {
        Type myType =(typeof(MyTypeClass));
        // Get the nonpublic methods.
        MethodInfo[] myArrayMethodInfo1 = myType.GetMethods(BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.DeclaredOnly);
        Console.WriteLine("\nThe number of protected methods is {0}.", myArrayMethodInfo1.Length);
        // Display information for all methods.
        DisplayMethodInfo(myArrayMethodInfo1);    
    }
    public static void DisplayMethodInfo(MethodInfo[] myArrayMethodInfo)
    {
        for(int i=0;i<myArrayMethodInfo.Length;i++)
        {
            MethodInfo myMethodInfo = (MethodInfo)myArrayMethodInfo[i];
            Console.WriteLine("\nThe name of the method is {0}.", myMethodInfo.Name);
        }
    }
}

   
  








Related examples in the same category

1.Use BindingFlags Instance and NonPublic
2.Print Method Info: BindingFlags
3.Searches for the constructors defined for the current Type, using the specified BindingFlags.
4.GetConstructors(BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance)
5.Using difference BindingFlags to get method
6.BindingFlags.Public | BindingFlags.Instance
7.Get Nested Types with BindingFlags
8.Get Properties with BindingFlags