>I want to translate an objects data to a byte array and vice-versa. The
> closest thing I found is Marshal.StructureToPtr(), and
[quoted text clipped - 3 lines]
> Is there an equivalent call that does a pure managed to managed byte array
> copy to and from an object?
The only problem that I have with serialization is the volume of data that
results from serializing a class object. I was hoping to just be able to
extract an array of bytes from the class object data. BitConverter only
works on primitive types.
I put together my own class to do this, but wanted to make sure it was not
already available.
Basically what I did was encapsulate the Marshal.PtrToStructure() and
Marshal.StructureToPtr() methods to do the translation via pinned objects to
and from a Byte Array. It seems to work pretty well, but I was not sure if
I was duplicating something that was already available.

Signature
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.
EmailID = varnk
Domain = Diebold.com
-----------------------------------
>I want to translate an objects data to a byte array and vice-versa. The
> closest thing I found is Marshal.StructureToPtr(), and
[quoted text clipped - 3 lines]
> Is there an equivalent call that does a pure managed to managed byte array
> copy to and from an object?
There's the BitConverter class, you'll have to do your own layout. If you
need to capture anything beyond binary numeric data (class type or
handle-linked structures), you're probably looking toward serialization
instead.
Ben Voigt - 06 Nov 2006 17:25 GMT
> The only problem that I have with serialization is the volume of data that
> results from serializing a class object. I was hoping to just be able to
> extract an array of bytes from the class object data. BitConverter only
> works on primitive types.
Yes, I think serialization is overkill for most purposes, it's geared toward
schema versioning and reconstructing object graphs with cycles.
> I put together my own class to do this, but wanted to make sure it was not
> already available.
[quoted text clipped - 20 lines]
> handle-linked structures), you're probably looking toward serialization
> instead.