DataContractSerializer and Constructors in Silverlight [duplicate]
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.
精彩评论