List<int>
'un GenericTypeDefinition ürününün ICollection<>
genel bir arabirimini içermesini beklediğim basit kod. Yine de, bunları düzgün bir şekilde karşılaştırmamı sağlayan List<int>
'dan kabul edilebilir bir tür türemiyorum.GenericType Arabirimlerin Karşılaştırılması
using System;
using System.Collections.Generic;
using System.Linq;
public class Test
{
public static void Main()
{
var a = typeof(List<int>);
var b = typeof(ICollection<>);
var r1 = a.GetGenericTypeDefinition().GetInterfaces();
foreach (var x in r1)
{
Console.WriteLine(x);
}
Console.WriteLine();
Console.WriteLine(b);
Console.WriteLine();
Console.WriteLine(r1.Any(x => x == b));
}
}
Çıktı
System.Collections.Generic.IEnumerable`1[T]
System.Collections.Generic.IReadOnlyList`1[T]
System.Collections.Generic.IReadOnlyCollection`1[T]
System.Collections.IEnumerable
System.Collections.Generic.IList`1[T]
System.Collections.Generic.ICollection`1[T]
System.Collections.ICollection
System.Collections.IList
System.Collections.Generic.ICollection`1[T]
False
Ben
r1
b
eşit olduğu bir tür içerdiğini beklerdik
. Sabit
DÜZENLEME Jon Skeet bana neler olduğunu içine doğru bir fikir verdi. T
IList<T>
tip parametredir
System.Collections.Generic.IEnumerable`1[T]
System.Collections.Generic.IReadOnlyList`1[T]
System.Collections.Generic.IReadOnlyCollection`1[T]
System.Collections.Generic.ICollection`1[T]
System.Collections.Generic.IList`1[T]
System.Collections.Generic.ICollection`1[T]
True
Teşekkür ederim, bana ihtiyacım olan bilgiyi verdin. –