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 ?
GenericTypeArguments
property returns an empty array if the type is a generic type defintion, while the GetGenericArguments
method returns an array with the types for the generic arguments.GenericTypeArguments
property was added in framework 4.5.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
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.
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