示例#1
0
        public void TestInherit()
        {
            var ser = new Regulus.Serialization.Dynamic.Serializer();


            var test = new TestGrandson();

            test.Data = 100;
            var testChild = test as TestChild;

            testChild.Data = 1;
            var testParent = test as TestParent;

            testParent.Data = 33;

            var buf       = ser.ObjectToBuffer(test);
            var val       = (TestGrandson)ser.BufferToObject(buf);
            var valParent = val as TestParent;
            var child     = val as TestChild;


            Assert.AreEqual(100, val.Data);
            Assert.AreEqual(1, child.Data);
            Assert.AreEqual(33, valParent.Data);
        }
示例#2
0
        public void TestInherit()
        {
            Serializer ser = new Regulus.Serialization.Dynamic.Serializer();


            TestGrandson test = new TestGrandson();

            test.Data = 100;
            TestChild testChild = test as TestChild;

            testChild.Data = 1;
            TestParent testParent = test as TestParent;

            testParent.Data = 33;

            byte[]       buf       = ser.ObjectToBuffer(test);
            TestGrandson val       = (TestGrandson)ser.BufferToObject(buf);
            TestParent   valParent = val as TestParent;
            TestChild    child     = val as TestChild;


            Assert.Equal(100, val.Data);
            Assert.Equal(1, child.Data);
            Assert.Equal(33, valParent.Data);
        }
示例#3
0
        public void TestClassPolytype1()
        {
            var g = new TestGrandson();

            g.Data = 100;
            var test = new TestPoly();

            test.Parent = g;



            var serializer =
                new Regulus.Serialization.Dynamic.Serializer(new CustomFinder((name) => Type.GetType(name)));
            var buf      = serializer.ObjectToBuffer(test);
            var val      = (TestPoly)serializer.BufferToObject(buf);
            var valChild = val.Parent as TestGrandson;

            Assert.AreEqual(100, valChild.Data);
        }
示例#4
0
        public void TestArray1()
        {
            var test = new TestGrandson();

            test.Data = 100;
            var testChild = test as TestChild;

            testChild.Data = 1;
            var testParent = test as TestParent;

            testParent.Data = 33;

            var serializer =
                new Regulus.Serialization.Dynamic.Serializer(new CustomFinder((name) => Type.GetType(name)));
            var buf = serializer.ObjectToBuffer(new TestParent[] { test, testChild, testParent });
            var val = (TestParent[])serializer.BufferToObject(buf);

            Assert.AreEqual(100, (val[0] as TestGrandson).Data);
            Assert.AreEqual(1, (val[1] as TestChild).Data);
            Assert.AreEqual(33, (val[2] as TestParent).Data);
        }