开发者

DataContractSerializer and Constructors in Silverlight [duplicate]

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