Пример #1
0
        public static void Main(string[] args)
        {
            var lebevila = new Person(new[] { "Le", "Bevilaqua" }, new Address("Diana Street", 1001));

            var refag = lebevila.DeepCopyXml();

            refag.Names[0]            = "Re";
            refag.Address.HouseNumber = 200;

            WriteLine(lebevila);
            WriteLine(refag);

            var l = new Line
            {
                Start = new Point {
                    X = 1, Y = 2
                },
                End = new Point {
                    X = 2, Y = 3
                }
            };

            WriteLine(l);

            var lcopy = l.DeepCopy();

            lcopy.Start = new Point {
                X = 55, Y = 11
            };
            WriteLine(lcopy);
        }
Пример #2
0
        static void Main(string[] args)
        {
            var john = new Person(new [] { "John", "Smith" }, new Address("London Road", 123));
            var jane = john.DeepCopyXml();

            jane.Names[0]            = "Jane";
            jane.Address.HouseNumber = 321;
            Console.WriteLine(john);
            Console.WriteLine(jane);
        }
Пример #3
0
        public static void CopyThroughXmlSerialization()
        {
            var john = new Person(new[] { "John", "Smith" }, new Address("London Rd", 123));
            var jane = john.DeepCopyXml();

            jane.Names[0]            = "Jane";
            jane.Address.HouseNumber = 456;

            Console.WriteLine(john);
            Console.WriteLine(jane);
        }
Пример #4
0
        static void Main(string[] args)
        {
            var john = new Person(new [] { "John", "Smith" }, new Address("Park Ave", 100));
            var jane = john.DeepCopyXml();

            jane.Names = new[] { "Jane", "Jackson" };
            jane.Address.HouseNumber = 221;
            Console.WriteLine(john);
            Console.WriteLine(jane);

            var jack = john;
        }
Пример #5
0
        static void Main(string[] args)
        {
            var john = new Person(new[] { "John", "Smith" },
                                  new Address("London Road", 123));

            var jane = john.DeepCopyXml();

            jane.Names[0]            = "Jane";
            jane.Address.HouseNumber = 321;

            WriteLine(john);
            WriteLine(jane);

            var john2 = john.DeepCopy();

            john2.Address = new Address("Birmingham Lane", 222);
            WriteLine(john2);
        }
        static void Main(string[] args)
        {
            var John = new Person(new[] { "John", "Smith" }, new Address("London Road", 123));

            Console.WriteLine(John);

            var Jane = new Person(John);

            Jane.Address.HouseNumber = 321;
            Console.WriteLine(Jane);

            /*var Jill = John.DeepCopy();*/
            var Jill = John.DeepCopyXml();

            Jill.Names[0] = "Jill";

            Console.WriteLine(Jill);
        }
Пример #7
0
        static void Main(string[] args)
        {
            var john = new Person(new [] { "John", "Smith" }, new Address("London Road", 123));

            // var jane = john; // wrong! we're copying a reference to john
            // jane.Names[0] = "Jane"; // this will modify the Name in both john and jane

            // var jane = (Person) john.Clone(); // This won't solve the problem since the implementation of clone does a shallow copy
            // jane.Address.HouseNumber = 321; // this will change the property in both objects

            // var jane = new Person(john);
            // jane.Address.HouseNumber = 321; // everything is working correctly

            // var jane = john.DeepCopy(); Uncomment the Serializable attribute
            var jane = john.DeepCopyXml();

            jane.Names[0]            = "Jane";
            jane.Address.HouseNumber = 321;

            Console.WriteLine(john);
            Console.WriteLine(jane);

            Console.ReadLine();
        }