给定以下类层次结构
public abstract class MyGenericClass<T1, T2>
{
public T1 Foo { get; set; }
public T2 Bar { get; set; }
}
public class BobGeneric : MyGenericClass<int, string>{}
public class JimGeneric : MyGenericClass<System.Net.Cookie, System.OverflowException>{}
我本以为我可以做到以下几点
//All types in the assembly containing BobGeneric and JimGeneric
var allTypes = _asm.GetTypes();
//This works for interfaces, but not here
var specialTypes = allTypes.Where(x => typeof(MyGenericClass<,>).IsAssignableFrom(x))
//This also fails
typeof(BobGeneric).IsSubclassOf(typeof(MyGenericClass<,>)).Dump();
我将如何确定BobGeneric
继承自的代码MyGenericClass
?