加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

XML序列化和空值 – C#

发布时间:2020-12-16 08:01:27 所属栏目:百科 来源:网络整理
导读:我有一个我将序列化为XML的对象。如果对象中的一个属性为空,则本机序列化将忽略此属性作为属性。这是正常的行为,如果是这样,有办法可以覆盖它吗? 例如: public class Test{ [XmlAttribute] public string value {set; get; } [XmlAttribute] public str
我有一个我将序列化为XML的对象。如果对象中的一个属性为空,则本机序列化将忽略此属性作为属性。这是正常的行为,如果是这样,有办法可以覆盖它吗?

例如:

public class Test
{
  [XmlAttribute]
  public string value {set; get; }

  [XmlAttribute]
  public string key {set; get; }
}

当值为null时,我得到

<Root>
  <Test key="blah">
</Root>
XmlElement( IsNullable = true )

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读