Type.GetNestedTypes メソッド ()
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As Type Dim returnValue As Type() returnValue = instance.GetNestedTypes
現在の Type 内で入れ子になっているパブリック型を表す Type オブジェクトの配列 (検索は非再帰的)。または、現在の Type で入れ子になっているパブリック型がない場合は、Type 型の空の配列。

現在の型で直接入れ子になっているパブリック型だけが返されます。検索は再帰的ではありません。
型に対するリフレクション時に Get メソッドによって返される基本クラスのメンバを次の表に示します。
メンバ型 | 非静的 | |
---|---|---|
いいえ | いいえ | |
いいえ | ||
適用なし | 共通型システムの規則では、継承は、プロパティを実装するメソッドの継承と同じになります。リフレクションは、プロパティを名前と署名によって隠ぺいされているとして扱います。下記のメモ 2 を参照してください。 | |
いいえ | はい。メソッド (仮想メソッドと非仮想メソッドの両方) は、名前によって隠蔽することもできますし、名前と署名によって隠蔽することもできます。 | |
いいえ | いいえ | |
適用なし | 共通型システムの規則では、継承は、プロパティを実装するメソッドの継承と同じになります。リフレクションは、プロパティを名前と署名によって隠ぺいされているとして扱います。下記のメモ 2 を参照してください。 |
-
名前と署名による隠ぺいでは、カスタム修飾子、戻り値の型、パラメータの型、sentinel、およびアンマネージ呼び出し規約を含めて、署名のすべての部分が判断の対象となります。これはバイナリ比較です。
-
リフレクションの場合、プロパティおよびイベントは名前と署名によって隠ぺいされています。基本クラスに get アクセサと set アクセサの両方を持つプロパティがあり、派生クラスには get アクセサしかない場合、派生クラスのプロパティにより基本クラスのプロパティが隠ぺいされ、基本クラスの set アクセサにはアクセスできません。
現在の Type がジェネリック型またはジェネリック メソッドの定義の型パラメータを表している場合、このメソッドはクラス制約の入れ子にされた型を検索します。
入れ子にされた型がジェネリック型である場合、このメソッドはそのジェネリック型定義を返します。包含するジェネリック型がクローズ構築型の場合も同様です。
![]() |
---|
現在の Type が C#、isual Basic、または C++ で定義されたジェネリック型を表す場合、入れ子にされた型はそれ自体のジェネリック パラメータが存在しなくてもすべてジェネリック型です。ただし、入れ子にされた型が動的アセンブリで定義された場合、または MSIL アセンブラ (Ilasm.exe) によってコンパイルされた場合は、ジェネリック型であるとは限りません。 |
入れ子になったジェネリック型の詳細、および入れ子になったジェネリック型をジェネリック型定義から構築する方法の詳細については、MakeGenericType のトピックを参照してください。

