C#デフォルトのコンストラクタの代わりにDESERIALIZALIZATIONコンストラクタが呼び出されますか?
-
12-12-2019 - |
質問
私はC#のオブジェクトの直列化に精通しているだけです。デフォルトコンストラクターの代わりに、またはそれに加えて、デシリアライズコンストラクタが呼び出されているかどうか疑問に思います。それに加えて、これらはどの順序で呼ばれていますか?例えば:
[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));
}
.
" ...:この()" - 構文 - しかしあなたの特別なケースでは必要ありません!
所属していません StackOverflow