递归的对象属性值比较
//方法代码如下:
public static bool PropertyEquals(object o1, object o2)
{
PropertyInfo []pInfos1 = o1.GetType().GetProperties();
PropertyInfo[] pInfos2 = o2.GetType().GetProperties();
if(!pInfos1.Length.Equals(pInfos2.Length))
{
return false;
}
for(int i=0; i<pInfos2.Length;i++)
{
if (!PropertyEquals(pInfos2[i].GetValue(o2, null), pInfos1[i].GetValue(o1, null))) return false;
}
return true;
}
/*
问题是这样递归的比较在遇到值类型时是不需要的。如何判断值类型?
现在还会进入死循环,加什么样的出口条件?请高手帮忙解决或提示一下。
*/