📜  c# 检查类型是否实现接口 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:05.031000             🧑  作者: Mango

代码示例1
typeof(IMyInterface).IsAssignableFrom(typeof(MyType))
  // or
typeof(MyType).GetInterfaces().Contains(typeof(IMyInterface))
  // or for a generic interface, it’s a bit different:
typeof(MyType).GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IMyInterface<>)