Difference between .NET's System.Type.GenericTypeArguments and System.Type.GetGenericArguments()

771 views Asked by At

Why does the .NET Framework provide both

System.Type.GenericTypeArguments

and

System.Type.GetGenericArguments()

which both return the type arguments (both as a Type[]) of a given generic type ?

Seems the property and the method expose the very same functionality, meaning the API's interface has redundant/duplicate functionalities ?

2

There are 2 answers

4
Guffa On BEST ANSWER

The GenericTypeArguments property is actually implemented to call GetGenericArguments when the type is an implementation of a generic type:

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

Source: http://referencesource.microsoft.com/#mscorlib/system/type.cs,0aa31a7de47b9dc7

0
Hans Passant On

It will become more obvious when you look at the Version Information documentation in the MSDN articles for these members. The GenericTypeArguments property is supported for WinRT (aka Windows Store apps), the GetGenericArguments() method is not.

WinRT caused many changes in .NET Framework version 4.5, most however are not that obvious. The language projection built into the framework covers up most of the fundamental type system differences and hides the fact that WinRT is COM-based at its core. Not if you use Reflection however, it had to be tackled very differently.