コード例 #1
0
        public void TestExternalSurrogate()
        {
            CBigPerson.GenerateData(100);
            var c = new CSerializationContext();

            c.SetConcise();
            var helper = new CFriendSerializer();

            c.RegisterExternalSurrogate(typeof(CFriend), helper);

            var s   = new CSerializer(c);
            var doc = s.Serialize(CBigPerson.People);

            Console.WriteLine("Depth of resulting XML: " + XmlExtensions.Depth(doc));
            Console.WriteLine("Length of resulting XML String: " + doc.OuterXml.Length);
            Console.WriteLine("Number of resulting XmlElements: " + XmlExtensions.ElementCount(doc));
            Print(doc);

            var d  = new CDeserializer(c);
            var x2 = d.Deserialize <CBigPerson[]>(doc);

            helper.FinishDeserializing(x2);

            CDeserializeTest.AssertEqualBigPeopleArray(CBigPerson.People, x2);
        }
コード例 #2
0
        public void TestPeople()
        {
            CBigPerson.GenerateData(100);
            var c = new CSerializationContext();

            c.SetConcise();
            var s   = new CSerializer(c);
            var doc = s.Serialize(CBigPerson.People);

            Console.WriteLine("Depth of resulting XML: " + XmlExtensions.Depth(doc));
            Console.WriteLine("Length of resulting XML String: " + doc.OuterXml.Length);
            Console.WriteLine("Number of resulting XmlElements: " + XmlExtensions.ElementCount(doc));

            var d = new CDeserializer(c);

            var x2 = d.Deserialize <CBigPerson[]>(doc);
            var x1 = CBigPerson.People;

            AssertEqualBigPeopleArray(x1, x2);
        }