Export (0) Print
Expand All

MethodInfo.ContainsGenericParameters Property

Note: This property is new in the .NET Framework version 2.0.

Gets a value indicating whether a generic method contains unassigned generic type parameters.

Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)

'Declaration
Public Overrides ReadOnly Property ContainsGenericParameters As Boolean
'Usage
Dim instance As MethodInfo
Dim value As Boolean

value = instance.ContainsGenericParameters

/** @property */
public boolean get_ContainsGenericParameters ()

public override function get ContainsGenericParameters () : boolean

Property Value

true if the current MethodInfo contains unassigned generic type parameters; otherwise, false.

To invoke a generic method, there must be no generic type definitions or open constructed types in the type arguments of the method itself, or in any enclosing types. Making this recursive determination can be difficult. For convenience, and to reduce the chance of error, the ContainsGenericParameters property provides a standard way to distinguish between closed constructed methods, which can be invoked, and open constructed methods, which cannot. If the ContainsGenericParameters property returns true, the method cannot be invoked.

The ContainsGenericParameters property searches recursively for type parameters. For example, it returns true for any method in an open type A<T> (A(Of T) in Visual Basic), even though the method itself is not generic. Contrast this with the behavior of the IsGenericMethod property, which returns false for such a method.

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.

The following code example uses the ContainsGenericParameters property to display a message indicating whether a MethodInfo is an open generic method (that is, whether it has unbound type parameters).

This example is part of a larger example provided for the MakeGenericMethod method.

Console.WriteLine(vbTab _
    & "Does it have unassigned generic parameters? {0}", _
    mi.ContainsGenericParameters)

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

.NET Compact Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft