2

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.

Community
  • 1
  • 1
Stay Foolish
  • 3,636
  • 3
  • 26
  • 30

1 Answers1

0

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

Ruslan_K
  • 423
  • 7
  • 23
Stay Foolish
  • 3,636
  • 3
  • 26
  • 30
  • I have the same issue. I kindly request you to specify in a wee more detail of how you solved it using xsd2code. – HelpMatters Sep 01 '14 at 05:04
  • 1
    When you generate that using the UI, there is an option call GeneratePropertyNameSpecified and if you set that to None, it won't generate the Prefix – Stay Foolish Sep 04 '14 at 06:26
  • Thanks. Found it. It probably helps if you can put a screenshot in your answer. It might help people to save the time to search for it in the tool again. – HelpMatters Sep 04 '14 at 18:27