Aracılığıyla paylaş


MethodInfo.GetGenericMethodDefinition Yöntem

Tanım

MethodInfo Geçerli yöntemin oluşturulabileceği genel yöntem tanımını temsil eden bir nesne döndürür.

public:
 virtual System::Reflection::MethodInfo ^ GetGenericMethodDefinition();
public virtual System.Reflection.MethodInfo GetGenericMethodDefinition();
[System.Runtime.InteropServices.ComVisible(true)]
public virtual System.Reflection.MethodInfo GetGenericMethodDefinition();
abstract member GetGenericMethodDefinition : unit -> System.Reflection.MethodInfo
override this.GetGenericMethodDefinition : unit -> System.Reflection.MethodInfo
[<System.Runtime.InteropServices.ComVisible(true)>]
abstract member GetGenericMethodDefinition : unit -> System.Reflection.MethodInfo
override this.GetGenericMethodDefinition : unit -> System.Reflection.MethodInfo
Public Overridable Function GetGenericMethodDefinition () As MethodInfo

Döndürülenler

MethodInfo Geçerli yöntemin oluşturulabileceği genel yöntem tanımını temsil eden bir nesne.

Öznitelikler

Özel durumlar

Geçerli yöntem genel bir yöntem değildir. Yani döndürür IsGenericMethodfalse.

Bu yöntem desteklenmez.

Örnekler

Aşağıdaki kod örneği, genel bir yönteme sahip bir sınıfı ve yöntemi için bir almak MethodInfo için gereken kodu gösterir, yöntemi bağımsız değişkenler yazmak için bağlar ve özgün genel tür tanımını ilişkili yöntemden geri alır.

Bu örnek, yöntemi için MakeGenericMethod sağlanan daha büyük bir örneğin parçasıdır.

// 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);
    }
}
' 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
// 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);
' 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)
// 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);
' 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)

Açıklamalar

Genel yöntem tanımı, yöntemlerin oluşturulabileceği bir şablondur. Örneğin, genel yöntem tanımından T M<T>(T t) (C# söz diziminde ifade edilir; Function M(Of T)(ByVal tVal As T) As T Visual Basic'te) yöntemini int M<int>(int t) oluşturabilir ve çağırabilirsiniz (Function M(Of Integer)(ByVal tVal As Integer) As Integer Visual Basic'te). Bu yapılı yöntemi temsil eden bir MethodInfo nesne verildiğinde, GetGenericMethodDefinition yöntem genel yöntem tanımını döndürür.

Aynı genel yöntem tanımından iki oluşturulmuş yöntem oluşturulursa, GetGenericMethodDefinition yöntem her iki yöntem için de aynı MethodInfo nesneyi döndürür.

Zaten genel bir yöntem tanımını temsil eden bir MethodInfo üzerinde çağrısı GetGenericMethodDefinition yaparsanız, geçerli MethodInfodöndürür.

Genel yöntem tanımı bildirim türünün genel parametrelerini içeriyorsa, her bir yapı türüne özgü genel bir yöntem tanımı olacaktır. Örneğin, aşağıdaki kodu göz önünde bulundurun:

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

(Visual Basic'te) yapısında C<int>C(Of Integer) genel yöntem M döndürürB<int, S>. açık türünde C<T>döndürür MB<T, S>. Her iki durumda IsGenericMethodDefinition da özelliğini temsil Meden için MethodInfo döndürürtrue, bu nedenle MakeGenericMethod her iki MethodInfo nesnede de çağrılabilir. Yapılandırılmış tür söz konusu olduğunda, çağrının MakeGenericMethod sonucu çağrılabilen bir MethodInfo sonucudur. Açık tür söz konusu olduğunda, MethodInfo tarafından MakeGenericMethod döndürülen çağrılamaz.

Genel yöntemlere özgü koşulların sabit koşullarının listesi için özelliğine IsGenericMethod bakın. Genel yansımada kullanılan diğer terimlere ilişkin sabit koşulların listesi için özelliğine IsGenericType bakın.

Şunlara uygulanır

Ayrıca bkz.