【问题标题】:Turn of/Ignore the speicified field postfix in xsd code generation在 xsd 代码生成中打开/忽略指定字段后缀
【发布时间】:2014-06-02 03:50:18
【问题描述】:

我在使用架构生成代码时遇到问题

<xs:complexType name="SampleComplexType">
   <xs:sequence>
      <xs:element minOccurs="0" name="ID" type="xs:int"/>

有一些可以为空的字段,例如complexType 中的 ID,在我运行模式生成后(我们在公司使用 xsd),我得到以下代码。

public partial class SampleComplexType
{

    private int idField;

    private bool idFieldSpecified;

[System.Xml.Serialization.XmlElementAttribute(Order=0)]
public int ID
{
    get
    {
        return this.idField;
    }
    set
    {
        this.idField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool IDSpecified
{
    get
    {
        return this.idFieldSpecified;
    }
    set
    {
        this.idFieldSpecified = value;
    }
}

似乎为了序列化 ID 字段,我需要将 IDSpecified 设置为 true...

XSD tool appends "Specified" to certain properties/fields when generating C# code

我想知道是否有办法禁用生成 XXSpecified 字段的选项,或者无论如何让序列化程序忽略它。架构中有许多可选字段,我们不想总是在那里设置值。

【问题讨论】:

    标签: c# .net xml serialization xsd


    【解决方案1】:

    最后我设法使用 xsd2code 解决了这个问题。有一个选项可以控制我们是否需要生成指定的字段

    截图:

    【讨论】:

    • 我也有同样的问题。我恳请您详细说明您是如何使用 xsd2code 解决它的。
    • 当您使用 UI 生成时,有一个选项调用 GeneratePropertyNameSpecified 如果您将其设置为 None,它将不会生成前缀
    • 谢谢。找到了。如果您可以在答案中放置屏幕截图,这可能会有所帮助。它可能会帮助人们节省再次在工具中搜索它的时间。
    猜你喜欢
    • 2021-11-24
    • 2020-07-10
    • 2018-08-22
    • 2019-11-20
    • 2012-08-21
    • 1970-01-01
    • 2015-12-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多