static ExampleOuter CreateExample()
        {
            var res = new ExampleOuter()
            {
                ValueString      = "Test",
                ValueStringArray = new string[] { "A", "B,", "C" },
                ValueDoubleArray = new double[] { 2, 3.14, 10000 },
                PropertyInteger  = 27,
                PropertyDateTime = new DateTime(2017, 12, 27, 14, 30, 0),
            };

            res.ValueObject      = new ExampleInner(2);
            res.ValueObjectArray = new ExampleInner[] { new ExampleInner(4), new ExampleInner(6) };
            res.ChangePrivateValue(2.345f);
            return(res);
        }
Пример #2
0
        public void Run()
        {
            Test = new UnitTestHelper();
            Test.PrintHeadline("UnitTest3 - Reflection-based Serialization");

            var o1 = new ExampleOuter()
            {
                ValueString      = "Test",
                ValueStringArray = new string[] { "A", "B,", "C" },
                ValueDoubleArray = new double[] { 2, 3.14, 10000 },
                PropertyInteger  = 27,
                PropertyDateTime = new DateTime(2017, 12, 27, 14, 30, 0),
            };

            o1.ValueObject      = new ExampleInner(2);
            o1.ValueObjectArray = new ExampleInner[] { new ExampleInner(4), new ExampleInner(6) };
            o1.ChangePrivateValue(2.345f);

            string s1 = Serialize(o1);
            //Console.WriteLine(s1);

            var          d  = new SLJsonDeserializer();
            ExampleOuter o2 = d.Deserialize <ExampleOuter>(s1);

            string s2 = Serialize(o1);

            Test.Assert(() => s1 == s2);

            SLJsonNode n1 = SLJsonParser.Parse(s1);
            SLJsonNode n2 = n1.Clone();
            SLJsonNode n3 = SLJsonParser.Parse(n2.AsJson);
            SLJsonNode n4 = SLJsonParser.Parse(n3.AsJsonCompact);

            Test.Assert(() => n1 != n2);
            CompareNodes(n1, n1);
            CompareNodes(n1, n2);
            CompareNodes(n1, n3);
            CompareNodes(n1, n4);

            //Console.WriteLine();
            Test.PrintSummary();
            Test = null;
        }