Click here to Skip to main content
15,886,199 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 510.5K   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 System.Collections;
using YAXLib;

namespace DemoApplication.SampleClasses
{
    [YAXComment("This sample demonstrates serialization of non-generic collection classes")]
    public class NonGenericCollectionsSample
    {
        public List<object> ObjList { get; set; }

        public ArrayList TheArrayList { get; set; }

        public Hashtable TheHashtable { get; set; }

        public Queue TheQueue { get; set; }

        public Stack TheStack { get; set; }

        public SortedList TheSortedList { get; set; }

        public BitArray TheBitArray { get; set; }

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

        public static NonGenericCollectionsSample GetSampleInstance()
        {
            List<object> lst = new List<object>();
            lst.Add(1);
            lst.Add(3.0);
            lst.Add("Hello");
            lst.Add(new DateTime(2010, 3, 4));
            lst.Add(new Author() { Name = "Charles", Age = 50 });

            ArrayList arLst = new ArrayList();
            arLst.Add(2);
            arLst.Add(8.5);
            arLst.Add("Hi");
            arLst.Add(new Author() { Name = "Steve", Age = 30 });

            Hashtable table = new Hashtable();
            table.Add(1.0, "Tim");
            table.Add("Tom", "Sam");
            table.Add(new DateTime(2009, 2, 1), 7);

            BitArray bitArray = new BitArray(10);
            bitArray[1] = true;
            bitArray[6] = true;

            Queue queue = new Queue();
            queue.Enqueue(10);
            queue.Enqueue(20);
            queue.Enqueue(30);

            Stack stack = new Stack();
            stack.Push(100);
            stack.Push(200);
            stack.Push(300);


            SortedList sortedList = new SortedList();
            sortedList.Add(1, 2);
            sortedList.Add(5, 7);
            sortedList.Add(8, 2);

            return new NonGenericCollectionsSample()
            {
                ObjList = lst,
                TheArrayList = arLst,
                TheHashtable = table,
                TheBitArray = bitArray,
                TheQueue = queue,
                TheStack = stack,
                TheSortedList = sortedList
            };
        }

    }
}

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