Why are generic type definitions in C # not the same as those they inherit from

I expected the next test to pass, but it is not.

var iCollectionType = typeof(ICollection<>);
var listSuper = typeof(List<>).GetInterfaces().First(i => i.GUID == iCollectionType.GUID);
Assert.That(listSuper, Is.EqualTo(iCollectionType));

I know that the same type loaded in 2 different application domains is not considered equal. I don’t see how this can happen in the above code, but I checked the AssemblyQualifiedName of each type and, of course, they are different.

iCollectionType.AssemblyQualifiedName.Dump();
//System.Collections.Generic.ICollection`1, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

listSuper.AssemblyQualifiedName.Dump();
//null

When I tested further, I found that this applies to all common interfaces in the list of interfaces for defining a common type, as well as for basic base types; but not for non-generic interfaces and base types, nor for constructed generic types.

I would like to know why the general type definitions that I get using typeof seem incompatible with those listed in their inheritance list and base type. This seems less than surprising.

Type.AssemblyQualifiedName MSDN, .

Type , null.

, , , , .

LinqPad v5.02.03, .

+4

Source: https://habr.com/ru/post/1617052/


All Articles