Type.GetNestedType Type.GetNestedType Type.GetNestedType Type.GetNestedType Method

定义

获取嵌套在当前 Type 中的特定类型。Gets a specific type nested within the current Type.

重载

GetNestedType(String, BindingFlags) GetNestedType(String, BindingFlags) GetNestedType(String, BindingFlags) GetNestedType(String, BindingFlags)

当在派生类中重写时,使用指定绑定约束搜索指定嵌套类型。When overridden in a derived class, searches for the specified nested type, using the specified binding constraints.

GetNestedType(String) GetNestedType(String) GetNestedType(String) GetNestedType(String)

搜索具有指定名称的公共嵌套类型。Searches for the public nested type with the specified name.

GetNestedType(String, BindingFlags) GetNestedType(String, BindingFlags) GetNestedType(String, BindingFlags) GetNestedType(String, BindingFlags)

当在派生类中重写时,使用指定绑定约束搜索指定嵌套类型。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);
abstract member GetNestedType : string * System.Reflection.BindingFlags -> Type
Public MustOverride Function GetNestedType (name As String, bindingAttr As BindingFlags) As Type

参数

name
String String String String

包含要获取的嵌套类型的名称的字符串。The string containing the name of the nested type to get.

bindingAttr
BindingFlags BindingFlags BindingFlags BindingFlags

枚举值的按位组合,这些值指定如何进行搜索。A bitwise combination of the enumeration values that specify how the search is conducted.

-or- 若为 Default,则返回 nullDefault to return null.

返回

表示符合指定要求的嵌套类型的对象(如果找到的话);否则为 nullAn object representing the nested type that matches the specified requirements, if found; otherwise, null.

实现

异常

注解

使用嵌套类name的简单名称。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. 例如,使用字符串 "Inner`1" 获取泛型嵌套类Inner<T>Inner(Of T)在 Visual Basic 中)。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.

以下BindingFlags筛选器标志可用于定义要包括在搜索中的嵌套类型: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. 若要查找嵌套在基类中的类型,必须遍历继承层次结构,并在GetNestedType每个级别调用。To find types that are nested in base classes, you must walk the inheritance hierarchy, calling GetNestedType at each level.

BindingFlags.InstanceBindingFlags.Static将被忽略。BindingFlags.Instance and BindingFlags.Static are ignored.

BindingFlags.Public用标志或BindingFlags.NonPublic标志调用此方法将返回指定的嵌套类型,并且不需要任何其他标志。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.

有关更多信息,请参见System.Reflection.BindingFlagsSee System.Reflection.BindingFlags for more information.

如果当前Type表示泛型类型或泛型方法的定义中的类型参数,则此方法会搜索类约束的嵌套类型。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.

备注

如果当前Type的表示在中C#定义的泛型类型,Visual Basic 或C++,则其嵌套类型都是通用的,即使它们不具有自己的泛型参数也是如此。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. 这不一定适用于动态程序集中定义的嵌套类型或用Ilasm (IL 汇编程序)编译的。This is not necessarily true of nested types defined in dynamic assemblies or compiled with the Ilasm.exe (IL Assembler).

有关嵌套泛型类型以及如何从其泛型类型定义构造嵌套的泛型类型的信息,请MakeGenericType参阅。For information on nested generic types, and on constructing nested generic types from their generic type definitions, see MakeGenericType.

另请参阅

GetNestedType(String) GetNestedType(String) GetNestedType(String) GetNestedType(String)

搜索具有指定名称的公共嵌套类型。Searches for the public nested type with the specified name.

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

参数

name
String String String String

包含要获取的嵌套类型的名称的字符串。The string containing the name of the nested type to get.

返回

如找到,则为表示具有指定名称的公共嵌套类型的对象;否则为 nullAn object representing the public nested type with the specified name, if found; otherwise, null.

实现

异常

注解

的搜索name区分大小写。The search for name is case-sensitive.

使用嵌套类name的简单名称。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. 例如,使用字符串 "Inner`1" 获取泛型嵌套类Inner<T>Inner(Of T)在 Visual Basic 中)。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.

下表显示了在类型上反射时Get方法返回的基类成员。The following table shows what members of a base class are returned by the Get methods when reflecting on a type.

成员类型Member Type StaticStatic 非静态Non-Static
构造函数Constructor NoNo NoNo
字段Field NoNo 可以。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. 请参阅下面的注释2。See note 2 below.
方法Method NoNo 可以。Yes. 方法(虚拟和非虚拟)可按名称隐藏或按名称和签名隐藏。A method (both virtual and non-virtual) can be hide-by-name or hide-by-name-and-signature.
嵌套类型Nested Type NoNo NoNo
PropertyProperty 不适用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. 请参阅下面的注释2。See note 2 below.
  1. 按名称和签名隐藏将考虑签名的所有部分,包括自定义修饰符、返回类型、参数类型、个 sentinel 和非托管调用约定。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. 如果在基类中同时具有 get 访问器和 set 访问器的属性,但派生类只有 get 访问器,则派生类属性将隐藏基类属性,并且你将无法访问基类的资源库。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.

如果当前Type表示泛型类型或泛型方法的定义中的类型参数,则此方法会搜索类约束的嵌套类型。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.

备注

如果当前Type的表示在中C#定义的泛型类型,Visual Basic 或C++,则其嵌套类型都是通用的,即使它们不具有自己的泛型参数也是如此。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. 这不一定适用于动态程序集中定义的嵌套类型或用Ilasm (IL 汇编程序)编译的。This is not necessarily true of nested types defined in dynamic assemblies or compiled with the Ilasm.exe (IL Assembler).

有关嵌套泛型类型以及如何从其泛型类型定义构造嵌套的泛型类型的信息,请MakeGenericType参阅。For information on nested generic types, and on constructing nested generic types from their generic type definitions, see MakeGenericType.

另请参阅

适用于