判断属性的值是否为空

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 == '')
{
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;
}

原文地址:https://www.cnblogs.com/liushangxin/p/3604532.html