I have problem in comparing two objects. I am struggling to find the difference between two objects. It gives me always same result.
Here is my object:
ClassA
{
int slNo;
string location;
Dictionary dic = new Dictionary<string,Object>();
ClassB classb = new ClassB();
}
ClassB
{
int id;
string name;
}
I have created an instance for classA and assigned some values.
ClassA obj = new ClassA{ dic = new Dictionary<string, object>, classb = new ClassB()};
and populated the obj with some values.
Copied the values to new object
var objNewA = obj;
and changed the classA like below.changed the value of obj.slNo = 100 and also changing some dic values collection. I can able to find the difference of slno using below method
public static bool FindDifference(ClassA originalObject, ClassA changedObject)
{
foreach (PropertyInfo property in originalObject.GetType().GetProperties())
{
object originalValue = property.GetValue(originalObject, null);
object newValue = property.GetValue(changedObject, null);
if (!Equals(originalValue, newValue))
{
return true;
}
}
return false;
}
but the dictionary value change i cant able to figure it out. Its giving me the modified value in both source and destination objects any help please?