如何对比实体类每个属性的前后变化差异?
Apple app1 = new Apple();
app1.name = "liu";
app1.pice = "33";
Apple app2 = new Apple();
app2.name = "liu";
app2.pice = "333";
System.Reflection.PropertyInfo[] mPi = typeof(Apple).GetProperties();
for (int i = 0; i < mPi.Length; i++)
{
System.Reflection.PropertyInfo pi = mPi[i];
string oldValue = pi.GetValue(app1, null).ToString();
string newValue = pi.GetValue(app2, null).ToString();
if (oldValue !=newValue )
{
// 有差别的列出来
}
}
public class Apple
{
public string name{get;set;}
public string pice { get; set; }
}