Click here to Skip to main content
15,896,201 members
Articles / Programming Languages / C# 4.0

Mini XML serializer

Rate me:
Please Sign up or sign in to vote.
4.80/5 (5 votes)
6 Jul 2010CPOL2 min read 25.4K   209   10  
A small XML serializer for Silverlight projects.
using System;
using System.Collections.Generic;
using System.Text;

namespace MiniXMLSerializer.TestClasses
{
    class DataClass : IMiniSerializable
    {
        static int instId = 0;
        public string name = "";
        public double X = 0;
        static Random rnd = new Random();
        public DataList listPointer = null;

        public DataClass()
        {
            name = "inst " + (instId++);
            X = rnd.NextDouble() * 300;
        }

        public void OnSerialize(MiniSerializer serializer)
        {
            serializer.Serialize("name", this.name);
            serializer.Serialize("X", X);
            serializer.Serialize("listPointer", listPointer);
        }

        public void OnDeserialize(MiniSerializer serializer)
        {
            object obj = serializer.Deserialize("DoNotExists"); // 1st empty objects
            object obj2 = serializer.Deserialize("DoNotExists2"); // 2nd empty objects
            name = (string)serializer.Deserialize("name");
            X = (double)serializer.Deserialize("X");
            listPointer = (DataList)serializer.Deserialize("listPointer");
        }
    }
}

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 Code Project Open License (CPOL)


Written By
Software Developer (Senior) Paul Scherrer Institute
Switzerland Switzerland
Full time developer in a Gov. research institute, I invest also some time to develop games.

I currently own since 5 years a PHP / AJAX MMORPG:
http://www.nowhere-else.org

And developing a MMO space combat trader game in Silverlight:
http://www.nebularider.com

Comments and Discussions