Binary serialization and versioning

  • Thread starter Thread starter Tamir Khason
  • Start date Start date
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
 
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
 
Back
Top