我一直在使用 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;
}
}
目前它按预期工作。我正在使用 xsd v2.0.50727.42 并且:
<xs:element name="Port" type="xs:int" nillable="true" />
准确生成您一直在寻找的内容(没有多余的...Specified
字段和属性):
private System.Nullable<int> portField;
[System.Xml.Serialization.XmlElementAttribute(IsNullable = true)]
public System.Nullable<int> Port {
get {
return this.portField;
}
set {
this.portField = value;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)