【发布时间】:2019-03-31 07:13:31
【问题描述】:
我想确定某个对象是从IEnumerable 派生的,但反射说List<int> 不是IEnumerable 的子类。
https://dotnetfiddle.net/an1n62
var a = new List<int>();
// true
Console.WriteLine(a is IEnumerable);
// falsa
Console.WriteLine(a.GetType().IsSubclassOf(typeof(IEnumerable)));
Console.WriteLine(a.GetType().IsSubclassOf(typeof(IEnumerable<>)));
Console.WriteLine(a.GetType().IsSubclassOf(typeof(IEnumerable<int>)));
is 关键字有效,但我必须在没有关键字的情况下解决这个问题。
【问题讨论】:
-
IsAssignableFrom
标签: c# .net reflection