判断属性的值是否为空

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

posted @ 2014-03-17 10:11  小猫给大家拜年  阅读(435)  评论(0编辑  收藏  举报