[Mono-list] Serialization Compatability and workaround question

Neil Cawse neilcawse@hotmail.com
Fri, 28 Feb 2003 09:25:18 -0500


Thanks Lluis that is exactly what I need ;)

-----Original Message-----
From: Lluis Sanchez [mailto:lluis@ideary.com] 
Sent: February 28, 2003 5:30 AM
To: neilcawse@hotmail.com; mono-list@lists.ximian.com
Subject: Re: [Mono-list] Serialization Compatability and workaround
question

Hi,

> If I create a replacement for the Image object - how can I make sure
that
it will
> correctly deserialize from a form that was created using .NET?
> ie How do I deserialize to my image object from the ms image object.

Image implement ISerializable, which means that to serialize the data of
an
Image, the serialization formatter will call
ISerializable.GetObjectData(SerializationInfo info, StreamingContext
context). SerializationInfo is like a dictionary where you store the
data to
be serialized. You should use the same keys and value types that MS.NET
uses. The order desn't matter.

To deserialize an Image, the formatter calls a special constructor that
Image needs to implement (it can be private). This constructor must have
the
following signature: Image (SerializationInfo info, StreamingContext
context). In SerializationInfo you'll find the data that you need to
reconstruct the image.

> Without digging into the classes, does my Image object need to have
the
exact same members both private and public?

It would be needed if Image used default serialization, but it does not.
You
can use whatever variables you want. Only what you put in
SerializationInfo
will be serialized.

> Is it just variables I need to worry about (because that's all that
will
get serialized)? Must the order or
> the names be the same?

Order doesn't matter because the name of the fields are serialized
together
with the data.

> I will certainly be doing a different implementation to Microsofts -
with
additional variables -
> If I mark these not to be serialized?

This is a solution when using default serialization.

Regards,
Lluis.