Why does DataContractSerializer bypass initializers?

Why are DataContractSerializer byte initializers?

Background:

Serialization formatting receives uninitialized class instances during deserialization. That is, instances where all fields have default values. For reference types, this will be null. That is why the "authors" in this case lead to the exclusion of a null reference. You must create it in a property, such as the code you commented out. By including this "lazy" initialization code for authors, you can remove the field initializer. In addition, you must modify the constructor to use a property, rather than a directive field.

/ Calla http://social.msdn.microsoft.com/Forums/en-CA/netfxremoting/thread/b786050e-4850-4739-8b2e-d57e35d95952

+3
source share
1 answer

For performance reasons — deserializing using a constructor with no default parameters and setting properties is rather slow — the way WCF is handled is much faster.

For this reason, the DataContractSerializer does not require a taskless public constructor (for example, XmlSerializer) - you do not need it, it will not be used in any case.

+3
source

Source: https://habr.com/ru/post/1751258/


All Articles