Get Nested Types with BindingFlags : BindingFlags « Reflection « C# / C Sharp






Get Nested Types with BindingFlags

 

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

public class MyTypeClass
{
    public class Myclass1
    {
    }
    public class Myclass2 
    {
    }
    protected class MyClass3
    {
    }
    protected class MyClass4
    {
    }
}

public class TypeMain
{
    public static void Main() 
    {
        Type myType =(typeof(MyTypeClass));

        Type[] myTypeArray = myType.GetNestedTypes(BindingFlags.Public|BindingFlags.Instance);
        Console.WriteLine("The number of nested public classes is {0}.", myTypeArray.Length);

        DisplayTypeInfo(myTypeArray);
    }
    public static void DisplayTypeInfo(Type[] myArrayType)
    {
        for(int i=0;i<myArrayType.Length;i++)
        {
            Type myType = (Type)myArrayType[i];
            Console.WriteLine("The name of the nested class is {0}.", myType.ToString());
        }
    }
}

   
  








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.BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.DeclaredOnly
8.Get Properties with BindingFlags