System.Type.GetGenericArguments Method

Returns an array of Type objects that represent the type arguments of a generic type or the type parameters of a generic type definition.

Syntax

public virtual Type[] GetGenericArguments ()

Returns

An array of Type objects that represent the type arguments of a generic type. Returns an empty array if the current type is not a generic type.

Remarks

The array elements are returned in the order in which they appear in the list of type arguments for the generic type.

  • If the current type is a closed constructed type (that is, the Type.ContainsGenericParameters property returns false), the array returned by the Type.GetGenericArguments method contains the types that have been assigned to the generic type parameters of the generic type definition.

  • If the current type is a generic type definition, the array contains the type parameters.

  • If the current type is an open constructed type (that is, the Type.ContainsGenericParameters property returns true) in which specific types have not been assigned to all of the type parameters and type parameters of enclosing generic types or methods, the array contains both types and type parameters. Use the Type.IsGenericParameter property to tell them apart. For a demonstration of this scenario, see the code example for the Type.ContainsGenericParameters property.

For a list of the invariant conditions for terms used in generic reflection, see the Type.IsGenericType property remarks.

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