Пример #1
0
        public void NewTest()
        {
            const string str = "231231";
            TestClass    m   = (TestClass)Obj.New(typeof(TestClass));
            TestClass    c   = Obj.New <TestClass>();
            TestClass    k   = (TestClass)Obj.New(typeof(TestClass));
            TestClass    t   = Obj <TestClass> .New();

            st1 s = Obj <st1> .New();

            st1 s1 = (st1)Obj.New <st1>();
            st1 s2 = (st1)Obj.New(typeof(st1));

            Console.WriteLine(s2.s);
            s2.s = str;
            Console.WriteLine(s2.s);
            Assert.IsNotNull(m);
            Assert.IsNotNull(t);
            Assert.IsNotNull(c);
            Assert.IsInstanceOfType(m, typeof(TestClass));
            Assert.IsInstanceOfType(c, typeof(TestClass));
            Assert.IsInstanceOfType(t, typeof(TestClass));
            Assert.IsInstanceOfType(s, typeof(st1));
            Assert.IsInstanceOfType(s1, typeof(st1));
            Assert.IsInstanceOfType(s2, typeof(st1));
            Assert.AreEqual(s2.s, str);
        }
Пример #2
0
        public void ShallowCopyTest()
        {
            const string str = "231231";
            TestClass    t   = Obj <TestClass> .New();

            t.Str = str + str;
            st1 s = Obj <st1> .New();

            s.s = str;
            Console.WriteLine(t.Str);
            Console.WriteLine(s.s);
            K ss = Obj <K> .New();

            ss.Field = 1;
            ss.t     = t;
            var t1   = t.ShallowCopy();
            var five = (5).ShallowCopy();
            var s1   = Obj <st1> .ShallowCopy(s);

            var ss1 = Obj <K> .ShallowCopy(ss);

            var s2 = s1;

            Console.WriteLine(t1.Str);
            Console.WriteLine(s1.s);
            Console.WriteLine(s2.s);
            Assert.IsNotNull(t);
            Assert.IsNotNull(t1);
            Assert.IsInstanceOfType(t1, typeof(TestClass));
            Assert.IsInstanceOfType(s1, typeof(st1));
            Assert.IsInstanceOfType(ss1, typeof(K));
            Assert.AreEqual(t1.Str, t.Str);
            Assert.AreEqual(s1.s, s.s);
            Assert.IsFalse(Assert.ReferenceEquals(t, t1));
            Assert.IsTrue(Assert.ReferenceEquals(ss.t, ss1.t));
            Assert.AreEqual(five, 5);
        }