且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何确定一个类型是否实现了特定的泛型接口类型

更新时间:2022-06-11 21:29:34

通过使用 TcKs 的答案,也可以使用以下 LINQ 查询来完成:

By using the answer from TcKs it can also be done with the following LINQ query:

bool isBar = foo.GetType().GetInterfaces().Any(x =>
  x.IsGenericType &&
  x.GetGenericTypeDefinition() == typeof(IBar<>));