public object ToStructure(byte[] data, int offset, Type type)
{
object obj;
GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
try
{
obj = Marshal.PtrToStructure(handle.AddrOfPinnedObject() + offset, type);
}
finally
{
handle.Free();
}
return obj;
}