【发布时间】:2012-09-05 14:25:05
【问题描述】:
我有一个包含我希望用 XmlSerializer 序列化的数组的类:
[XmlArray("properties")]
[XmlArrayItem("property", IsNullable = true)]
public List<Property> Properties { get; set; }
Property是一个包含一个属性和一些XmlText的类:
[XmlAttribute("name")]
public string Name { get; set; }
[XmlText]
public string Value { get; set; }
问题是当Value为null时,序列化为空字符串:
<property name="foo" />
而不是 null。我正在寻找要完全省略的值,或者看起来像这样:
<property name="foo" xsi:nil="true" />
是否可以根据XmlText 值将列表中的元素清空?我真的想避免自定义序列化,但在这种情况下,也许其他一些序列化框架会更好?
【问题讨论】:
-
只是从臀部射击 - 尝试使用
public string? Value而不是仅仅使用public string Value并让我们知道它是否有所作为。 -
string是引用类型,所以怕是isn't nullable in that way。 -
啊,我明白了。 this 有什么帮助吗?
标签: .net xmlserializer