示例#1
0
    // Use this for initialization
    void Start()
    {
        XmlDocument xDoc = new XmlDocument();
        var         Root = xDoc.CreateElement("Root");

        xDoc.AppendChild(Root);

        var testClass = new TestClass();

        testClass.testString = "asdasdas";
        testClass.testList   = new List <int>()
        {
            1, 2, 3
        };
        testClass.testDict = new Dictionary <int, string>()
        {
            { 1, "asdasd" },
            { 2, "asdcqwe" },
        };

        testClass.TestChildren = new List <TestChild>()
        {
            new TestChild()
            {
                testString = "asdasd", testList = new List <int>()
                {
                    5, 3, 123
                }
            },
            new TestChild()
            {
                testString = "asdasd", testList = new List <int>()
                {
                    5, 3, 123
                }
            },
            new TestChild()
            {
                testString = "asdasd", testList = new List <int>()
                {
                    5, 3, 123
                }
            },
            new TestChild()
            {
                testString = "asdasd", testList = new List <int>()
                {
                    5, 3, 123
                }
            }
        };

        ReXmlSerializer.WriteAny(Root, "TestClass", testClass);
        Debug.Log(xDoc.InnerXml);

        var res = ReXmlSerializer.ReadAny(Root, "TestClass", typeof(TestClass), null);

        Debug.Log(res);
    }
        public virtual void Write(System.Xml.XmlElement xElement, string name, TestSerializeData obj)
        {
            var node = xElement.OwnerDocument.CreateElement(name);

            xElement.AppendChild(node);
            ReXmlSerializer.Write(xElement, "helloInt", obj.helloInt);
            CustomSerializer.GetSerializer <TestSerializeData>().Write(xElement, "testData", obj.testData);
        }