示例#1
0
        public TestCopyClass(TestCopyClass other)
        {
            TestCopyClass copy = DeepCopy.Copy <TestCopyClass>(other);

            Num    = copy.Num;
            Name   = copy.Name;
            Helper = copy.Helper;
        }
示例#2
0
        public void DeepCopyTest()
        {
            TestCopyClass c1 = new TestCopyClass
            {
                Num    = 1,
                Name   = "Morgan",
                Helper = new TestCopyHelperClass
                {
                    helperString = "Help",
                    helperInt    = 2
                }
            };
            //Test copy
            TestCopyClass c2 = DeepCopy.Copy <TestCopyClass>(c1);

            Assert.AreEqual(c1.Helper.helperInt, c2.Helper.helperInt);
            Assert.AreEqual(c1.Num, c2.Num);
            //Test Modify to property
            c2.Num = 5;
            Assert.AreNotEqual(c1.Num, c2.Num);
            Assert.AreEqual(5, c2.Num);
            Assert.AreEqual(1, c1.Num);
            //Test Modification to Helper class
            c2.Helper.helperInt = 12;
            Assert.AreNotEqual(c1.Helper.helperInt, c2.Helper.helperInt);
            Assert.AreEqual(12, c2.Helper.helperInt);
            c2.Helper.helperString = "poop";
            Assert.AreNotEqual(c1.Helper.helperString, c2.Helper.helperString);
            Assert.AreEqual("poop", c2.Helper.helperString);
            //Test clone constructor
            TestCopyClass c3 = new TestCopyClass(c1);

            Assert.AreEqual(c1.Num, c3.Num);
            Assert.AreEqual(c1.Helper.helperString, c3.Helper.helperString);
            c3.Num = 7;
            c3.Helper.helperInt = 7;
            Assert.AreNotEqual(c1.Helper.helperInt, c3.Helper.helperInt);
            Assert.AreEqual(7, c3.Helper.helperInt);
            Assert.AreNotEqual(c1.Num, c3.Num);
        }
示例#3
0
 public void DeepCopyTest()
 {
     TestCopyClass c1 = new TestCopyClass
     {
         Num = 1,
         Name = "Morgan",
         Helper = new TestCopyHelperClass
         {
             helperString = "Help",
             helperInt = 2
         }
     };
     //Test copy
     TestCopyClass c2 = DeepCopy.Copy<TestCopyClass>(c1);
     Assert.AreEqual(c1.Helper.helperInt, c2.Helper.helperInt);
     Assert.AreEqual(c1.Num, c2.Num);
     //Test Modify to property
     c2.Num = 5;
     Assert.AreNotEqual(c1.Num, c2.Num);
     Assert.AreEqual(5, c2.Num);
     Assert.AreEqual(1, c1.Num);
     //Test Modification to Helper class
     c2.Helper.helperInt = 12;
     Assert.AreNotEqual(c1.Helper.helperInt, c2.Helper.helperInt);
     Assert.AreEqual(12, c2.Helper.helperInt);
     c2.Helper.helperString = "poop";
     Assert.AreNotEqual(c1.Helper.helperString, c2.Helper.helperString);
     Assert.AreEqual("poop", c2.Helper.helperString);
     //Test clone constructor
     TestCopyClass c3 = new TestCopyClass(c1);
     Assert.AreEqual(c1.Num, c3.Num);
     Assert.AreEqual(c1.Helper.helperString, c3.Helper.helperString);
     c3.Num = 7;
     c3.Helper.helperInt = 7;
     Assert.AreNotEqual(c1.Helper.helperInt, c3.Helper.helperInt);
     Assert.AreEqual(7, c3.Helper.helperInt);
     Assert.AreNotEqual(c1.Num, c3.Num);
 }
示例#4
0
 public TestCopyClass(TestCopyClass other)
 {
     TestCopyClass copy = DeepCopy.Copy<TestCopyClass>(other);
     Num = copy.Num;
     Name = copy.Name;
     Helper = copy.Helper;
 }