Nicholas Hill
Nicholas Hill

Reputation: 23

Excluding specific properties when serialising back to XML from data loaded in via XSD.exe generated classes?

I have generated classes from XSD using the "XSD.exe /c" command line. Partial classes were generated, so I "completed" them by adding classes with the same name, which allowed me to add additional properties. However, the value of these properties are being included whenever I serialise data back into XML files. Does anyone know how to prevent this, perhaps via an attribute?

Thanks very much,

Nick Hill

Upvotes: 2

Views: 249

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062885

[XmlIgnore]
public string Foo {get;set;}

actually (for completeness only), you can also do this by two other name-based patterns - you just wouldn't in this scenario - they are designed for conditionally including data during serialization, and (in the second example) disambiguating between "explicitly deserialized to the default" vs "not in the deserialization source":

public bool ShouldSerializeFoo() {return false;}

or

[XmlIgnore]
public bool FooSpecified { get { return false;} set {} }

Upvotes: 2

Related Questions