DataContract, default DataMember value

后端 未结 3 1758
醉梦人生
醉梦人生 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条回答
  •  闹比i
    闹比i (楼主)
    2021-02-18 18:55

    This should work.

    [DataContract]
     public class Person 
      {
        public Person ()
        {
        }
        [DataMember(Name = "Name")]
        public string mName { get; set; }
        [DataMember(Name = "Age")]
        public int mAge = 18;
        [DataMember(Name = "Single")]
        public bool mIsSingle { get; set; }
      };
    

    Take a look at this page.

提交回复
热议问题