我一直在使用 xsd.exe 生成一个用于将 XML 反序列化为的类。我在源 xsd 中有不需要的十进制值:
<xs:attribute name="Balance" type="xs:decimal" use="optional" />
xsd 生成的类生成以下代码:
private decimal balanceField;
[System.Xml.Serialization.XmlAttributeAttribute()]
public decimal Balance {
get {
return this.balanceField;
}
set {
this.balanceField = value;
}
}
我注意到这是不可为空的。
如何改为将字段生成为可为空,如下所示:
private decimal? balanceField;
[System.Xml.Serialization.XmlAttributeAttribute()]
public decimal? Balance {
get {
return this.balanceField;
}
set {
this.balanceField = value;
}
}