Domanda

Sto solo familiarizzando con la serializzazione degli oggetti in C #.Mi chiedo se il costruttore di deserializzazione viene chiamato al posto del costruttore predefinito o in aggiunta a.Se è in aggiunta a, quale ordine sono chiamati?Ad esempio:

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

È stato utile?

Soluzione

No Verrà chiamato "invece" del default - ma puoi inizializzare la tua lista con qualcosa del genere:

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

Si prega di notare il " ...: questo () " - Sintassi - Ma nel tuo caso speciale non devi!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top