Set DataContract and DataMember Without All the Attributes

后端 未结 3 916
死守一世寂寞
死守一世寂寞 2021-02-18 18:23

I find the [DataContract] and [DataMember] attributes a bit messy and would rather do this with code in a config method or something. Is this possible?

3条回答
  •  清歌不尽
    2021-02-18 19:01

    No, the DataContractSerializer is an opt-in serializer - you have to tell it what you want included.

    With other serializers you need to use things like NonSerializedAttribute or XmlIgnoreAttribute to tell the serializer to leave things alone.

提交回复
热议问题