Επεξεργασία

Κοινή χρήση μέσω


Type.GetNestedType Method

Definition

Gets a specific type nested within the current Type.

Overloads

GetNestedType(String)

Searches for the public nested type with the specified name.

GetNestedType(String, BindingFlags)

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

GetNestedType(String)

Source:
Type.cs
Source:
Type.cs
Source:
Type.cs

Searches for the public nested type with the specified name.

public:
 Type ^ GetNestedType(System::String ^ name);
public:
 virtual Type ^ GetNestedType(System::String ^ name);
public Type? GetNestedType (string name);
public Type GetNestedType (string name);
member this.GetNestedType : string -> Type
abstract member GetNestedType : string -> Type
override this.GetNestedType : string -> Type
Public Function GetNestedType (name As String) As Type

Parameters

name
String

The string containing the name of the nested type to get.

Returns

An object representing the public nested type with the specified name, if found; otherwise, null.

Implements

Exceptions

name is null.

Remarks

The search for name is case-sensitive.

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 arguments. 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 table shows what members of a base class are returned by the Get methods when reflecting on a type.

Member Type Static Non-Static
Constructor No No
Field No Yes. A field is always hide-by-name-and-signature.
Event Not applicable The common type system rule is that the inheritance is the same as that of the methods that implement the property. Reflection treats properties as hide-by-name-and-signature. See note 2 below.
Method No Yes. A method (both virtual and non-virtual) can be hide-by-name or hide-by-name-and-signature.
Nested Type No No
Property Not applicable The common type system rule is that the inheritance is the same as that of the methods that implement the property. Reflection treats properties as hide-by-name-and-signature. See note 2 below.
  1. Hide-by-name-and-signature considers all of the parts of the signature, including custom modifiers, return types, parameter types, sentinels, and unmanaged calling conventions. This is a binary comparison.

  2. For reflection, properties and events are hide-by-name-and-signature. If you have a property with both a get and a set accessor in the base class, but the derived class has only a get accessor, the derived class property hides the base class property, and you will not be able to access the setter on the base class.

  3. Custom attributes are not part of the common type system.

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.

Note

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 Ilasm.exe (IL Assembler).

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

See also

Applies to

GetNestedType(String, BindingFlags)

Source:
Type.cs
Source:
Type.cs
Source:
Type.cs

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

public:
 abstract Type ^ GetNestedType(System::String ^ name, System::Reflection::BindingFlags bindingAttr);
public abstract Type? GetNestedType (string name, System.Reflection.BindingFlags bindingAttr);
public abstract Type GetNestedType (string name, System.Reflection.BindingFlags bindingAttr);
abstract member GetNestedType : string * System.Reflection.BindingFlags -> Type
Public MustOverride Function GetNestedType (name As String, bindingAttr As BindingFlags) As Type

Parameters

name
String

The string containing the name of the nested type to get.

bindingAttr
BindingFlags

A bitwise combination of the enumeration values that specify how the search is conducted.

-or-

Default to return null.

Returns

An object representing the nested type that matches the specified requirements, if found; otherwise, null.

Implements

Exceptions

name is null.

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:

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.

Note

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 Ilasm.exe (IL Assembler).

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

See also

Applies to