.NET的System.Type.GenericTypeArguments和System.Type.GetGenericArguments()之间的区别

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的接口具有冗余/重复的功能?

Guf*_*ffa 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