码迷,mamicode.com
首页 > Windows程序 > 详细

C# 取得对象属性类型

时间:2019-11-13 12:59:10      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:pretty   ret   obj   bsp   name   对象   foreach   unset   属性   

1、对象 Object obj;

2、对象属性

Type postType = obj.GetType();

PropertyInfo[] postTypeInfos = postType.GetProperties();

3、对象属性类型

foreach (PropertyInfo p in postTypeInfos)       
{
  if (p.PropertyType.FullName == typeof(DateTime).FullName)
  {
    Object pValue = p.GetValue(obj, null);
  }
   else if (p.PropertyType.FullName == typeof(Int32).FullName)
  {
    Object pValue = p.GetValue(obj, null);
  }
  else if (p.PropertyType.FullName == typeof(Boolean).FullName)
  {
    Object pValue = p.GetValue(obj, null);
  }
  else if (p.PropertyType.FullName == typeof(String).FullName)
  {
    Object pValue = p.GetValue(obj, null);
  }
   else if (p.PropertyType.FullName == typeof(List<Address>).FullName)
  {
    List<Address> list = (List<Address>)p.GetValue(obj, null);
  }
}



C# 取得对象属性类型

标签:pretty   ret   obj   bsp   name   对象   foreach   unset   属性   

原文地址:https://www.cnblogs.com/sntetwt/p/11847761.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!