C# 取得对象属性类型

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);
  }
}



posted @ 2019-11-13 11:38  microsoftzhcn  阅读(4576)  评论(0编辑  收藏  举报