相关疑难解决方法(0)

检查类是否派生自泛型类

我的项目中有一个派生类的泛型类.

public class GenericClass<T> : GenericInterface<T>
{
}

public class Test : GenericClass<SomeType>
{
}
Run Code Online (Sandbox Code Playgroud)

有没有办法找出一个Type对象是否来自GenericClass

t.IsSubclassOf(typeof(GenericClass<>))
Run Code Online (Sandbox Code Playgroud)

不起作用.

c# generics reflection

287
推荐指数
11
解决办法
14万
查看次数

标签 统计

c# ×1

generics ×1

reflection ×1