M
Maheal
I have been trying to Serialize an object that is the child of another
object which is also serializable. Here is the simplified scenario
(assume missing code is correct):
class One : ISerializable {
int x;
int y;
One() {}; // constructor
One(SerializationInfo i, StreamingContext c) { // deserialization
constructor
// deserialize x and y
};
GetObjectData(SerializationInfo i, StreamingContext c) {
// serialize x and y
};
}
class Two : One, ISerializable {
int z;
One() {}; // constructor
One(SerializationInfo i, StreamingContext c) { // deserialization
constructor
// deserialize z
};
GetObjectData(SerializationInfo i, StreamingContext c) {
// serialize z
};
}
Here's the problem... I can serialize class One just fine, it saves x
and y and reloads it. However class Two returns a compile warning,
"The keyword new is required on Two.GetObjectData() because it hides
inherited member One.GetObjectData()" Whether I add "new" or not
doesn't matter, it only serializes "z", not "x" and "y". I have found
that calling base.GetObjectData() is an easy way around this. But,
deserialization has the same problem. It will use the deserialization
constructor for Two, but the regular constructor for its parent, One.
It seems there should be an easy way to get serialization to follow
the laws of inheritance. I'm not about to write duplicate code for
each child of One. It's tedious and bad programming....what if I
changed One? Is there anyway to get Serialization to work this way?
Maheal
object which is also serializable. Here is the simplified scenario
(assume missing code is correct):
class One : ISerializable {
int x;
int y;
One() {}; // constructor
One(SerializationInfo i, StreamingContext c) { // deserialization
constructor
// deserialize x and y
};
GetObjectData(SerializationInfo i, StreamingContext c) {
// serialize x and y
};
}
class Two : One, ISerializable {
int z;
One() {}; // constructor
One(SerializationInfo i, StreamingContext c) { // deserialization
constructor
// deserialize z
};
GetObjectData(SerializationInfo i, StreamingContext c) {
// serialize z
};
}
Here's the problem... I can serialize class One just fine, it saves x
and y and reloads it. However class Two returns a compile warning,
"The keyword new is required on Two.GetObjectData() because it hides
inherited member One.GetObjectData()" Whether I add "new" or not
doesn't matter, it only serializes "z", not "x" and "y". I have found
that calling base.GetObjectData() is an easy way around this. But,
deserialization has the same problem. It will use the deserialization
constructor for Two, but the regular constructor for its parent, One.
It seems there should be an easy way to get serialization to follow
the laws of inheritance. I'm not about to write duplicate code for
each child of One. It's tedious and bad programming....what if I
changed One? Is there anyway to get Serialization to work this way?
Maheal