public void Start() { var concreteClass = new ConcreteClass { FirstProp = 111, SecondProp = "Text", AnotherClass = new AnotherClass(222) }; DisplayObject(nameof(concreteClass), concreteClass); ConcreteClass shallowCopy = concreteClass.ShallowCopy(); DisplayObject(nameof(shallowCopy), shallowCopy); concreteClass.SecondProp = "AnotherText"; concreteClass.AnotherClass.SomeField = 333; DisplayObject(nameof(shallowCopy), shallowCopy); ConcreteClass deepCopy = concreteClass.DeepCopy(); concreteClass.AnotherClass.SomeField = 444; DisplayObject(nameof(deepCopy), deepCopy); DisplayObject(nameof(concreteClass), concreteClass); }
private void DisplayObject(string name, ConcreteClass obj) { Console.WriteLine($"{name}: {obj.FirstProp} {obj.SecondProp} {obj.AnotherClass.SomeField}"); Console.WriteLine("---------------------"); }