/// <summary>
/// 判断两个实体类是否相等
/// </summary>
/// <param name="processObj">对象1</param>
/// <param name="processObj2">对象2</param>
public static bool ReflectField(object processObj, object processObj2)
{
Type t1 = processObj.GetType();
Type t2 = processObj2.GetType();
string str = "";
string str2 = "";
foreach (PropertyInfo item in t1.GetProperties())
{
if (item.Name != "CCBNumber" && item.Name != "CCBCreateDate" && item.Name != "CCBCreaterId" && item.Name != "StampTime" )
{
str += GetModelValue(item.Name, processObj);
Debug.Print(item.Name + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + GetModelValue(item.Name, processObj));
}
}
foreach (PropertyInfo item in t2.GetProperties())
{
if (item.Name != "CCBNumber" && item.Name != "CCBCreateDate" && item.Name != "CCBCreaterId" && item.Name != "StampTime")
{
str2 += GetModelValue(item.Name, processObj2);
Debug.Print(item.Name + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + GetModelValue(item.Name, processObj2));
}
}
if (str.Equals(str2))
{
return true;
}
//str = "";
//str2 = "";
Debug.Print(str + "--------------------------");
Debug.Print(str2 + "--------------------------");
return false;
}
/// <summary>
/// 获取属性值
/// </summary>
/// <param name="FieldName">属性</param>
/// <param name="obj">对象</param>
/// <returns></returns>
public static string GetModelValue(string FieldName, object obj)
{
try
{
Type Ts = obj.GetType();
object o = Ts.GetProperty(FieldName).GetValue(obj, null);
string Value = Convert.ToString(o);
if (string.IsNullOrEmpty(Value)) return null;
return Value;
}
catch
{
return null;
}
}
http://www.qbzao.com/