What's the difference between the Type.GenericTypeArguments property and the Type.GetGenericArguments() method? Do they always return the same thing or are there situations where they differ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With