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- 要傳回 nullDefaultDefault 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. 泛型的巢狀類別,也就是使用 mangled 的名稱、 附加抑音符號和泛型參數的數目。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. 這是 true,即使封入泛型型別是封閉式的建構型別。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 Assembler)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. 泛型的巢狀類別,也就是使用 mangled 的名稱、 附加抑音符號和泛型引數數目。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 No No
欄位Field No 可以。Yes. 欄位永遠是依名稱和簽章隱藏。A field is always hide-by-name-and-signature.
Event - 事件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 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. 請參閱附註 2。See note 2 below.
  1. 依名稱和簽章隱藏會考慮所有組件的簽章,包括自訂修飾詞,傳回類型、 參數類型、 sentinels 和 unmanaged 呼叫慣例。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 存取子,在衍生的類別的屬性會隱藏基底類別屬性中,並不能存取的基底類別的 setter。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. 這是 true,即使封入泛型型別是封閉式的建構型別。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 Assembler)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.

另請參閱

適用於