.NET与x27之间的差异;s System.Type.GenericTypeArguments和System.Type.GetGenericArguments()
为什么.NET框架同时提供这两种功能.NET与x27之间的差异;s System.Type.GenericTypeArguments和System.Type.GetGenericArguments(),.net,generics,system.type,.net,Generics,System.type,为什么.NET框架同时提供这两种功能 System.Type.GenericTypeArguments 及 哪两个都返回给定泛型类型的类型参数(都作为类型[] 属性和方法似乎公开了完全相同的功能,这意味着API的接口具有冗余/重复的功能? 如果类型是泛型类型定义,则返回空数组,而返回包含泛型参数类型的数组 框架4.5中添加了GenericTypeArguments属性 当类型是泛型类型的实现时,GenericTypeArguments属性实际用于调用GetGenericArguments:
System.Type.GenericTypeArguments
及
哪两个都返回给定泛型类型的类型参数(都作为类型[]
属性和方法似乎公开了完全相同的功能,这意味着API的接口具有冗余/重复的功能?- 如果类型是泛型类型定义,则返回空数组,而返回包含泛型参数类型的数组
- 框架4.5中添加了
属性GenericTypeArguments
GenericTypeArguments
属性实际用于调用GetGenericArguments
:
public virtual Type[] GenericTypeArguments {
get {
if (IsGenericType && !IsGenericTypeDefinition){
return GetGenericArguments();
} else {
return Type.EmptyTypes;
}
}
}
来源:当您查看MSDN文章中针对这些成员的版本信息文档时,会更加明显。WinRT(又称Windows应用商店应用程序)支持GenericTypeArguments属性,但GetGenericArguments()方法不支持
WinRT在.NETFramework 4.5版中引起了许多变化,但大多数变化并不明显。框架中内置的语言投影掩盖了大多数基本类型系统的差异,并隐藏了WinRT的核心是基于COM的事实。但是,如果使用反射,则不会。必须以非常不同的方式处理它。真的吗?真奇怪。。。如果GenericTypeArguments的用途和您所说的一样,那么它不应该是布尔值吗?!返回一个空数组有什么用?为了说明一个类型是否是泛型类型定义@Veverke:如果类型是泛型类型的实现,则返回一个类型数组
typeof(列表)。GenericTypeArguments
返回一个空数组,typeof(列表)。GenericTypeArguments
返回一个包含typeof(int)
和typeof(列表)的数组。GetGenericArguments()
返回一个包含泛型参数T
类型的数组。哦。。。这一点更清楚,尽管要保持这些名称的正确性并非易事……我忘了.NET是去年11月开放源码的。。。我想搜索代码,但认为它还没有发生。谢谢
public virtual Type[] GenericTypeArguments {
get {
if (IsGenericType && !IsGenericTypeDefinition){
return GetGenericArguments();
} else {
return Type.EmptyTypes;
}
}
}