/*
OpenNxSerialization Framework
Copyright (C) 2006 - 2007 "NeXtreme Innovations"
[The Next Xtreme in ingenuity]
This program is free software, distributed under the terms of
the GNU General Public License Version 2. See the License file
at the top of the source tree.
*/
using System;
using System.Collections;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using NeXtreme.OpenNxSerialization;
using NeXtreme.OpenNxSerialization.IO;
using NeXtreme.OpenNxSerialization.Surrogates;
namespace NeXtreme.CommonTypes
{
/* How to use an INxSerializable */
/// <summary>
/// Demomstrates a custom type that implements <see cref="INxSerializable"/>.
/// </summary>
[Serializable]
public class SampleINxSerializableClass : INxSerializable
{
public const short FIXED_ID = 0xFee;
private string id;
private SampleInternalType nested = new SampleInternalType();
private Hashtable table = new Hashtable(11);
/// <summary> Default constructor is not mandatory for types that implement INxSerializable.</summary>
public SampleINxSerializableClass() { }
public SampleINxSerializableClass(String title)
{
id = title;
table[1] = new SampleInternalType();
table[2] = new SampleInternalType();
table[3] = new SampleInternalType();
table[4] = new SampleInternalType();
}
/// <summary>
/// Implementation of INxSerializable.Serialize
/// </summary>
void INxSerializable.Serialize(INxBinaryWriter w)
{
w.WriteObject(id);
w.WriteObject(nested);
w.WriteObject(table);
}
/// <summary>
/// Implementation of INxSerializable.Deserialize
/// </summary>
void INxSerializable.Deserialize(INxBinaryReader r)
{
id = (String)r.ReadObject();
nested = (SampleInternalType)r.ReadObject();
table = (Hashtable)r.ReadObject();
}
}
}