namespace Connected.Interop { public static class Generics { public static bool IsSubclassOfGenericType(this Type type, Type genericType) { var current = type.BaseType; while (current is not null && current != typeof(object)) { var currentType = current.IsGenericType ? current.GetGenericTypeDefinition() : current; if (genericType == currentType) return true; current = current.BaseType; } return false; } } }