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



猜你喜欢

转载自www.cnblogs.com/sntetwt/p/11847761.html
今日推荐