Esempio n. 1
0
            public bool Serialize(object _object, Type _useType, XmlElement _parentNode, CSerializer _serializer)
            {
                var f = (CFriend)_object;

                _serializer.IgnoreField("FriendPerson");
                var idx = Array.IndexOf(CBigPerson.People, f.FriendPerson);

                XmlExtensions.AddElement(_parentNode, "FriendPerson", idx);
                return(false);
            }
Esempio n. 2
0
        public void AddElementTest()
        {
            var doc     = new XmlDocument();
            var simpson = XmlExtensions.AddElement(doc, "Simpson");

            XmlExtensions.AddElement(simpson, "Homer", "Father");
            XmlExtensions.AddElement(simpson, "Marge", "Mother");

            Assert.AreEqual <string>("Simpson", doc.DocumentElement.Name, "DocElement name is wrong");
            Assert.AreEqual <int>(2, doc.DocumentElement.ChildNodes.Count, "Number of child nodes is wrong.");
            Assert.AreEqual <string>("Homer", doc.DocumentElement.ChildNodes[0].Name, "Name of 1st node is wrong");
            Assert.AreEqual <string>("Father", doc.DocumentElement.ChildNodes[0].InnerText, "Contents of 1st node is wrong");
            Assert.AreEqual <string>("Marge", doc.DocumentElement.ChildNodes[1].Name, "Name of 2nd node is wrong");
            Assert.AreEqual <string>("Mother", doc.DocumentElement.ChildNodes[1].InnerText, "Contents of 2nd node is wrong");

            XmlExtensions.AddElementWithAttribute(simpson, "Bart", "Child", 1);
            Assert.AreEqual <string>("Bart", doc.DocumentElement.ChildNodes[2].Name, "Bart is wrong");
            Assert.AreEqual <string>("Child", doc.DocumentElement.ChildNodes[2].Attributes[0].Name, "Name of Bart's attribute is wrong.");
            Assert.AreEqual <string>("1", doc.DocumentElement.ChildNodes[2].Attributes[0].Value, "Value of Bart's attribute is wrong.");
        }