• 首先说下 IsGenericType

    用3个实例说明:
   typeof(DateTime).IsGenericType : false
typeof(List<int>).IsGenericType: true
typeof(Dictionary<,>).IsGenericType:true

类型如果是泛型则为 true

但是要注意以下情况:

T[], List[] 等等数组时, IsGenericType为False

typeof(T[]).GetElementType().IsGenericType才是True


  • 接着说 IsGenericTypeDefinition

    用2个实例说明:
   typeof(List<int>).IsGenericTypeDefintion : false
typeof(List<>).IsGenericTypeDefinition :true

IsGenericTypeDefinition : 获取一个值,该值指示当前 Type 是否表示可以用来构造其他泛型类型的泛型类型定义。

也就是说表明 这个 type 是否可以用于构建泛型定义

比如 List<> 可以通过反射构建出 List,List

例子:

var typeList = typeof(List<>);
Type typeDataList = typeList.MakeGenericType( typeof(DateTime)); //通过List<>构建出List<DateTime>

  • 最后说下 IsGenericParameter

    这个Property用于表明当前类型是一个T类型

    例如:
    typeof(List<>).GetGenericArguments()
返回: new Type[]{ typeof(T) }
此时:
typeof(T).IsGenericParameter == True
typeof(T).GenericParameterPosition == 0

对比:

 typeof(List<DateTime>).GetGenericArguments()
返回: new Type[]{ typeof(DateTime) }
此时:
typeof(DateTime).IsGenericParameter == False
typeof(DateTime).GenericParameterPosition : throw exception

最新文章

  1. 工作中那些提高你效率的神器(第一篇)_Everything
  2. yii + elasticsearch 手册
  3. IOS第16天(4,Quartz2D柱状图)
  4. Window 常用文件
  5. poj3692 最大点权独立集/最大独立集
  6. shell基础(一)
  7. Firefox常用插件
  8. Android Studio下载安装使用教程
  9. 参数TFilterPredicate 类型说明
  10. SDUT 2351 In Danger
  11. ctr预估模型
  12. C#使用DirectoryEntry操作IIS创建网站和虚拟路径
  13. 【转】CodeGear RAD 2007 SP4
  14. 实参时丢弃了类型 discards qualifiers discards qualifiers问题
  15. js 设计模式之观察者模式
  16. Oracle EBS OM 取消订单行
  17. PHP代码审计笔记--命令执行漏洞
  18. HDU 6447 - YJJ&#39;s Salesman - [树状数组优化DP][2018CCPC网络选拔赛第10题]
  19. 下载YouTube视频的方法
  20. Python学习-29.Python中列表的一些操作

热门文章

  1. 【windows phone】CollectionViewSource的妙用
  2. 九度OJ 1090:路径打印 (树、DFS)
  3. Building REST services with Spring
  4. 在react里面使用jquery插件
  5. P1604&amp;P1601
  6. mac配置apache
  7. struts2 session登录
  8. ssh整合 小例子
  9. python 基础之第八天--字典相关
  10. some characters cannot be mapped using iso-8859-1 character encoding