我已经在子类和父类中实现了 ISerializable,如下所示:
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);
}
}
但是在子类Bus
中,我遇到了错误Use of keyword base is not valid in this context
。我知道我可以在父CircuitElement
类上隐式实现接口,然后我不必担心转换,但我的印象是显式实现更适合这种情况(原因类似于此处介绍的原因:https://stackoverflow.com/a/143425/996592)
有没有办法进行转换,或者我是否ISerializable
隐式地在父类中实现接口?