MethodInfo.ContainsGenericParameters Property
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 that indicates whether a generic method contains unassigned generic type parameters.
public:
virtual property bool ContainsGenericParameters { bool get(); };
public override bool ContainsGenericParameters { get; }
member this.ContainsGenericParameters : bool
Public Overrides ReadOnly Property ContainsGenericParameters As Boolean
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>
, 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.
Product | Versions |
---|---|
.NET Framework | 2.0, 3.0, 3.5 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: