Click here to Skip to main content
15,891,473 members
Articles / Programming Languages / XML

Yet Another XML Serialization Library for the .NET Framework

Rate me:
Please Sign up or sign in to vote.
4.92/5 (91 votes)
2 Oct 2012MIT24 min read 515.6K   207  
A flexible XML serialization library that lets developers design the XML file structure, and select the exception handling policy. YAXLib supports polymorphic serialization and serializing generic and non-generic collection classes and arrays.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YAXLib;

namespace DemoApplication.SampleClasses
{
    [YAXComment(@"This example demonstrates usage of recursive collection serialization
                and deserialization. In this case a Dictionary whose Key, or Value is 
                another dictionary or collection has been used.")]
    public class NestedDicSample
    {
        public Dictionary<Dictionary<double, Dictionary<int, int>>, Dictionary<Dictionary<string, string>, List<double>>> SomeDic { get; set; }

        public override string ToString()
        {
            return GeneralToStringProvider.GeneralToString(this);
        }

        public static NestedDicSample GetSampleInstance()
        {
            var dicKV1 = new Dictionary<int, int>();
            dicKV1.Add(1, 1);
            dicKV1.Add(2, 2);
            dicKV1.Add(3, 3);
            dicKV1.Add(4, 4);

            var dicKV2 = new Dictionary<int, int>();
            dicKV2.Add(9, 1);
            dicKV2.Add(8, 2);

            var dicVK1 = new Dictionary<string, string>();
            dicVK1.Add("Test", "123");
            dicVK1.Add("Test2", "456");

            var dicVK2 = new Dictionary<string, string>();
            dicVK2.Add("Num1", "123");
            dicVK2.Add("Num2", "456");

            var dicK = new Dictionary<double, Dictionary<int, int>>();
            dicK.Add(0.99999, dicKV1);
            dicK.Add(3.14, dicKV2);

            var dicV = new Dictionary<Dictionary<string, string>, List<double>>();
            dicV.Add(dicVK1, new double[] { 0.98767, 232, 13.124}.ToList());
            dicV.Add(dicVK2, new double[] { 9.8767, 23.2, 1.34 }.ToList());

            var mainDic = new Dictionary<Dictionary<double, Dictionary<int, int>>, Dictionary<Dictionary<string, string>, List<double>>>();
            mainDic.Add(dicK, dicV);

            return new NestedDicSample()
            {
                SomeDic = mainDic
            };
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Software Developer
Australia Australia
A software designer and developer

Comments and Discussions