I need to convert a byte array to a structure with conversion on the byte
order. I found the below deserilizer which works for getting the data
converted to a structure but it's in the wrong byte order. Basically it's
the whole big/little endian problem.
Is there someway to do this directly or do I need to use the bitconverter
step the array myself?
Regards,
John
public static object RawDeserializeEx( byte[] rawdatas, Type anytype )
{
int rawsize = Marshal.SizeOf( anytype );
if( rawsize > rawdatas.Length )
return null;
GCHandle handle = GCHandle.Alloc( rawdatas, GCHandleType.Pinned );
IntPtr buffer = handle.AddrOfPinnedObject();
object retobj = Marshal.PtrToStructure( buffer, anytype );
handle.Free();
return retobj;
}