MyClass に入れ子になったクラスと struct を定義し、MyClass の型を使用して、入れ子にされた型のオブジェクトを取得する例を次に示します。
Imports System Imports System.Reflection Public Class MyClass1 Public Class NestClass Public Shared myPublicInt As Integer = 0 End Class 'NestClass Public Structure NestStruct Public myPublicInt As Integer End Structure 'NestStruct End Class 'MyClass1 Public Class MyMainClass Public Shared Sub Main() Try ' Get the Type object corresponding to MyClass. Dim myType As Type = GetType(MyClass1) ' Get an array of nested type objects in MyClass. Dim nestType As Type() = myType.GetNestedTypes() Console.WriteLine("The number of nested types is {0}.", nestType.Length) Dim t As Type For Each t In nestType Console.WriteLine("Nested type is {0}.", t.ToString()) Next t Catch e As Exception Console.WriteLine("Error", e.Message.ToString()) End Try End Sub 'Main End Class 'MyMainClass
using System; using System.Reflection; public class MyClass { public class NestClass { public static int myPublicInt=0; } public struct NestStruct { public static int myPublicInt=0; } } public class MyMainClass { public static void Main() { try { // Get the Type object corresponding to MyClass. Type myType=typeof(MyClass); // Get an array of nested type objects in MyClass. Type[] nestType=myType.GetNestedTypes(); Console.WriteLine("The number of nested types is {0}.", nestType.Length); foreach(Type t in nestType) Console.WriteLine("Nested type is {0}.", t.ToString()); } catch(Exception e) { Console.WriteLine("Error"+e.Message); } } }
using namespace System; using namespace System::Reflection; public ref class MyClass { public: ref class NestClass { public: static int myPublicInt = 0; }; ref struct NestStruct { public: static int myPublicInt = 0; }; }; int main() { try { // Get the Type object corresponding to MyClass. Type^ myType = MyClass::typeid; // Get an array of nested type objects in MyClass. array<Type^>^nestType = myType->GetNestedTypes(); Console::WriteLine( "The number of nested types is {0}.", nestType->Length ); System::Collections::IEnumerator^ myEnum = nestType->GetEnumerator(); while ( myEnum->MoveNext() ) { Type^ t = safe_cast<Type^>(myEnum->Current); Console::WriteLine( "Nested type is {0}.", t ); } } catch ( Exception^ e ) { Console::WriteLine( "Error {0}", e->Message ); } }
import System.*; import System.Reflection.*; public class MyClass { public static class NestClass { public static int myPublicInt = 0; } //NestClass public static class NestStruct { public static int myPublicInt = 0; } //NestStruct } //MyClass public class MyMainClass { public static void main(String[] args) { try { // Get the Type object corresponding to MyClass. Type myType = MyClass.class.ToType(); // Get an array of nested type objects in MyClass. Type nestType[] = myType.GetNestedTypes(); Console.WriteLine("The number of nested types is {0}.", System.Convert.ToString(nestType.get_Length())); for (int iCtr = 0; iCtr < nestType.get_Length(); iCtr++) { Type t = nestType[iCtr]; Console.WriteLine("Nested type is {0}.", t.ToString()); } } catch (System.Exception e) { Console.WriteLine("Error" + e.get_Message()); } } //main } //MyMainClass

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Type.GetNestedTypes メソッド (BindingFlags)
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As Type Dim bindingAttr As BindingFlags Dim returnValue As Type() returnValue = instance.GetNestedTypes(bindingAttr)
public abstract Type[] GetNestedTypes ( BindingFlags bindingAttr )
public abstract Type[] GetNestedTypes ( BindingFlags bindingAttr )
- bindingAttr
検索の実行方法を指定する 1 つ以上の BindingFlags から成るビット マスク。
または
null 参照 (Visual Basic では Nothing) を返す 0。
指定したバインディング制約と一致する現在の Type で入れ子にされたすべての型を表す Type オブジェクトの配列 (検索は非再帰的)。または、バインディング制約と一致する入れ子にされた型が見つからない場合は、Type 型の空の配列。

次の BindingFlags フィルタ フラグは、入れ子にされた型で、検索対象に含める型を定義するために使用できます。
-
戻り値を取得するには、BindingFlags.Public または BindingFlags.NonPublic のいずれかを指定する必要があります。
-
検索対象にパブリックではない入れ子にされた型 (つまり、プライベート メンバやプロテクト メンバ) を含めるための BindingFlags.NonPublic を指定します。
このメソッドは、現在の型の入れ子にされた型のみを返します。継承型の階層は検索しません。継承型に入れ子にされた型を見つけるには、継承階層をウォークする必要があります。
BindingFlags.Instance と BindingFlags.Static は無視されます。
指定した入れ子にされた型を返すには、BindingFlags.Public フラグだけか、または BindingFlags.NonPublic フラグだけを指定してこのメソッドを呼び出します。他のフラグを指定する必要はありません。
詳細については、「System.Reflection.BindingFlags」を参照してください。
現在の Type がジェネリック型またはジェネリック メソッドの定義の型パラメータを表している場合、このメソッドはクラス制約の入れ子にされた型を検索します。
入れ子にされた型がジェネリック型である場合、このメソッドはそのジェネリック型定義を返します。包含するジェネリック型がクローズ構築型の場合も同様です。
![]() |
---|
現在の Type が C#、isual Basic、または C++ で定義されたジェネリック型を表す場合、入れ子にされた型はそれ自体のジェネリック パラメータが存在しなくてもすべてジェネリック型です。ただし、入れ子にされた型が動的アセンブリで定義された場合、または MSIL アセンブラ (Ilasm.exe) によってコンパイルされた場合は、ジェネリック型であるとは限りません。 |
入れ子になったジェネリック型の詳細、および入れ子になったジェネリック型をジェネリック型定義から構築する方法の詳細については、MakeGenericType のトピックを参照してください。

入れ子になったパブリック クラスとプロテクト クラスをそれぞれ 2 つずつ作成し、指定したバインディング制約に一致するクラスの情報を表示する例を次に示します。
Imports System Imports System.Reflection Imports System.Reflection.Emit Imports Microsoft.VisualBasic ' Create a class with name 'MyTypeClass' with three properties. Public Class MyTypeClass Public Class Myclass1 End Class 'Myclass1 Public Class Myclass2 End Class 'Myclass2 Protected Class MyClass3 End Class 'MyClass3 Protected Class MyClass4 End Class 'MyClass4 End Class 'MyTypeClass Public Class TypeMain Public Shared Sub Main() Dim myType As Type = GetType(MyTypeClass) ' Get the public nested classes. Dim myTypeArray As Type() = myType.GetNestedTypes((BindingFlags.Public Or BindingFlags.Instance)) Console.WriteLine("The number of public nested classes is {0}.", myTypeArray.Length.ToString()) ' Display all the public nested classes. DisplayTypeInfo(myTypeArray) ' Get the nonpublic nested classes. Dim myTypeArray1 As Type() = myType.GetNestedTypes((BindingFlags.NonPublic Or BindingFlags.Instance)) Console.WriteLine("The number of protected nested classes is {0}.", myTypeArray1.Length.ToString()) ' Display the information for all nested classes. DisplayTypeInfo(myTypeArray1) End Sub 'Main Public Shared Sub DisplayTypeInfo(ByVal myArrayType() As Type) ' Display the information for all nested classes. Dim i As Integer For i = 0 To myArrayType.Length - 1 Dim myType As Type = CType(myArrayType(i), Type) Console.WriteLine("The name of the nested class is {0}.", myType.ToString()) Next i End Sub 'DisplayTypeInfo End Class 'TypeMain
using System; using System.Reflection; using System.Reflection.Emit; // Create a class with two nested public classes and two nested protected classes. public class MyTypeClass { public class Myclass1 { } public class Myclass2 { } protected class MyClass3 { } protected class MyClass4 { } } public class TypeMain { public static void Main() { Type myType =(typeof(MyTypeClass)); // Get the public nested classes. Type[] myTypeArray = myType.GetNestedTypes(BindingFlags.Public|BindingFlags.Instance); Console.WriteLine("The number of nested public classes is {0}.", myTypeArray.Length); // Display all the public nested classes. DisplayTypeInfo(myTypeArray); // Get the nonpublic nested classes. Type[] myTypeArray1 = myType.GetNestedTypes(BindingFlags.NonPublic|BindingFlags.Instance); Console.WriteLine("The number of nested protected classes is {0}.", myTypeArray1.Length); // Display all the nonpublic nested classes. DisplayTypeInfo(myTypeArray1); } public static void DisplayTypeInfo(Type[] myArrayType) { // Display the information for all the nested classes. for(int i=0;i<myArrayType.Length;i++) { Type myType = (Type)myArrayType[i]; Console.WriteLine("The name of the nested class is {0}.", myType.ToString()); } }
using namespace System; using namespace System::Reflection; using namespace System::Reflection::Emit; // Create a class with two nested public classes and two nested protected classes. public ref class MyTypeClass { public: ref class Myclass1{}; private: ref class Myclass2{}; protected: ref class MyClass3{}; private: ref class MyClass4{}; }; void DisplayTypeInfo( array<Type^>^myArrayType ) { // Display the information for all the nested classes. for ( int i = 0; i < myArrayType->Length; i++ ) { Type^ myType = myArrayType[ i ]; Console::WriteLine( "The name of the nested class is {0}.", myType ); } } int main() { Type^ myType = MyTypeClass::typeid; // Get the public nested classes. array<Type^>^myTypeArray = myType->GetNestedTypes( static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Instance) ); Console::WriteLine( "The number of nested public classes is {0}.", myTypeArray->Length ); // Display all the public nested classes. DisplayTypeInfo( myTypeArray ); // Get the nonpublic nested classes. array<Type^>^myTypeArray1 = myType->GetNestedTypes( static_cast<BindingFlags>(BindingFlags::NonPublic | BindingFlags::Instance) ); Console::WriteLine( "The number of nested protected classes is {0}.", myTypeArray1->Length ); // Display all the nonpublic nested classes. DisplayTypeInfo( myTypeArray1 ); }
import System.*; import System.Reflection.*; import System.Reflection.Emit.*; // Create a class with two nested public classes and //two nested protected classes. public class MyTypeClass { public class Myclass1 { } //Myclass1 public class Myclass2 { } //Myclass2 protected class MyClass3 { } //MyClass3 protected class MyClass4 { } //MyClass4 } //MyTypeClass public class TypeMain { public static void main(String[] args) { Type myType = MyTypeClass.class.ToType(); // Get the public nested classes. Type myTypeArray[] = myType.GetNestedTypes(BindingFlags.Public | BindingFlags.Instance); Console.WriteLine("The number of nested public classes is {0}.", (Int32)myTypeArray.get_Length()); // Display all the public nested classes. DisplayTypeInfo(myTypeArray); // Get the nonpublic nested classes. Type myTypeArray1[] = myType.GetNestedTypes(BindingFlags.NonPublic | BindingFlags.Instance); Console.WriteLine("The number of nested protected classes is {0}.", (Int32)myTypeArray1.get_Length()); // Display all the nonpublic nested classes. DisplayTypeInfo(myTypeArray1); } //main public static void DisplayTypeInfo(Type myArrayType[]) { // Display the information for all the nested classes. for (int i = 0; i < myArrayType.get_Length(); i++) { Type myType = (Type)myArrayType.get_Item(i); Console.WriteLine("The name of the nested class is {0}.", myType.ToString()); } } //DisplayTypeInfo } //TypeMain


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Type.GetNestedTypes メソッド

名前 | 説明 |
---|---|
Type.GetNestedTypes () | 現在の Type 内で入れ子になっているすべてのパブリック型を返します。 |
Type.GetNestedTypes (BindingFlags) | 派生クラスによってオーバーライドされた場合、指定したバインディング制約を使用して、現在の Type 内で入れ子になっている型を検索します。 .NET Compact Framework によってサポートされています。 |

_Type.GetNestedTypes メソッド

名前 | 説明 |
---|---|
_Type.GetNestedTypes () | COM オブジェクトに、Type.GetNestedTypes メソッドへのバージョンに依存しないアクセスが用意されています。 |
_Type.GetNestedTypes (BindingFlags) | バージョンに依存しない Type.GetNestedTypes メソッドへのアクセスを COM オブジェクトに提供し、指定したバインディング制約を使用して、現在の Type 内で入れ子になっている型を検索します。 |

- Type.GetNestedTypesのページへのリンク