我只是熟悉C#中对象的序列化。我想知道Deserialization构造函数是否被调用而不是默认构造函数或除了。如果它是此之外,这些令在哪个订单中呼叫?例如:

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

有帮助吗?

解决方案

否它将被称为“而不是”默认值 - 但您可以使用类似的内容初始化列表:

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

请注意“ ...:这个()” - 语法 - 但在您的特殊情况下,您不必!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top