Esempio n. 1
0
        //TODO: One day I'd like to support multi-inheritance
        //[Test]
        public static void Test_Can_Manually_Deserialize_HandCrafted_Bytes()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            Assert.DoesNotThrow(() => serializer.RegisterType <SecondLevelClass>());
            serializer.Compile();

            //act
            byte[]      bytes = new byte[] { /*type*/ 55, 0, 0, 0, /*i val*/ 99, 0, 0, 0, /*b val*/ 69, 0, 0, 0, /*c val*/ 255, 255, 255, 255 };
            ChildClass1 child = serializer.Deserialize <TestBaseClass>(bytes) as ChildClass1;

            //assert
            Assert.NotNull(child);

            Assert.AreEqual(int.MaxValue, child.c);
            Assert.AreEqual(69, child.b);
            Assert.AreEqual(99, child.i);
        }
Esempio n. 2
0
        public static void Test_Can_Serialize_Then_Deserialize_With_Correct_Values()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            Assert.DoesNotThrow(() => serializer.RegisterType <SecondLevelClass>());
            serializer.Link <SecondLevelClass, ChildClass1>();
            serializer.Link <ChildClass1, TestBaseClass>();
            serializer.Compile();

            //act
            byte[] bytes = serializer.Serialize(new ChildClass1()
            {
                i = 1, b = 2, c = 3
            });
            ChildClass1 child = serializer.Deserialize <TestBaseClass>(bytes) as ChildClass1;

            //assert
            Assert.NotNull(child);

            Assert.AreEqual(3, child.c);
            Assert.AreEqual(2, child.b);
            Assert.AreEqual(1, child.i);
        }
Esempio n. 3
0
        public void TransformClass()
        {
            try
            {
                BaseClass bc = new BaseClass();
                ChildClass1 cc = new ChildClass1();
                bc = cc;//只有子类转化的基类才能重新强制转化为子类,直接转化无法进行
                ChildClass1 cc1 = (ChildClass1)bc;
            }
            catch(Exception ex)
            {

            }
        }
Esempio n. 4
0
        public void ShowNewOrVitual()
        {
            BaseClass a = new BaseClass();
            BaseClass b = new ChildClass1();
            BaseClass c = new ChildClass2();
            ChildClass1 d = new ChildClass1();
            ChildClass1 e = new ChildClass2();
            ChildClass2 f = new ChildClass2();

            string all = string.Format("{0}\n{1}\n{2}\n{3}\n{4}\n{5}\n", a.Show(), b.Show(), c.Show(), d.Show(), e.Show(), f.Show());
        }