8

Is it possible to force xsd.exe to generate auto-implemented properties instead of the ugly manually implemented code which xsd.exe generates?

public abstract partial class SomeClass {

    private string valueField;

    /// <remarks/>
    [System.Xml.Serialization.XmlTextAttribute()]
    public string Value {
        get {
            return this.valueField;
        }
        set {
            this.valueField = value;
        }
    }
}
Suchiman
  • 1,636
  • 2
  • 20
  • 30
  • Why? There's no real difference, or performance benefit. It's just auto-generated code that you shouldn't be modifying anyway. – Bryan Boettcher Sep 10 '14 at 22:45
  • In case someone stumbles over this that does not need the get/set at all. The /fields option generates fields instead of properties and does not generate any getter or setters. – HeikoG Mar 20 '19 at 10:08

1 Answers1

11

It seems XML Schema Definition Tool (Xsd.exe) does not support generating auto-implemented properties.

But there is an alternative: Xsd2Code community edition. From feature list:

Support automatic properties when no special get or set is required.

Related answer: XSDObjectGen.exe vs XSD.exe.

Community
  • 1
  • 1
  • 2
    Beware that Xsd2Code has also a commercial side and some free features have jumped at least once unexpectedly from the free world to commercial. Do not rely on generated code private bits whichever way you go. – Imre Pühvel Jun 27 '16 at 12:38