共用方式為


Type.GetNestedType Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

When overridden in a derived class, searches for the specified nested type, using the specified binding constraints.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public MustOverride Function GetNestedType ( _
    name As String, _
    bindingAttr As BindingFlags _
) As Type
public abstract Type GetNestedType(
    string name,
    BindingFlags bindingAttr
)

Parameters

  • name
    Type: System.String
    The string containing the name of the nested type to get.

Return Value

Type: System.Type
A Type object representing the nested type that matches the specified requirements, if found; otherwise, nulla null reference (Nothing in Visual Basic).

Exceptions

Exception Condition
ArgumentNullException

name is nulla null reference (Nothing in Visual Basic).

Remarks

Use the simple name of the nested class for name. Do not qualify it with the name of the outer class. For a generic nested class, use the mangled name — that is, append a grave accent and the number of generic parameters. For example, use the string "Inner`1" to get the generic nested class Inner<T> (Inner(Of T) in Visual Basic). Do not include language-specific syntax for type parameters.

The following BindingFlags filter flags can be used to define which nested types to include in the search:

  • You must specify either BindingFlags.Public or BindingFlags.NonPublic to get a return.

  • Specify BindingFlags.Public to include public nested types in the search.

  • Specify BindingFlags.NonPublic to include non-public nested types (that is, private and protected nested types) in the search.

This method returns only the nested types of the current type. It does not search the base classes of the current type. To find types that are nested in base classes, you must walk the inheritance hierarchy, calling GetNestedType at each level.

BindingFlags.Instance and BindingFlags.Static are ignored.

Calling this method with only the BindingFlags.Public flag or only the BindingFlags.NonPublic flag will return the specified nested types and does not require any other flags.

See System.Reflection.BindingFlags for more information.

If the current Type represents a type parameter in the definition of a generic type or generic method, this method searches the nested types of the class constraint.

If a nested type is generic, this method returns its generic type definition. This is true even if the enclosing generic type is a closed constructed type.

NoteNote:

If the current Type represents a generic type defined in C#, Visual Basic, or C++, its nested types are all generic even if they have no generic parameters of their own. This is not necessarily true of nested types defined in dynamic assemblies or compiled with the Microsoft intermediate language (MSIL) assembler.

For information on nested generic types, and on constructing nested generic types from their generic type definitions, see MakeGenericType.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.