Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
true
if the MethodInfo object represents the definition of a generic method; otherwise, false
.
The following code example uses the IsGenericMethodDefinition
property to display a message indicating whether a MethodInfo represents a generic method definition.
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);
If the current MethodInfo represents a generic method definition, then:
IsGenericMethodDefinition
returns true
.
For each Type object in the array returned by the GetGenericArguments() method:
true
.Use the IsGenericMethodDefinition
property to determine whether type arguments have been assigned to the type parameters of a generic method. 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. For example, consider the following code:
```csharp
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);
}
};
```
The method body of M contains a call to method N, specifying the type parameter of M and the type Int32. The IsGenericMethodDefinition
property returns false for method N<V,int>
.
Note
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. For example, consider the following 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() {...};
};
```
In the constructed type C<int>
(C(Of Integer)
in Visual Basic), the generic method M returns B<int, S>
. In the open type C<T>
, M returns B<T, S>
. In both cases, the IsGenericMethodDefinition
property returns true
for the MethodInfo that represents M.
For a list of the invariant conditions for terms specific to generic methods, see the IsGenericMethod property. For a list of the invariant conditions for other terms used in generic reflection, see the IsGenericType property.
Product | Versions |
---|---|
.NET Framework | 2.0, 3.0, 3.5 |
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in