C# TypeInfo GetNestedTypes(BindingFlags)

Description

TypeInfo GetNestedTypes(BindingFlags) When overridden in a derived class, searches for the types nested in the current Type, using the specified binding constraints.

Syntax

TypeInfo.GetNestedTypes(BindingFlags) has the following syntax.


public abstract Type[] GetNestedTypes(
  BindingFlags bindingAttr
)

Parameters

TypeInfo.GetNestedTypes(BindingFlags) has the following parameters.

  • bindingAttr - A bitmask comprised of one or more BindingFlags that specify how the search is conducted.
  • bindingAttr - -or-
  • bindingAttr - Zero, to return null.

Returns

TypeInfo.GetNestedTypes(BindingFlags) method returns

Example


using System;//from   w w  w.j  a v a2s. com
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);

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

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Reflection »




EventInfo
FieldInfo
MemberInfo
MethodInfo
ParameterInfo
TypeInfo