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

前端 未结 3 1351
情话喂你
情话喂你 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:52

    This is because XmlSerializer only serializes public fields/properties. Other forms of serialization can serialize private data, which constitutes a potential security risk, so you have to "opt in" using an attribute.

提交回复
热议问题