System.Type.ContainsGenericParameters Property

Gets a value indicating whether the current Type object has type parameters that have not been replaced by specific types.

Syntax

public virtual bool ContainsGenericParameters { get; }

Value

true if a Type object contains unassigned generic parameters; otherwise false.

Remarks

In order to create an instance of a type, there must be no generic type definitions or open constructed types in the type arguments of the type itself, in any enclosing generic types, or in any elements of the type. Another way of saying this is that when examined recursively, the type must contain no generic type parameters.

Since types can be arbitrarily complex, making this determination is difficult. For convenience and to reduce the chance of error, the Type.ContainsGenericParameters property provides a standard way to distinguish between closed constructed types, which can be instantiated, and open constructed types, which cannot. If the Type.ContainsGenericParameters property returns true, the type cannot be instantiated.

The Type.ContainsGenericParameters property searches recursively for type parameters. For example, it returns true for an array whose elements are type A<T> (A(Of T) in Visual Basic), even though the array is not itself generic. Contrast this with the behavior of the Type.IsGenericType property, which returns false for arrays.

For a set of example classes and a table showing the values of the Type.ContainsGenericParameters property, see Type.IsGenericType.

Example

For an example of using this method, see the example for Type.GenericParameterPosition.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0