This question does a good job of explaining the difference in functionality between the serializers. BinaryFormatter
is fast, XmlSerializer
is interoperable, etc. I know that.
But what is the difference in intent? What use-case was each class designed for?
In particular:
- Why did they decide to make
XmlSerializer
blind for private data, whenBinaryFormatter
sees it fast enough (via the supposedly-slow reflection) - Why did they make 3 separate XML serializers -
XmlSerializer
,SoapFormatter
andDataContractSerializer
? - Why are some opt-in and some opt-out?
- Why did they make the interfaces so inconsistent? E.g. XmlSerializer doesn't provide an
OnDeserializedCallback
equivalent. Another example - XmlSerializer usesIsNullable
[XmlIgnore]
for what BinarySerializer uses[OptionalField]
and[NonSerialized]
.