首页 > 其他 > 详细

判断属性的值是否为空

时间:2014-03-18 12:27:20      阅读:530      评论:0      收藏:0      [点我收藏+]

private bool CheckCompanyDetail()
{
CompanyDetail companyDetail = CompanyDetailAdapter.Instance.LoadByCompanyArticleId(CurrentArticleId);
Type type= companyDetail.GetType();
PropertyInfo[] proes= type.GetProperties();
foreach (var item in proes)
{
if (item.PropertyType.Name == "String")
{
object obj= item.GetValue(companyDetail,null);
if (obj == null)
{
return false;
}
}
if (item.PropertyType.Name == "Int32")
{
object obj = item.GetValue(companyDetail, null);
if ((int)obj ==0 )
{
return false;
}
}
if (item.PropertyType.Name == "Guid")
{
object obj = item.GetValue(companyDetail, null);
if ((Guid)obj == Guid.Empty)
{
return false;
}
}
if (item.PropertyType.Name == "Char")
{
object obj = item.GetValue(companyDetail, null);
if ((char)obj == ‘\0‘)
{
return false;
}
}
if (item.PropertyType.Name == "Decimal")
{
object obj = item.GetValue(companyDetail, null);
if ((Decimal)obj == 0.00m)
{
return false;
}
}
if (item.PropertyType.Name == "DateTime")
{
object obj = item.GetValue(companyDetail, null);
if ((DateTime)obj == null)
{
return false;
}
}
}
return true;
}

判断属性的值是否为空,布布扣,bubuko.com

判断属性的值是否为空

原文:http://www.cnblogs.com/liushangxin/p/3604532.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!