Binary serialization and versioning

T

Tamir Khason

I have a base class MyBaseFoo with some properties, methods etc.
I have some derived classes, implements small part of MyBaseFoo and a lot of
their own.
In order to ensure proper deserialization on versioning MyBaseFoo implements
ISerializable and override constructor
So following
public void GetObjectData(SerializationInfo info, StreamingContext context)

{

//info.AddValue("foo",foo);

//etc..

}

public MyBaseFoo(SerializationInfo info,StreamingContext context)

{

//foo = (Foo)info.GetValue("foo",typeof(foo));

}


The problem begins at derrived classes (with thier own variables)
The serialization made ONLY for base members, but not for derrived members.
Is any way to "discover" who inherit the class and get all properties to
serialize? Or I have to override both implementation and constructor
manually in derrived class. Is any intelligent way to implement such
pattern?

TNX
 
?

=?ISO-8859-2?Q?Marcin_Grz=EAbski?=

Hi,

I think that your problem lies in the implementation of "inherited"
classes.

If "base" class implements "ISerializable" then any its "implemented"
class should implements "ISerializable" too.

e.g.

public class MyNextFoo: MyBaseFoo
{

public MyNextFoo(SerializationInfo info,StreamingContext context)
: base(info, context)
{
// your deserialization code here!
}

public void GetObjectData(SerializationInfo info
, StreamingContext context)
{
base.GetObjectData(info, context);

// your serialization code here
}
}

HTH
Marcin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top