I have two objects with these definitions:
public static Dictionary<string, Container> cont1 = new Dictionary<string, Container>();
public static Dictionary<string, Container> cont2 = new Dictionary<string, Container>();
The schema of Container class is as following:
public class Container
{
public string IDx { get; set; }
public string IDy { get; set; }
public string Name { get; set; }
public Dictionary<string, Sub> Subs = new Dictionary<string, Sub>();
}
public class Sub
{
public string Namex { get; set; }
public string Namey { get; set; }
public string Value { get; set; }
public Dictionary<string, string> Paths { get; set; }
}
My question is: How can I deep check the equity of cont1 and cont2? I mean the equality of every member and value even deep down within Subs objects;
Is there any functionality in c# for such situations or I have to write a custom method for checking equality based on the structure of the objects myself;
Second Question: I can obviate the equality problem if I can create two different copies of Products; I mean say we have a base Container object with all the members and values and then create two separate copies of Container, namely cont1 and cont2 which changing a value in cont1 wont change the same value in cont2.
Note1: this method for cloning is not working:
cont2 = new Dictionary<string, Container>(cont1);
Note2: most of the proposed methods in other answers are based on a one level dictionary (using loops or LINQ for checking) and not such a case when we have properties and dictionary objects (which having their own properties) within the object.