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.

实现

异常

注解

使用的嵌套类的简单名称nameUse 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. 例如,使用字符串"内部`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.exe (IL 汇编程序)This is not necessarily true of nested types defined in dynamic assemblies or compiled with the Ilasm.exe (IL Assembler).

在嵌套的泛型类型和构造从各自的泛型类型定义的嵌套泛型类型信息,请参阅MakeGenericTypeFor 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.

使用的嵌套类的简单名称nameUse 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. 例如,使用字符串"内部`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. 按名称和签名隐藏会考虑所有的签名,包括自定义修饰符,部分返回类型、 参数类型、 标记和非托管调用约定。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.exe (IL 汇编程序)This is not necessarily true of nested types defined in dynamic assemblies or compiled with the Ilasm.exe (IL Assembler).

在嵌套的泛型类型和构造从各自的泛型类型定义的嵌套泛型类型信息,请参阅MakeGenericTypeFor information on nested generic types, and on constructing nested generic types from their generic type definitions, see MakeGenericType.

另请参阅

适用于