Type.IsGenericTypeDefinition プロパティ
アセンブリ: mscorlib (mscorlib.dll 内)

Type オブジェクトがジェネリック型定義を表している場合は true。それ以外の場合は false。

ジェネリック型定義は、他の型を構築するためのテンプレートです。たとえば、ジェネリック型定義 G<T> (C# 構文) (Visual Basic の場合は G(Of T)、C++ の場合は generic <typename T> ref class G) から、型 G<int> (Visual Basic の場合は G(Of Integer)) を構築できます。構築するには、Int32 型を含む汎用引数リストを指定して MakeGenericType メソッドを呼び出します。この構築型を表す Type オブジェクトの場合、GetGenericTypeDefinition メソッドはジェネリック型定義を再度取得します。
IsGenericTypeDefinition プロパティを使用して、現在の型から新しい型を作成できるかどうかを判断します。IsGenericTypeDefinition プロパティが true を返した場合は、MakeGenericType メソッドを呼び出して新しいジェネリック型を作成できます。
ジェネリック リフレクションで使用される用語の一定の条件の一覧については、IsGenericType のプロパティの解説を参照してください。

型がジェネリック型定義であるかどうかなど、型に関する情報を次の例に示します。構築型、ジェネリック型定義、および通常の型に対して情報が表示されています。
Imports System Imports System.Reflection Imports System.Collections.Generic Imports Microsoft.VisualBasic Public Class Test Private Shared Sub DisplayGenericTypeInfo(ByVal t As Type) Console.WriteLine(vbCrLf & t.ToString()) Console.WriteLine(vbTab & "Is this a generic type definition? " _ & t.IsGenericTypeDefinition) Console.WriteLine(vbTab & "Is it a generic type? " _ & t.IsGenericType) If t.IsGenericType Then ' If this is a generic type, display the type arguments. ' Dim typeArguments As Type() = t.GetGenericArguments() Console.WriteLine(vbTab & "List type arguments (" _ & typeArguments.Length & "):") For Each tParam As Type In typeArguments ' If this is a type parameter, display its position. ' If tParam.IsGenericParameter Then Console.WriteLine(vbTab & vbTab & tParam.ToString() _ & vbTab & "(unassigned - parameter position " _ & tParam.GenericParameterPosition & ")") Else Console.WriteLine(vbTab & vbTab & tParam.ToString()) End If Next tParam End If End Sub Public Shared Sub Main() Console.WriteLine(vbCrLf & "--- Display information about a constructed type, its") Console.WriteLine(" generic type definition, and an ordinary type.") ' Create a Dictionary of Test objects, using strings for the ' keys. Dim d As New Dictionary(Of String, Test)() DisplayGenericTypeInfo(d.GetType()) DisplayGenericTypeInfo(d.GetType().GetGenericTypeDefinition()) ' Display information for an ordinary type. DisplayGenericTypeInfo(GetType(String)) End Sub 'Main End Class 'Test ' This example produces the following output: ' '--- Display information about a constructed type, its ' generic type definition, and an ordinary type. ' 'System.Collections.Generic.Dictionary[System.String, Test] ' Is this a generic type definition? False ' Is it a generic type? True ' List type arguments (2): ' System.String ' Test ' 'System.Collections.Generic.Dictionary[TKey,TValue] ' Is this a generic type definition? True ' Is it a generic type? True ' List type arguments (2): ' TKey (unassigned - parameter position 0) ' TValue (unassigned - parameter position 1) ' 'System.String ' Is this a generic type definition? False ' Is it a generic type? False
using System; using System.Reflection; using System.Collections.Generic; public class Test { private static void DisplayGenericTypeInfo(Type t) { Console.WriteLine("\r\n{0}", t); Console.WriteLine("\tIs this a generic type definition? {0}", t.IsGenericTypeDefinition); Console.WriteLine("\tIs it a generic type? {0}", t.IsGenericType); if (t.IsGenericType) { // If this is a generic type, display the type arguments. // Type[] typeArguments = t.GetGenericArguments(); Console.WriteLine("\tList type arguments ({0}):", typeArguments.Length); foreach (Type tParam in typeArguments) { // If this is a type parameter, display its // position. // if (tParam.IsGenericParameter) { Console.WriteLine("\t\t{0}\t(unassigned - parameter position {1})", tParam, tParam.GenericParameterPosition); } else { Console.WriteLine("\t\t{0}", tParam); } } } } public static void Main() { Console.WriteLine("\r\n--- Display information about a constructed type, its"); Console.WriteLine(" generic type definition, and an ordinary type."); // Create a Dictionary of Test objects, using strings for the // keys. Dictionary<string, Test> d = new Dictionary<string, Test>(); // Display information for the constructed type and its generic // type definition. DisplayGenericTypeInfo(d.GetType()); DisplayGenericTypeInfo(d.GetType().GetGenericTypeDefinition()); // Display information for an ordinary type. DisplayGenericTypeInfo(typeof(string)); } } /* This example produces the following output: --- Display information about a constructed type, its generic type definition, and an ordinary type. System.Collections.Generic.Dictionary[System.String,Test] Is this a generic type definition? False Is it a generic type? True List type arguments (2): System.String Test System.Collections.Generic.Dictionary[TKey,TValue] Is this a generic type definition? True Is it a generic type? True List type arguments (2): TKey (unassigned - parameter position 0) TValue (unassigned - parameter position 1) System.String Is this a generic type definition? False Is it a generic type? False */
using namespace System; using namespace System::Reflection; using namespace System::Collections::Generic; public ref class Test { private: static void DisplayGenericTypeInfo( Type^ t ) { Console::WriteLine( L"\r\n{0}", t ); Console::WriteLine( L"\tIs this a generic type definition? {0}", t->IsGenericTypeDefinition ); Console::WriteLine( L"\tIs it a generic type? {0}", t->IsGenericType ); if ( t->IsGenericType ) { // If this is a generic type, display the type arguments. // array<Type^>^typeArguments = t->GetGenericArguments(); Console::WriteLine( L"\tList type arguments ({0}):", typeArguments->Length ); System::Collections::IEnumerator^ myEnum = typeArguments->GetEnumerator(); while ( myEnum->MoveNext() ) { Type^ tParam = safe_cast<Type^>(myEnum->Current); // If this is a type parameter, display its // position. // if ( tParam->IsGenericParameter ) { Console::WriteLine( L"\t\t{0}\t(unassigned - parameter position {1})", tParam, tParam->GenericParameterPosition ); } else { Console::WriteLine( L"\t\t{0}", tParam ); } } } } public: static void Main() { Console::Write( L"\r\n--- Display information about a " ); Console::WriteLine( L"constructed type, its" ); Console::WriteLine( L" generic type definition, and an ordinary type." ); // Create a Dictionary of Test objects, using strings for the // keys. Dictionary< String^,Test^ >^ d = gcnew Dictionary< String^,Test^ >; // Display information for the constructed type and its generic // type definition. DisplayGenericTypeInfo( d->GetType() ); DisplayGenericTypeInfo( d->GetType()->GetGenericTypeDefinition() ); // Display information for an ordinary type. DisplayGenericTypeInfo( String::typeid ); } }; int main() { Test::Main(); } /* This example produces the following output: --- Display information about a constructed type, its generic type definition, and an ordinary type. System.Collections.Generic.Dictionary[System.String,Test] Is this a generic type definition? False Is it a generic type? True List type arguments (2): System.String Test System.Collections.Generic.Dictionary[TKey,TValue] Is this a generic type definition? True Is it a generic type? True List type arguments (2): TKey (unassigned - parameter position 0) TValue (unassigned - parameter position 1) System.String Is this a generic type definition? False Is it a generic type? False */
import System.*; import System.Reflection.*; import System.Collections.Generic.*; public class Test { private static void DisplayGenericTypeInfo(Type t) { Console.WriteLine("\r\n{0}", t); Console.WriteLine("\tIs this a generic type definition? {0}", (System.Boolean)t.get_IsGenericTypeDefinition()); Console.WriteLine("\tDoes it have generic arguments? {0}", (System.Boolean)t.get_IsGenericType()); if (t.get_IsGenericType()) { // If this is a generic type, display the type arguments. Type typeArguments[] = t.GetGenericArguments(); Console.WriteLine("\tList type arguments ({0}):", (Int32)typeArguments.get_Length()); for (int iCtr = 0; iCtr < typeArguments.get_Length(); iCtr++) { Type tParam = typeArguments[iCtr]; // If this is a type parameter, display its // position. if (tParam.get_IsGenericParameter()) { Console.WriteLine("\t\t{0}\t(unassigned - parameter " + "position {1})", tParam, (Int32)tParam.get_GenericParameterPosition()); } else { Console.WriteLine("\t\t{0}", tParam); } } } } //DisplayGenericTypeInfo public static void main(String[] args) { Console.WriteLine("\r\n--- Display information about a " + "constructed type, its"); Console.WriteLine(" generic type definition, and an ordinary type."); // Create a Dictionary of Test objects, using strings for the // keys. Dictionary<String,Test> d = new Dictionary<String ,Test>(); // Display information for the constructed type and its generic // type definition. DisplayGenericTypeInfo(d.GetType()); DisplayGenericTypeInfo(d.GetType().GetGenericTypeDefinition()); // Display information for an ordinary type. DisplayGenericTypeInfo(String.class.ToType()); } //main } //Test /* This example produces the following output: --- Display information about a constructed type, its generic type definition, and an ordinary type. System.Collections.Generic.Dictionary[System.String,Test] Is this a generic type definition? False Is it a generic type? True List type arguments (2): System.String Test System.Collections.Generic.Dictionary[TKey,TValue] Is this a generic type definition? True Is it a generic type? True List type arguments (2): TKey (unassigned - parameter position 0) TValue (unassigned - parameter position 1) System.String Is this a generic type definition? False Is it a generic type? False */

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


Weblioに収録されているすべての辞書からType.IsGenericTypeDefinition プロパティを検索する場合は、下記のリンクをクリックしてください。

- Type.IsGenericTypeDefinition プロパティのページへのリンク