Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如果可能,为什么泛型类型定义的基类型本身不是泛型类型定义?_C#_.net_Types_Type Systems_.net 4.6 - Fatal编程技术网

C# 如果可能,为什么泛型类型定义的基类型本身不是泛型类型定义?

C# 如果可能,为什么泛型类型定义的基类型本身不是泛型类型定义?,c#,.net,types,type-systems,.net-4.6,C#,.net,Types,Type Systems,.net 4.6,在下面的示例中,我试图理解为什么BaseType不是泛型类型定义,更一般地说,为什么它不仅仅等于typeof(List) 公共类MyList:列表 { } //这是正确的定义 typeof(列表)。IsGenericTypeDefinition //这是假的 //BaseType.FullName也是空的?!? //还有BaseType.IsConstructedGenericType是真的?!?!? //因此,BaseType!=类型(列表) typeof(MyList).BaseType.I

在下面的示例中,我试图理解为什么
BaseType
不是泛型类型定义,更一般地说,为什么它不仅仅等于
typeof(List)

公共类MyList:列表
{
}
//这是正确的定义
typeof(列表)。IsGenericTypeDefinition
//这是假的
//BaseType.FullName也是空的?!?
//还有BaseType.IsConstructedGenericType是真的?!?!?
//因此,BaseType!=类型(列表)
typeof(MyList).BaseType.IsGenericTypeDefinition;

编辑-以下是一些有关相关主题的有用链接


可以给你一些想法,也可能有用。谢谢链接!我将原始帖子中的内容以及我发现的其他一些内容包括在内,以供参考。有趣的是,
Type.BaseType
的文档涵盖了除泛型类型定义之外的所有情况,因此,如果您想了解技术,结果甚至没有正确定义。实际返回的是一个打开的类型
列表
,其中
T
未绑定(即
.GetGenericParameters()[0]。IsGenericParameter==true
)。这不是不合理的,但仍然没有记录在案。@Jeroenmoster-我发现了同样的情况;我阅读了5次文档,以确保我没有遗漏任何东西,但它没有得到解决!我同意这并不是不合理的,但它似乎是次优的,不像返回泛型类型定义那样直观。
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;