Pregunta

Me estoy familiarizando con la serialización de los objetos en C #.Me pregunto si el constructor de deserialización se llama en lugar del constructor predeterminado o además de.Si está además de, ¿en qué orden se llama estos?Por ejemplo:

[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));
    }
}

¿Fue útil?

Solución

No se llama "en su lugar" de los predeterminados, pero puede inicializar su lista con algo así:

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));
}

Tenga en cuenta la " ...: esta () " - sintaxis, pero en su caso especial, no tiene que hacerlo.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top