Suppress Null Value Types from Being Emitted by XmlSerializer

前端 未结 3 423
野的像风
野的像风 2020-11-29 17:53

Please consider the following Amount value type property which is marked as a nullable XmlElement:

[XmlElement(IsNullable=true)] 
public double? Amount { ge         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-29 18:00

    There is also an alternative to get

      instead of 
    

    Use

    [XmlElement("amount", IsNullable = false)]
    public string SerializableAmount
    {
        get { return this.Amount == null ? "" : this.Amount.ToString(); }
        set { this.Amount = Convert.ToDouble(value); }
    }
    

提交回复
热议问题