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

AltSerializer - An Alternate Binary Serializer

Rate me:
Please Sign up or sign in to vote.
4.93/5 (27 votes)
19 Sep 20066 min read 142K   1.9K   69  
The AltSerializer is a replacement for the binary serializer built in to .NET.
using System;
using System.Collections.Generic;
using System.Text;

using AltSerialize;

namespace AltSerializeTest.TestObjects
{
    public class ClassIAltSerializable : IAltSerializable
    {
        #region Properties

        private string _message;
        public string Message
        {
            get { return _message; }
            set { _message = value; }
        }

        private int _value;
        public int Value
        {
            get { return _value; }
            set { _value = value; }
        }

        private bool _wasAltSerialized;
        public bool WasSerialized
        {
            get { return _wasAltSerialized; }
            set { _wasAltSerialized = value; }
        }

        private bool _wasDeserialized;
        public bool WasDeserialized
        {
            get { return _wasDeserialized; }
            set { _wasDeserialized = value; }
        }

        #endregion

        public ClassIAltSerializable()
        {
        }

        public ClassIAltSerializable(SerializerTestBase test)
        {
            Message = (string)test.GetRandomData(typeof(string));
            Value = (int)test.GetRandomData(typeof(int));
        }

        #region IAltSerializable Members

        public void Serialize(AltSerializer serializer)
        {
            WasSerialized = true;
            serializer.Write(Message);
            serializer.Write(Value);
        }

        public void Deserialize(AltSerializer deserializer)
        {
            WasDeserialized = true;
            Message = deserializer.ReadString();
            Value = deserializer.ReadInt32();
        }

        #endregion
    }
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
I've been writing code since I started learning BASIC on the Apple //c. Since then, I've learned C, C++, a few assembly languages. I went to college for Computer Science and Mathematics at the University of Texas at Dallas.

Comments and Discussions