Is there a way to avoid the XmlSerializer to not initialize a null property when deserializing?

后端 未结 4 1747
旧巷少年郎
旧巷少年郎 2020-12-16 18:00

I have this class:

public class MySerializableClass
{
    public List MyList { get; set; }
}

If MyList is null when MySeria

4条回答
  •  暖寄归人
    2020-12-16 18:31

    If you add a property with the name *PropertyName*Specified as a boolean the XmlSerializer will render the tag for the list only when it is true.

    Example:

    public class MySerializableClass
    {
        public List MyList { get; set; }
    
        [XmlIgnore]
        public bool MyListSpecified { get; set; }
    }
    

提交回复
热议问题