'How to tell xsd.exe to use a specific .NET type for a custom xs:simpleType?

In my XSD I have some type definitions like this:

<xs:simpleType name="Ref_System">
    <xs:restriction base="xs:string">
        <xs:pattern value="[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}"/>
    </xs:restriction>
</xs:simpleType>

Obviously, this defines a UUID. However, since the xs:simpleType is based on xs:string, the xsd.exe tool will create a string property for elements using this type Ref_System.

The following xs:complexType...

<xs:complexType name="Incident">
    <xs:sequence>
        <xs:element name="system" type="Ref_System" minOccurs="1" maxOccurs="1" />
        <!-- ... -->
    </xs:sequence>
</xs:complexType>

...will result in the following C# class:

public partial class Incident {
    private string systemField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
    public string system {
        get {
            return this.systemField;
        }
        set {
            this.systemField = value;
        }
    }

    // ...
}

Is there any way to tell the xsd.exe tool to generate Guid properties for elements which use the Ref_System type?

Note: It is not an option to change the XSD file since this is coming from an external source!

Note 2: I know that I can extend the partial class, define a custom Guid property in there and then convert the string property to the Guid property using XmlConvert.ToGuid(...). However, since I have lots of cases like this, I would like to avoid the manual work and use an automated approach instead.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source