xsd.exe 在不显示 nil 属性的情况下进行序列化时显示 null 属性

问题描述

我使用 xsd.exe 从我的 xsd 文件生成一个 cs 文件我有一个可以有空值的元素。当我序列化类时,如果它为空,则属性消失,如果我设置 IsNullable = true,它会显示属性但没有属性,有没有办法修改 xsd.exe 生成的 cs 文件显示没有属性的空标签

[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified,IsNullable = true)]
public string Phone {
    get { return this.phoneField; }
    set { this.phoneField = value; }
}

如果 Phone = null 和 IsNullable = true,我得到

<Phone p7:nil="true" xmlns:p7="some namespace" />

如果 Phone = null 且 IsNullable = false,Phone 甚至不会出现在我的 xml 文件中。

期望的输出

<Phone />

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)