Hi,
to transform a structure to array of byte[] I am using the following
procedure:

public static unsafe byte[] StructToByte(MySimpleStruct simpleStruct)
{
  byte[] arr = new byte[
System.Runtime.InteropServices.Marshal.SizeOf(simpleStruct) ];
  fixed( byte* parr = arr )
  {
    *((MySimpleStruct*)parr) = simpleStruct;
  }
  return arr;
}

in order to keep it more generic, I can change the parameter to
ValueType. The problem raises on the casting:

*((MySimpleStruct*)parr) = simpleStruct;

Is it possible to make somwthing like a dynamic_cast ?

Thanks
Pierre

-----------------------------------------------
Pierre Greborio
[EMAIL PROTECTED]
http://www.pierregreborio.it <http://www.pierregreborio.it/>
-----------------------------------------------





You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to