DataContractSerializer vs XmlSerializer: Pros and Cons of each serializer

前端 未结 1 1794
悲&欢浪女
悲&欢浪女 2020-11-30 22:14

My desktop application serializes objects using XmlSerializer. I was suggested to leverage DataContractSerializer instead.
Under which scenario

相关标签:
1条回答
  • 2020-11-30 22:33

    Dan Rigsby has the ultimate post on this - go read it!

    XmlSerializer vs. DataContractSerializer (web archive)

    He says all there is to say, and in a very convincing way.

    In short:

    XmlSerializer:

    • has been around for a long time
    • is "opt-out"; everything public gets serialized, unless you tell it not to ([XmlIgnore])

    DataContractSerializer is:

    • the new kid in town
    • optimized for speed (about 10% faster than XmlSerializer, typically)
    • "opt-in" - only stuff you specifically mark as [DataMember] will be serialized
    • but anything marked with [DataMember] will be serialized - whether it's public or private
    • doesn't support XML attributes (for speed reasons)
    0 讨论(0)
提交回复
热议问题