Serialization inheritance

I

Ilya Evseev

Hi, folks!
There is some class in external library
that is declared with [Serializable()] attribute.
I need to create class inherited from them
that should be serializable too.
My class uses fields calculated at deserialization stage,
so it's declared not as following:
[Serializable()]
class MyClass : BaseClass { ... }

but as following (look all !!! and ???'s carefully:):

class MyClass : BaseClass, ISerializable
{
protected int SimpleField; // serializable
protected int CalculatedField; // non-serializable

public MyClass(
SerializationInfo info,
StreamingContext ctx)
// : base(info, ctx) // error!!!
{
// my stuff
info.Add("SimpleField", SimpleField);
}
public virtual void GetObjectData(
SerializationInfo info,
StreamingContext ctx)
{
// base.GetObjectData(info, ctx); // error!!!
// my stuff
SimpleField = info.GetInteger("SimpleField");
// how to conform next line
// with calling of inherited deserialization routine???
CalculatedField = SomethingVerySpecial(SimpleField);
}
}

Well, I don't know how to call inherited constructor
and GetObjectData from my own constructor/GetObjectData
appropriately, because this functionality in base class
is generated implicitly and cannot be called by name.

How to solve this problem?

WBR, Ilya
 
V

Vadym Stetsyak

Well, I don't know how to call inherited constructor
and GetObjectData from my own constructor/GetObjectData
appropriately, because this functionality in base class
is generated implicitly and cannot be called by name.

How to solve this problem?

you can use ConstuctorInfo class from System.Reflection namespace with the
GetConstructor method
 

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