SFu*_*n28 5 .net c# types type-systems .net-4.6
在下面的示例中,我试图理解为什么BaseType不是泛型类型定义,更一般地说,为什么它不只是等于typeof(List<>)
public class MyList<T> : List<T>
{
}
// this is true by definition
typeof(List<>).IsGenericTypeDefinition
// this is false
// also the BaseType.FullName is null ?!?
// also BaseType.IsConstructedGenericType is true ?!?!?
// as such, BaseType != typeof(List<>)
typeof(MyList<>).BaseType.IsGenericTypeDefinition;
Run Code Online (Sandbox Code Playgroud)
编辑-以下是相关主题的一些有用链接:
Type.IsGenericTypeDefinition 和 Type.ContainsGenericParameters 之间的区别
https://learn.microsoft.com/en-us/dotnet/api/system.type.isgenerictype
| 归档时间: |
|
| 查看次数: |
175 次 |
| 最近记录: |