How to ignore a nullable property from serialization if it is null or empty?

后端 未结 5 1126
星月不相逢
星月不相逢 2021-01-14 15:15

I have a class which is used for Xml Serialization.

Inside which I have a nullable property which is decorated with XmlAttribute:

 [XmlAttribute(\"la         


        
5条回答
  •  半阙折子戏
    2021-01-14 15:50

    You can use XmlElementAttribute.IsNullable:

    [Serializable]
    public class Result
    {
        [XmlElement(IsNullable = true)]
        public DateTime? LastUpdated  { get; set; }
    }
    

提交回复
热议问题