DataContract, default DataMember value

后端 未结 3 1768
醉梦人生
醉梦人生 2021-02-18 18:07

Is there a way to choose default values of attributes that are not in the xml file during deserialization?
If the mAge attribute is not present in the xml file,

3条回答
  •  星月不相逢
    2021-02-18 18:59

    use [OnDeserializing()]

    and you set your values BEFORE the deserialization. So there is no check necessary, which could go wrong - what if the mAge was serialized to be 0?

提交回复
热议问题