开发者

DataContractSerializer and Constructors in Silverlight [duplicate]

开发者 https://www.devze.com 2023-04-06 02:47 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: 开发者_开发问答 How does WCF deserialization instantiate objects without calling a constructor?
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

开发者_开发问答 How does WCF deserialization instantiate objects without calling a constructor?

If I use a DataContract attribute it doesn't call my constructor, but if I skip it then it will. Why does this happen?


The purpose of serializing/deserializing is to recreate the object in its original state. The object has already been constructed so we don't need to call the constructor. It is like raising an object from the dead rather than giving birth. :)

If you need some code to happen when an object is deserialized just decorate a method with the OnDeserialized attribute and call the code you need to execute from there.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号