MethodInfo.IsGenericMethodDefinition MethodInfo.IsGenericMethodDefinition MethodInfo.IsGenericMethodDefinition MethodInfo.IsGenericMethodDefinition Property

定义

获取一个值,该值指示当前 MethodInfo 是否表示泛型方法的定义。Gets a value indicating whether the current MethodInfo represents the definition of a generic method.

public:
 virtual property bool IsGenericMethodDefinition { bool get(); };
public override bool IsGenericMethodDefinition { get; }
member this.IsGenericMethodDefinition : bool
Public Overrides ReadOnly Property IsGenericMethodDefinition As Boolean

属性值

如果 MethodInfo 对象表示泛型方法的定义,则为 true;否则为 falsetrue if the MethodInfo object represents the definition of a generic method; otherwise, false.

示例

下面的代码示例使用IsGenericMethodDefinition属性来显示一条消息,指示MethodInfo是否表示泛型方法定义。The following code example uses the IsGenericMethodDefinition property to display a message indicating whether a MethodInfo represents a generic method definition.

此示例摘自为MakeGenericMethod方法提供的一个更大的示例。This example is part of a larger example provided for the MakeGenericMethod method.

Console.WriteLine(vbTab _
    & "Is this a generic method definition? {0}", _
    mi.IsGenericMethodDefinition)
Console.WriteLine("\tIs this a generic method definition? {0}", 
    mi.IsGenericMethodDefinition);
Console::WriteLine("\tIs this a generic method definition? {0}", 
    mi->IsGenericMethodDefinition);

注解

如果当前MethodInfo表示泛型方法定义,则:If the current MethodInfo represents a generic method definition, then:

IsGenericMethodDefinition使用属性可确定是否已将类型参数分配给泛型方法的类型参数。Use the IsGenericMethodDefinition property to determine whether type arguments have been assigned to the type parameters of a generic method. 如果已分配类型参数,即使某些IsGenericMethodDefinition类型参数是表示封闭类型的类型参数的对象Type ,属性也会返回 false。If type arguments have been assigned, the IsGenericMethodDefinition property returns false even if some of the type arguments are Type objects that represent type parameters of enclosing types. 例如,请考虑以下 C#、Visual Basic 和C++代码:For example, consider the following C#, Visual Basic, and C++ code:

```cs
class C
{
    T N<T,U>(T t, U u) {...}
    public V M<V>(V v)
    {
        return N<V,int>(v, 42);
    }
}
```

```vb
Class C
    Public Function N(Of T,U)(ByVal ta As T, ByVal ua As U) As T
        ...
    End Function
    Public Function M(Of V)(ByVal va As V ) As V
        Return N(Of V, Integer)(va, 42)
    End Function
End Class
```

```cpp
ref class C
{
private:
    generic <typename T, typename U> T N(T t, U u) {...}
public:
    generic <typename V> V M(V v)
    {
        return N<V, int>(v, 42);
    }
};
```

M 的方法体包含对方法 N 的调用,该方法指定 M 的类型参数和类型Int32The method body of M contains a call to method N, specifying the type parameter of M and the type Int32. 对于方法N<V,int>,属性返回 false。 IsGenericMethodDefinitionThe IsGenericMethodDefinition property returns false for method N<V,int>.

备注

尽管在通过 c 类N<V,int>反射时未遇到开放构造方法,但必须使用MakeGenericMethod生成该方法才能将 C 作为动态类发出。Although the open constructed method N<V,int> is not encountered when reflecting over class C, it must be generated using MakeGenericMethod in order to emit C as a dynamic class.

如果泛型方法定义包含声明类型的泛型参数,则会有特定于每个构造类型的泛型方法定义。If a generic method definition includes generic parameters of the declaring type, there will be a generic method definition specific to each constructed type. 例如,请考虑以下 C#和 Visual Basic 代码:For example, consider the following C# and Visual Basic code:

```csharp
class B<U,V> {}
class C<T> { public B<T,S> M<S>() {...}}
```

```vb
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
```

```cpp
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>In the constructed type C<int> (C(Of Integer) in Visual Basic), the generic method M returns B<int, S>. 在 open 类型C<T>中,M 返回B<T, S>In the open type C<T>, M returns B<T, S>. 在这两种情况IsGenericMethodDefinition下, true属性将MethodInfo返回表示 M 的。In both cases, the IsGenericMethodDefinition property returns true for the MethodInfo that represents M.

有关特定于泛型方法的术语的固定条件列表,请参见IsGenericMethod属性。For a list of the invariant conditions for terms specific to generic methods, see the IsGenericMethod property. 有关泛型反射中使用的其他术语的固定条件列表,请参见IsGenericType属性。For a list of the invariant conditions for other terms used in generic reflection, see the IsGenericType property.

适用于

另请参阅