// Return a copy of the current object
        public object Clone()
        {
            // First get a shallow copy
            DeepCloneablePoint newPoint = (DeepCloneablePoint)this.MemberwiseClone();

            // Fill in the gaps
            PointDescription currentDesc = new PointDescription();

            currentDesc.PetName = this.desc.PetName;

            newPoint.desc = currentDesc;
            return(newPoint);
        }
Exemple #2
0
        /// <summary>
        /// Deep Object Copy
        /// </summary>
        private void DeepObjectCopy()
        {
            Console.WriteLine("=> Deep Object Copy: ");

            DeepCloneablePoint p3 = new DeepCloneablePoint(100, 100, "Jane");
            DeepCloneablePoint p4 = (DeepCloneablePoint)p3.Clone();

            Console.WriteLine("Before modification:");
            Console.WriteLine("p3: {0}", p3);
            Console.WriteLine("p4: {0}", p4);

            p4.desc.PetName = "My new Point";
            p4.X            = 9;

            Console.WriteLine("\nChanged p4.desc.petName and p4.X");
            Console.WriteLine("After modification:");
            Console.WriteLine("p3: {0}", p3);
            Console.WriteLine("p4: {0}", p4);

            Console.WriteLine();
        }