C# 取得对象属性类型

2019/11/13 11:38
阅读数 45

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



展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部