How to exclude null properties when using XmlSerializer

前端 未结 9 1551
谎友^
谎友^ 2021-02-02 07:11

I\'m serializing a class like this

public MyClass
{
    public int? a { get; set; }
    public int? b { get; set; }
    public int? c { get; set; }
}
         


        
9条回答
  •  迷失自我
    2021-02-02 08:03

    Better late than never...

    I found a way (maybe only available with the latest framework I don't know) to do this. I was using DataMember attribute for a WCF webservice contract and I marked my object like this:

    [DataMember(EmitDefaultValue = false)]
    public decimal? RentPrice { get; set; }
    

提交回复
热议问题