Hi all,

I made a setup of unboxed serialization. There is much work to do to make it useful to use. This is a raw setup version. The key is to write the value within the class it contains and publish/register the reader/writer method to the serializer.

It will look like this:

 

public delegate void ReadHandler(object obj, BinaryReader reader);
public delegate void WriteHandler(object obj, BinaryWriter writer);
public class SampleClass
{
	static SampleClass()
	{
		#region Value handler
		FastBinarySerializer.Register(
			"Value",
			typeof(double),
			typeof(SampleClass),
			(instance, reader) => 
			{ 
				((SampleClass)instance).Value = reader.ReadDouble(); 
			},
			(instance, writer) => 
			{ 
				writer.Write(((SampleClass)instance).Value); 
			});
		#endregion

		#region TimeStamp handler
		FastBinarySerializer.Register(
			"TimeStamp",
			typeof(DateTime),
			typeof(SampleClass),
			(instance, reader) => 
			{ 
				((SampleClass)instance).TimeStamp = new DateTime(reader.ReadInt64()); 
			},
			(instance, writer) => 
			{ 
				writer.Write(((SampleClass)instance).TimeStamp.Ticks); 
			});
		#endregion
	}

	public double Value { get; set; }
	public DateTime TimeStamp { get; set; }
}

 

Regards,

Jeroen

Last edited Apr 26, 2012 at 1:57 PM by jvanlangen, version 13

Comments

No comments yet.