代码之家  ›  专栏  ›  技术社区  ›  jethro

比较封闭式和开放式

  •  8
  • jethro  · 技术社区  · 16 年前

    我很好奇如何检查给定类型是否已关闭 开放式的。例如

    public bool IsGenericList(Type source)
    {
        return (source.IsGenericType &&
                /*here goes the manipulation on source type*/ == typeof(List<>));
    }
    
    1 回复  |  直到 16 年前
        1
  •  14
  •   Jon Skeet    16 年前

    Type.GetGenericTypeDefinition :

    public bool IsGenericList(Type source)
    {
        return source.IsGenericType &&
               source.GetGenericTypeDefinition() == typeof(List<>);
    }