开发者

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

开发者 https://www.devze.com 2023-02-07 04:04 出处:网络
I have generated classes from XSD using the \"XSD.exe /c\" comma开发者_JAVA百科nd line. Partial classes were generated, so I \"completed\" them by adding classes with the same name, which allowed me t

I have generated classes from XSD using the "XSD.exe /c" comma开发者_JAVA百科nd 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


[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 {} }
0

精彩评论

暂无评论...
验证码 换一张
取 消