Stay Foolish Stay Foolish - 21 days ago 7
C# Question

Turn of/Ignore the speicified field postfix in xsd code generation

I am having a problem generating the code using the schema

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


There is some nullable field e.g. ID in the complexType, After I run the schema generation (we are using xsd in the company), i am getting the following code.

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;
}
}


It seems like that in order for the ID field to be serialized, i need to set the IDSpecified to be true...

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

I am wondering if there is a way to disabled the option to generate the XXSpecified field or anyway to let the Serializer to ignore that. There are many optional fields in the schema, we don't want to always set the value there.

Answer Source

At the end i managed to solve the problem using xsd2code. there is an option to control whether we need to generate the specified field or not

Screenshot:

enter image description here