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

Dim instance As MethodInfo Dim returnValue As MethodInfo returnValue = instance.GetGenericMethodDefinition
現在のメソッドを構築する元になるジェネリック メソッド定義を表す MethodInfo オブジェクト。


ジェネリック メソッド定義は、メソッドを構築するためのテンプレートです。たとえば、ジェネリック メソッド定義 T M<T>(T t) (C# 構文の場合) (Visual Basic の場合は Function M(Of T)(ByVal tVal As T) As T) から int M<int>(int t) メソッド (Visual Basic の場合は Function M(Of Integer)(ByVal tVal As Integer) As Integer) の構築と呼び出しを行うことができます。この構築メソッドを表す MethodInfo オブジェクトの場合、GetGenericMethodDefinition メソッドはジェネリック メソッド定義を返します。
2 つの構築メソッドが同じジェネリック メソッド定義から作成された場合、GetGenericMethodDefinition メソッドは両方のメソッドに対して同じ MethodInfo オブジェクトを返します。
既にジェネリック メソッド定義を表している MethodInfo オブジェクトで GetGenericMethodDefinition を呼び出した場合、現在の MethodInfo が返されます。
ジェネリック メソッド定義に宣言型のジェネリック パラメータが含まれている場合は、構築された各型に固有のジェネリック メソッド定義になります。例として、C#、Visual Basic、および C++ の各コードを次に示します。
class B<U,V> {} class C<T> { public B<T,S> M<S>() {...}} Class B(Of U, V) End Class Class C(Of T) Public Function M(Of S)() As B(Of T, S) ... End Function End Class generic <typename U, typename V> ref class B {}; generic <typename T> ref class C { public: generic <typename S> B<T,S>^ M() {...}; };
構築型 C<int> (Visual Basic の場合は C(Of Integer)) では、ジェネリック メソッドの M は B<int, S> を返します。オープン型 C<T> では、M は B<T, S> を返します。どちらの場合も、IsGenericMethodDefinition プロパティは、M を表す MethodInfo に対して true を返すため、MakeGenericMethod は両方の MethodInfo オブジェクトで呼び出すことができます。構築型の場合、MakeGenericMethod を呼び出した結果は、呼び出すことのできる MethodInfo になります。オープン型の場合、MakeGenericMethod によって返される MethodInfo を呼び出すことはできません。
ジェネリック メソッドに固有の用語に関する一定の条件の一覧については、IsGenericMethod プロパティのトピックを参照してください。ジェネリック リフレクションで使用されるその他の用語に関する一定の条件の一覧については、IsGenericType のプロパティのトピックを参照してください。

ジェネリック メソッドを持つクラスと、メソッドの MethodInfo を取得し、メソッドを型引数にバインドし、バインドされたメソッドから元のジェネリック型定義を取得するために必要なコードを次のコード例に示します。
このコード例は、MakeGenericMethod メソッドのトピックで取り上げているコード例の一部分です。
' Define a class with a generic method. Public Class Example Public Shared Sub Generic(Of T)(ByVal toDisplay As T) Console.WriteLine(vbCrLf & "Here it is: {0}", toDisplay) End Sub End Class <br /><span space="preserve">...</span><br /> ' Create a Type object representing class Example, and ' get a MethodInfo representing the generic method. ' Dim ex As Type = GetType(Example) Dim mi As MethodInfo = ex.GetMethod("Generic") DisplayGenericMethodInfo(mi) ' Assign the Integer type to the type parameter of the Example ' method. ' Dim arguments() As Type = { GetType(Integer) } Dim miConstructed As MethodInfo = mi.MakeGenericMethod(arguments) DisplayGenericMethodInfo(miConstructed) <br /><span space="preserve">...</span><br /> ' Get the generic type definition from the constructed method, ' and show that it's the same as the original definition. ' Dim miDef As MethodInfo = miConstructed.GetGenericMethodDefinition() Console.WriteLine(vbCrLf & "The definition is the same: {0}", _ miDef Is mi)
// Define a class with a generic method. public class Example { public static void Generic<T>(T toDisplay) { Console.WriteLine("\r\nHere it is: {0}", toDisplay); } } <br /><span space="preserve">...</span><br /> // Create a Type object representing class Example, and // get a MethodInfo representing the generic method. // Type ex = typeof(Example); MethodInfo mi = ex.GetMethod("Generic"); DisplayGenericMethodInfo(mi); // Assign the int type to the type parameter of the Example // method. // MethodInfo miConstructed = mi.MakeGenericMethod(typeof(int)); DisplayGenericMethodInfo(miConstructed); <br /><span space="preserve">...</span><br /> // Get the generic type definition from the closed method, // and show it's the same as the original definition. // MethodInfo miDef = miConstructed.GetGenericMethodDefinition(); Console.WriteLine("\r\nThe definition is the same: {0}", miDef == mi);
// Define a class with a generic method. ref class Example { public: generic<typename T> static void Generic(T toDisplay) { Console::WriteLine("\r\nHere it is: {0}", toDisplay); } }; <br /><span space="preserve">...</span><br /> // Create a Type object representing class Example, and // get a MethodInfo representing the generic method. // Type^ ex = Example::typeid; MethodInfo^ mi = ex->GetMethod("Generic"); DisplayGenericMethodInfo(mi); // Assign the int type to the type parameter of the Example // method. // MethodInfo^ miConstructed = mi->MakeGenericMethod(int::typeid); DisplayGenericMethodInfo(miConstructed); <br /><span space="preserve">...</span><br /> // Get the generic type definition from the closed method, // and show it's the same as the original definition. // MethodInfo^ miDef = miConstructed->GetGenericMethodDefinition(); Console::WriteLine("\r\nThe definition is the same: {0}", miDef == mi);

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に収録されているすべての辞書からMethodInfo.GetGenericMethodDefinition メソッドを検索する場合は、下記のリンクをクリックしてください。

- MethodInfo.GetGenericMethodDefinition メソッドのページへのリンク