Why doesn't the XmlSerializer need the type to be marked [Serializable]?

前端 未结 3 1372
情话喂你
情话喂你 2020-11-28 12:11

In C#, if I want to serialize an instance with XmlSerializer, the object\'s type doesn\'t have to be marked with [Serializable] attribute. However,

3条回答
  •  时光说笑
    2020-11-28 12:46

    Right now there are really 3 forms of serialization in the .Net Framework.

    1. XmlSerialization - By default works on public fields and properties. Can still be controlled via XmlElementAttribute, XmlAttributeAttribute, etc ...
    2. BinarySerialization - Controlled by the SerializationAttribute. Deeply integrated into the CLR
    3. WCF Seralization - DataContractAttribute, etc ...

    There unfortunately is standard overall pattern for serialization. All 3 frameworks have different requirements and quirks.

提交回复
热议问题