I have the following setup:
[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
}
}
I would have expected the methods marked with [OnDeserialized] to be called after the respective serialization constructors, but it appears as though they are called BEFORE their serialization constructors - how is this supposed to work??
William