static void Main(string[] args) { System s1 = new ShallowClone(new TELO("A", 1)); System s2 = s1.Clone(); s1.telo.Lenght = 4; Console.WriteLine(s1.telo.Lenght + " " + s2.telo.Lenght); System s3 = new DeepClone(new TELO("B", 2)); System s4 = s3.Clone(); s3.telo.Lenght = 5; Console.WriteLine(s3.telo.Lenght + " " + s4.telo.Lenght); Console.Read(); }
/// <summary> /// Builds a document from the corresponding response xml node /// </summary> /// <param name="node">response xml node</param> /// <param name="fields">document fields</param> /// <returns>populated document(s)</returns> public IEnumerable <T> ParseDocument(XElement node) { IList <T> docs = new List <T>(); IList <XElement> children = new List <XElement>(); var doc = activator.Create(); foreach (var field in node.Elements()) { if (field.HasElements && string.Equals(field.Name.LocalName, "doc", System.StringComparison.OrdinalIgnoreCase)) { children.Add(field); } else { string fieldName = field.Attribute("name").Value; propVisitor.Visit(doc, fieldName, field); } } if (children.Count > 0) { foreach (var child in children) { var newDoc = ShallowClone.Clone(doc); foreach (var field in child.Elements()) { string fieldName = field.Attribute("name").Value; propVisitor.Visit(newDoc, fieldName, field); } docs.Add(newDoc); } } else { docs.Add(doc); } return(docs); }