Search code examples
c#xsdxsd2code

Using non default types within a xsd definition for xsd2code when generating C# code


In our project we are using Xsd2Code to generate c# code.

The XSD I am trying to adjust looks like this:

<?xml version="1.0"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="File">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Version" type="xs:string" />
        <xs:element name="Language" type="xs:string" />
        <xs:element name="Component" type="xs:anyType" minOccurs="1" maxOccurs="unbounded" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Within our project we now defined an abstract class Version. Is it possible to use our own class Version instead of string as the type of the element Version within the Xsd?

We would like to generate as many classes as possible using Xsd2Code. That's why I want to avoid to also having to create the File class by hand.

Thanks in advance for any help.


Solution

  • You can create a new abstract class Version in xsd scheme and then make your defined Version class as partial and put it to the same namespace as the generated classes. By default all your generated classes must be partial.