MethodInfo.GetGenericMethodDefinition メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > MethodInfo.GetGenericMethodDefinition メソッドの意味・解説 

MethodInfo.GetGenericMethodDefinition メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

現在のメソッド構築する元になるジェネリック メソッド定義を表す MethodInfo オブジェクト返します

名前空間: System.Reflection
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<ComVisibleAttribute(True)> _
Public Overridable Function
 GetGenericMethodDefinition As MethodInfo
Dim instance As MethodInfo
Dim returnValue As MethodInfo

returnValue = instance.GetGenericMethodDefinition
[ComVisibleAttribute(true)] 
public virtual MethodInfo GetGenericMethodDefinition ()
[ComVisibleAttribute(true)] 
public:
virtual MethodInfo^ GetGenericMethodDefinition ()
/** @attribute ComVisibleAttribute(true) */ 
public MethodInfo GetGenericMethodDefinition ()
ComVisibleAttribute(true) 
public function GetGenericMethodDefinition
 () : MethodInfo

戻り値
現在のメソッド構築する元になるジェネリック メソッド定義を表す MethodInfo オブジェクト

例外例外
例外種類条件

InvalidOperationException

現在のメソッドジェネリック メソッドではありません。つまり、IsGenericMethod は false返します

解説解説

ジェネリック メソッド定義は、メソッド構築するためのテンプレートです。たとえば、ジェネリック メソッド定義 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)) では、ジェネリック メソッドMB<int, S>返しますオープン型 C<T> では、MB<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);
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からMethodInfo.GetGenericMethodDefinition メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からMethodInfo.GetGenericMethodDefinition メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からMethodInfo.GetGenericMethodDefinition メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「MethodInfo.GetGenericMethodDefinition メソッド」の関連用語

MethodInfo.GetGenericMethodDefinition メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



MethodInfo.GetGenericMethodDefinition メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS