コード例 #1
0
        public void ThreeAttrsPrivate()
        {
            ThreeAttrsTestClass a = new ThreeAttrsTestClass
            {
                A = 123,
                B = "testString",
                C = NanoState.Ignore
            };

            a.SetPrivate("private");

            XmlDocument           target   = new XmlDocument();
            SerializationSettings settings = new SerializationSettings();

            settings.SerializePrivateProperties = true;
            Serializer serializer = new Serializer(settings);

            serializer.SerializeObject((SystemXmlAdapter)target, a);

            Assert.AreEqual(0, target.DocumentElement.ChildNodes.Count);
            Assert.AreEqual(5, target.DocumentElement.Attributes.Count);
            Assert.AreEqual("123", target.DocumentElement.GetAttribute("A_"));
            Assert.AreEqual("testString", target.DocumentElement.GetAttribute("B"));
            Assert.AreEqual("Ignore", target.DocumentElement.GetAttribute("C"));
            Assert.AreEqual("private", target.DocumentElement.GetAttribute("F"));

            ThreeAttrsTestClass b = Deserializer.Deserialize <ThreeAttrsTestClass>((SystemXmlAdapter)target);

            Assert.AreEqual(a.A, b.A);
            Assert.AreEqual(a.B, b.B);
            Assert.AreEqual(a.C, b.C);
            Assert.AreEqual(a.GetPrivate(), b.GetPrivate());

            ThreeAttrsTestClass c = new ThreeAttrsTestClass();

            new Deserializer().FillObject(c, (SystemXmlAdapter)target);

            Assert.AreEqual(a.A, c.A);
            Assert.AreEqual(a.B, c.B);
            Assert.AreEqual(a.C, c.C);
            Assert.AreEqual(a.GetPrivate(), c.GetPrivate());
        }
コード例 #2
0
        public void ThreeAttrs()
        {
            ThreeAttrsTestClass a = new ThreeAttrsTestClass
            {
                A = 123,
                B = "testString",
                C = NanoState.Ignore
            };

            a.SetPrivate("private");

            XmlDocument target = new XmlDocument();

            Serializer.Serialize((SystemXmlAdapter)target, a);

            Assert.AreEqual(0, target.DocumentElement.ChildNodes.Count);
            Assert.AreEqual(4, target.DocumentElement.Attributes.Count);
            Assert.AreEqual("123", target.DocumentElement.GetAttribute("A_"));
            Assert.AreEqual("testString", target.DocumentElement.GetAttribute("B"));
            Assert.AreEqual("Ignore", target.DocumentElement.GetAttribute("C"));

            ThreeAttrsTestClass b = Deserializer.Deserialize <ThreeAttrsTestClass>((SystemXmlAdapter)target);

            Assert.AreEqual(a.A, b.A);
            Assert.AreEqual(a.B, b.B);
            Assert.AreEqual(a.C, b.C);
            Assert.IsNull(b.GetPrivate());

            ThreeAttrsTestClass c = new ThreeAttrsTestClass();

            new Deserializer().FillObject(c, (SystemXmlAdapter)target);

            Assert.AreEqual(a.A, c.A);
            Assert.AreEqual(a.B, c.B);
            Assert.AreEqual(a.C, c.C);
            Assert.IsNull(c.GetPrivate());
        }
コード例 #3
0
        public void ThreeAttrs()
        {
            ThreeAttrsTestClass a = new ThreeAttrsTestClass
            {
                A = 123,
                B = "testString",
                C = NanoState.Ignore
            };

            a.SetPrivate("private");

            JObject target = new JObject();

            Serializer.Serialize(new NewtonsoftJsonAdapter(target), a);

            AssertChildren(4, target);
            AssertAttribute("123", "A_", target);
            AssertAttribute("testString", "B", target);
            AssertAttribute("Ignore", "C", target);

            ThreeAttrsTestClass b = Deserializer.Deserialize <ThreeAttrsTestClass>((NewtonsoftJsonAdapter)target);

            Assert.AreEqual(a.A, b.A);
            Assert.AreEqual(a.B, b.B);
            Assert.AreEqual(a.C, b.C);
            Assert.IsNull(b.GetPrivate());

            ThreeAttrsTestClass c = new ThreeAttrsTestClass();

            new Deserializer().FillObject(c, (NewtonsoftJsonAdapter)target);

            Assert.AreEqual(a.A, c.A);
            Assert.AreEqual(a.B, c.B);
            Assert.AreEqual(a.C, c.C);
            Assert.IsNull(c.GetPrivate());
        }