Xml Serialization - Render Empty Element

前端 未结 5 1448
说谎
说谎 2021-02-07 03:44

I am using the XmlSerializer and have the following property in a class

public string Data { get; set; }

which I need to be output exactly like

5条回答
  •  甜味超标
    2021-02-07 04:26

    try to use public bool ShouldSerialize_PropertyName_(){} with setting the default value inside.

    public bool ShouldSerializeData()
    {
       Data = Data ?? "";
       return true;
    }
    

    Description of why this works can be found on MSDN.

提交回复
热议问题