Vev*_*rke 4 .net generics system.type
.NET Framework为什么同时提供这两种功能
System.Type.GenericTypeArguments
Run Code Online (Sandbox Code Playgroud)
和
System.Type.GetGenericArguments()
Run Code Online (Sandbox Code Playgroud)
哪个都返回Type[]给定泛型类型的类型参数(都作为)?
似乎属性和方法具有完全相同的功能,这意味着API的接口具有冗余/重复的功能?
GenericTypeArguments属性返回一个空数组,而该GetGenericArguments方法返回具有泛型参数类型的数组。GenericTypeArguments属性已添加到框架4.5中。当类型是泛型类型的实现时,GenericTypeArguments实际上实现了该属性以进行调用GetGenericArguments:
public virtual Type[] GenericTypeArguments {
get {
if (IsGenericType && !IsGenericTypeDefinition){
return GetGenericArguments();
} else {
return Type.EmptyTypes;
}
}
}
Run Code Online (Sandbox Code Playgroud)
来源:http : //referencesource.microsoft.com/#mscorlib/system/type.cs,0aa31a7de47b9dc7
| 归档时间: |
|
| 查看次数: |
536 次 |
| 最近记录: |