gpt4 book ai didi

c# - 关闭/忽略 xsd 代码生成中指定的字段后缀

转载 作者:太空宇宙 更新时间:2023-11-03 15:55:09 24 4
gpt4 key购买 nike

我在使用模式生成代码时遇到问题

<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 字段的选项,或者无论如何让序列化程序忽略它。架构中有很多可选字段,我们不想总是在那里设置值。

最佳答案

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

截图:

enter image description here

关于c# - 关闭/忽略 xsd 代码生成中指定的字段后缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23987100/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com