I am overloading the System.IO BinaryReader to serialize some classes for file storage purposes. I have had no issues doing items like dictionaries and such, but have not been successful with a nullable type. Is it possible to do? Specifically I am attempting decimal? and string?, but any types should work for me to adapt my solution to.
I have to do binary serialization for specific business reasons, so please limit responses to only solutions that work for that.
For Example... for Reading/Writing a Byte Array I use these methods:
public byte[] ReadByteArray()
{
int len = ReadInt32();
if (len > 0) return ReadBytes(len);
if (len < 0) return null;
return new byte[0];
}
public override void Write(byte[] b)
{
int len = b.Length;
Write(len);
if (len > 0) base.Write(b);
}