MethodInfo.GetGenericMethodDefinition 메서드

정의

현재 메서드를 생성하는 데 사용할 수 있는 제네릭 메서드 정의를 나타내는 MethodInfo 개체를 반환합니다.

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

반환

MethodInfo

현재 메서드를 생성하는 데 사용할 수 있는 제네릭 메서드 정의를 나타내는 MethodInfo 개체입니다.

특성

예외

현재 메서드가 제네릭 메서드가 아닌 경우. 즉, IsGenericMethodfalse를 반환합니다.

이 메서드는 지원되지 않습니다.

예제

다음 코드 예제에서는 제네릭 메서드가 있는 클래스와 메서드를 가져오 MethodInfo 고, 메서드를 형식 인수에 바인딩하고, 바인딩된 메서드에서 원래 제네릭 형식 정의를 다시 가져오는 데 필요한 코드를 보여줍니다.

이 예제는 메서드에 제공된 더 큰 예제의 MakeGenericMethod 일부입니다.

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

설명

제네릭 메서드 정의는 메서드를 생성할 수 있는 템플릿입니다. 예를 들어 제네릭 메서드 정의 T M<T>(T t) (C# 구문으로 표현됨, Function M(Of T)(ByVal tVal As T) As T Visual Basic)에서 메서드 int M<int>(int t) 를 생성하고 호출할 수 있습니다(Function M(Of Integer)(ByVal tVal As Integer) As IntegerVisual Basic). MethodInfo 이 생성된 메서드를 나타내는 개체를 지정하면 메서드는 GetGenericMethodDefinition 제네릭 메서드 정의를 반환합니다.

동일한 제네릭 메서드 정의에서 생성된 두 메서드가 만들어지면 메서드는 GetGenericMethodDefinition 두 메서드에 대해 동일한 MethodInfo 개체를 반환합니다.

이미 제네릭 메서드 정의를 나타내는 값을 호출 GetGenericMethodDefinition MethodInfo 하면 현재 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> (C(Of Integer)Visual Basic)에서 제네릭 메서드 M 는 반환합니다B<int, S>. 열려 있는 형식 C<T>``M 에서 .를 반환합니다B<T, S>. 두 경우 IsGenericMethodDefinition 모두 속성을 나타내는 M속성이 MethodInfo 반환 true 되므로 MakeGenericMethod 두 개체에서 모두 MethodInfo 호출할 수 있습니다. 생성된 형식의 경우 호출 MakeGenericMethod 결과는 호출할 수 있는 MethodInfo 결과입니다. 열린 형식의 경우 반환 MakeGenericMethod 된 형식을 MethodInfo 호출할 수 없습니다.

제네릭 메서드와 관련된 용어에 대한 고정 조건 목록은 속성을 참조 IsGenericMethod 하세요. 제네릭 리플렉션에 사용되는 다른 용어에 대한 고정 조건 목록은 속성을 참조 IsGenericType 하세요.

적용 대상

추가 정보