using System; using System.Linq; namespace ln.type { public static class TypeExtensions { public static bool HasGenericInterface(this Type type) => HasGenericInterface(type, typeof(T).GetGenericTypeDefinition()); public static bool HasGenericInterface(this Type type, Type genericInterfaceType) { return type.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == genericInterfaceType); } public static Type GetGenericInterface(this Type type) => GetGenericInterface(type, typeof(T).GetGenericTypeDefinition()); public static Type GetGenericInterface(this Type type, Type genericInterfaceType) { return type.GetInterfaces().First(x => x.IsGenericType && x.GetGenericTypeDefinition() == genericInterfaceType); } } }