DataContractSerializer: How to serialize classes/members without DataContract/DataMember attributes

后端 未结 3 1161
有刺的猬
有刺的猬 2020-12-16 03:36

DataContractSerializer requires classes and members to be marked with the DataContract and DataMember attributes. However, in my case

3条回答
  •  离开以前
    2020-12-16 04:24

    Just mark the class with the [Serializable] attribute. Any members you don't want serialized mark with [NonSerialized]. Note that [Serializable] causes all fields to be serialized by default, where [DataContract] serialized no fields by default except those marked with [DataMember].

提交回复
热议问题