示例#1
0
        public static void CallDeepCopy()
        {
            Console.WriteLine("Deep Copy Example");

            var author = new AuthorDeepCopy()
            {
                Name           = "Stephan Walther",
                TwitterAccount = "http://www.twitter.com/swalther",
                Website        = "http://www.superexpert.com",
                HomeAddress    = new Deep.Address
                {
                    City  = "New York",
                    State = "Nevada"
                }
            };

            Console.WriteLine("\n Originial Copy");
            PrintDeepDetails(author);

            var clonedObject = (AuthorDeepCopy)author.Clone();

            Console.WriteLine("\n Cloned Copy");
            PrintDeepDetails(clonedObject);

            Console.WriteLine("\n Make Changes to clone copy address");

            clonedObject.Name              = "Changed Name";
            clonedObject.TwitterAccount    = "http://www.twitter.com/changedaccount";
            clonedObject.Website           = "http://www.microsoft.com";
            clonedObject.HomeAddress.City  = "Los Angles";
            clonedObject.HomeAddress.State = "North Carolina";

            Console.WriteLine("\n Cloned object After Update");
            PrintDeepDetails(clonedObject);

            Console.WriteLine("\n Original Copy");
            PrintDeepDetails(author);
        }