我有以下设置:
[Serializable]
public class TickerSymbol : ISerializable
{
public readonly string Symbol;
public TickerSymbol(string Symbol)
{
this.Symbol = Symbol;
}
protected TickerSymbol(SerializationInfo info, StreamingContext context)
{
// Call Order: 3
Symbol = info.GetString("Symbol");
}
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue<string>("Symbol", Symbol);
}
[OnDeserialized]
public void OnDeserialized(StreamingContext context)
{
// Call Order: 1
// Do something that requires the symbol to not be null
}
}
[Serializable]
public class EquitySymbol : TickerSymbol, ISerializable
{
public EquitySymbol(stirng Symbol)
: base(Symbol)
{
}
protected EquitySymbol(SerializationInfo info, StreamingContext context)
: base(info, context)
{
// Call Order: 4
}
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
}
[OnDeserialized]
public void OnDeserialized(StreamingContext context)
{
// Call order 2
}
}
我本来希望在各自的序列化构造函数之后调用标有 [OnDeserialized] 的方法,但看起来好像在它们的序列化构造函数之前调用它们 - 这应该如何工作?
威廉