Pergunta

Estou apenas me familiarizando com a serialização de objetos em C#.Gostaria de saber se o construtor de desserialização é chamado INSTEAD OF do construtor padrão ou IN ADDITION TO.Se for ALÉM DE, em que ordem são chamados?Por exemplo:

[Serializable()]
public class ReadCache : ISerializable
{
    protected ArrayList notifiedURLs;

    // Default constructor
    public ReadCache()
    {
        notifiedURLs = new ArrayList();
    }

    // Deserialization constructor.
    public ReadCache(SerializationInfo info, StreamingContext ctxt)
    {
        //Get the values from info and assign them to the appropriate properties
        notifiedURLs = (ArrayList)info.GetValue("notifiedURLs", typeof(ArrayList));
    }
}
Foi útil?

Solução

Não, ele será chamado "em vez" do padrão - mas você pode inicializar sua lista com algo assim:

public ReadCache(SerializationInfo info, StreamingContext ctxt)
  : this()
{
    //Get the values from info and assign them to the appropriate properties
    notifiedURLs = (ArrayList)info.GetValue("notifiedURLs", typeof(ArrayList));
}

Observe o "...:esse()" - sintaxe - mas no seu caso especial você não precisa!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top