.NET 的 System.Type.GenericTypeArguments 和 System.Type.GetGenericArguments() 之间的区别
Difference between .NET's System.Type.GenericTypeArguments and System.Type.GetGenericArguments()
为什么 .NET Framework 提供两者
System.Type.GenericTypeArguments
和
System.Type.GetGenericArguments()
这两个 return 给定泛型类型的类型参数(都是 Type[]
)?
似乎 属性 和该方法公开了完全相同的功能,这意味着 API 的接口具有 redundant/duplicate 功能?
GenericTypeArguments
property returns an empty array if the type is a generic type defintion, while the GetGenericArguments
method returns 具有泛型参数类型的数组。
- 框架 4.5 中添加了
GenericTypeArguments
属性。
GenericTypeArguments
属性实际实现是调用GetGenericArguments
,当类型是泛型的实现时:
public virtual Type[] GenericTypeArguments {
get {
if (IsGenericType && !IsGenericTypeDefinition){
return GetGenericArguments();
} else {
return Type.EmptyTypes;
}
}
}
来源:http://referencesource.microsoft.com/#mscorlib/system/type.cs,0aa31a7de47b9dc7
当您查看这些成员的 MSDN 文章中的版本信息 文档时,它会变得更加明显。 WinRT 支持 GenericTypeArguments 属性(又名 Windows Store 应用程序),GetGenericArguments() 方法不受支持。
WinRT 在 .NET Framework 4.5 版中引起了许多变化,但大多数变化并不那么明显。框架中内置的 语言投影 掩盖了大部分基本的类型系统差异,并隐藏了 WinRT 的核心是基于 COM 的事实。但是,如果您使用 Reflection,则必须以非常不同的方式解决它。
为什么 .NET Framework 提供两者
System.Type.GenericTypeArguments
和
System.Type.GetGenericArguments()
这两个 return 给定泛型类型的类型参数(都是 Type[]
)?
似乎 属性 和该方法公开了完全相同的功能,这意味着 API 的接口具有 redundant/duplicate 功能?
GenericTypeArguments
property returns an empty array if the type is a generic type defintion, while theGetGenericArguments
method returns 具有泛型参数类型的数组。- 框架 4.5 中添加了
GenericTypeArguments
属性。
GenericTypeArguments
属性实际实现是调用GetGenericArguments
,当类型是泛型的实现时:
public virtual Type[] GenericTypeArguments {
get {
if (IsGenericType && !IsGenericTypeDefinition){
return GetGenericArguments();
} else {
return Type.EmptyTypes;
}
}
}
来源:http://referencesource.microsoft.com/#mscorlib/system/type.cs,0aa31a7de47b9dc7
当您查看这些成员的 MSDN 文章中的版本信息 文档时,它会变得更加明显。 WinRT 支持 GenericTypeArguments 属性(又名 Windows Store 应用程序),GetGenericArguments() 方法不受支持。
WinRT 在 .NET Framework 4.5 版中引起了许多变化,但大多数变化并不那么明显。框架中内置的 语言投影 掩盖了大部分基本的类型系统差异,并隐藏了 WinRT 的核心是基于 COM 的事实。但是,如果您使用 Reflection,则必须以非常不同的方式解决它。