C# 有关泛型类继承
泛型的继承判断:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
public static bool IsAssignableToGenericType(Type givenType, Type genericType) { var interfaceTypes = givenType.GetInterfaces(); foreach (var it in interfaceTypes) { if (it.IsGenericType && it.GetGenericTypeDefinition() == genericType) return true; } if (givenType.IsGenericType && givenType.GetGenericTypeDefinition() == genericType) return true; Type baseType = givenType.BaseType; if (baseType == null) return false; return IsAssignableToGenericType(baseType, genericType); } |
比如泛型类声明:
1 |
abstract public class BaseClass<T> where T : BaseClass<T> |
子类 ClassA Continue reading C# 有关泛型类继承