C# Type GetNestedTypes(BindingFlags)

Description

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

Syntax

Type.GetNestedTypes(BindingFlags) has the following syntax.


public abstract Type[] GetNestedTypes(
  BindingFlags bindingAttr
)

Parameters

Type.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

Type.GetNestedTypes(BindingFlags) method returns

Example

The following example creates two nested public classes and two nested protected classes, and displays information for classes that match the specified binding constraints.


/*from w  ww.jav  a2  s.com*/
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(myTypeArray.Length);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version