I've implemented ISerializable in both a child class and a parent class, like this:
class CircuitElement : ISerializable
{
...
protected void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
throw new ArgumentNullException("info");
info.AddValue("ID", ID);
}
}
class Bus : CircuitElement, ISerializable
{
...
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
throw new ArgumentNullException("info");
((ISerializable)base).GetObjectData(info,context);
info.AddValue("Voltage", Voltage);
info.AddValue("BaseVoltage", BaseVoltage);
info.AddValue("Location", Location);
}
}
But in the child class Bus
, I'm getting the error Use of keyword base is not valid in this context
. I know I can just implement the interface implicitly on the parent CircuitElement
class, and then I don't have to worry about the conversion, but was under the impression that explicit implementation is more appropriate for this scenario (for reasons akin to those presented here: https://stackoverflow.com/a/143425/996592)
Is there a way to do the conversion, or am I stuck implementing the ISerializable
interface in the parent class implicitly?