public static bool IsGenericSubclassOf(this Type type, Type superType)
{
    if (type.BaseType != null 
        && !type.BaseType.Equals(typeof(object))
        && type.BaseType.IsGenericType)
    {
        if (type.BaseType.GetGenericTypeDefinition().Equals(superType))
        {
            return true;
        }
        return type.BaseType.IsGenericSubclassOf(superType);
    }

    return false;
} 

 使用

typeof(AAA).IsGenericSubclassOf(typeof(A<>))

 

相关文章:

  • 2021-07-22
  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
  • 2021-06-11
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-21
  • 2022-12-23
  • 2021-07-08
  • 2022-12-23
  • 2021-10-24
  • 2022-12-23
相关资源
相似解决方案