Type.GenericTypeArguments property vs Type.GetGenericArguments() method

typeof(List<>) is an example where they differ. The property returns an empty array, while the method returns an array with a generic T in it. (this T has IsGenericParameter true)

From reading the documentation, I think that you can think of GenericTypeArguments as GetGenericArguments().Where(t => !t.IsGenericParameter).ToArray(), i.e. only the concrete types. See also ContainsGenericParameters.


The reference source tells the exact answer:

public virtual Type[] GenericTypeArguments{
    get{
        if(IsGenericType && !IsGenericTypeDefinition){
            return GetGenericArguments();
        }
        else{
            return Type.EmptyTypes;
    }
}

This implementation is never overridden with something else.

Tags:

C#

Reflection

F#