c # 기본 생성자 대신 Deserialization 생성자가 호출됩니까?
-
12-12-2019 - |
문제
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));
}
.
" ... :이 () "- 구문 -하지만 특별한 경우에는 필요하지 않습니다!
제휴하지 않습니다 StackOverflow