C
Chris Holmes
I'm working on an application where we need to persist
decimal values on a PocketPC device, but the Compact
Framework doesn't support decimal types in the BinaryWriter/
BinaryReader classes, or even in the BitConverter class.
Is there some nice, happy way to convert a decimal into
it's byte array equivalent through the framework?
At the moment, I'm accomplishing the task by using some
unsafe code that looks like this:
public byte[] Serialize( decimal d ) {
byte[] data = new byte[16]; // decimals being 16 bytes
fixed( byte *ptr = data ) {
*(decimal *)ptr = d;
}
return data;
}
Deserialization works almost exactly the same way.
Is there a better way to do this conversion, and are there
any problems with this particular method of doing the
conversion? I really don't understand why every type but
decimal is supported throughout the Compact Framework.
Thanks much,
Chris
decimal values on a PocketPC device, but the Compact
Framework doesn't support decimal types in the BinaryWriter/
BinaryReader classes, or even in the BitConverter class.
Is there some nice, happy way to convert a decimal into
it's byte array equivalent through the framework?
At the moment, I'm accomplishing the task by using some
unsafe code that looks like this:
public byte[] Serialize( decimal d ) {
byte[] data = new byte[16]; // decimals being 16 bytes
fixed( byte *ptr = data ) {
*(decimal *)ptr = d;
}
return data;
}
Deserialization works almost exactly the same way.
Is there a better way to do this conversion, and are there
any problems with this particular method of doing the
conversion? I really don't understand why every type but
decimal is supported throughout the Compact Framework.
Thanks much,
Chris