Serialize&Deserialize Composite objects

  • Thread starter Thread starter Gianmaria
  • Start date Start date
G

Gianmaria

Hi,
how do i deserialize a composite object

my object have this structure...

obj
|_ leaf
|_subObj
|_leaf

and so on.. everything ok when i serialize (i'm using bin formatting), but
when i deserialize...

i have a costructor for desialization like this...

public Ghost(System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
{
this.leaf = info.GetValue("Leaf")
}

Do i have to use info.GetValue during deserializaion????



Regards,

Gianmaria
 
Hi

I'm affraid that method "GetValue" needs the Type of
returned object. And if your "leaf" variable type is
other than "object" you should provide a type casting.

e.g.

this.leaf = (LeafType) info.GetValue("Leaf"
, typeof(LeafType));

I'm not sure, but it should work if you replace
LeafType with its interface (then leaf variable should
be that interface too).

Regards

Marcin
 
Back
Top