What are the differences between the XmlSerializer and BinaryFormatter

前端 未结 5 1980
-上瘾入骨i
-上瘾入骨i 2020-11-29 16:54

I spent a good portion of time last week working on serialization. During that time I found many examples utilizing either the BinaryFormatter or XmlSerializer. Unfortunatel

5条回答
  •  不知归路
    2020-11-29 17:36

    The XmlSerializer serialises the type by reading all the type's properties that have both a public getter and a public setter (and also any public fields). In this sense the XmlSerializer serializes/deserializes the "public view" of the instance.

    The binary formatter, by contrast, serializes a type by serializing the instance's "internals", i.e. its fields. Any fields that are not marked as [NonSerialized] will be serialized to the binary stream. The type itself must be marked as [Serializable] as must any internal fields that are also to be serialized.

提交回复
热议问题