I have some public members I don't want to be serialized, was wondering if there is an attribute for it?
views:
118answers:
5
+2
A:
Use XmlIgnoreAttribute to do it statically, as others advised you.
You can also do it dynamically. Suppose you have a serializable property Name. Then the following:
[XmlIgnore]
public bool NameSpecified {
get {
// your logic here
}
}
If this special property getter returns true, Name will be included in the output XML document, otherwise, it won't be included. NameSpecified itself is marked with [XmlIgnore] because you obviously don't want to include it.
azheglov
2009-10-22 18:31:52
A:
Following on from Azheglov's comment regarding the "Specified" suffix, the DefaultValue
attribute is also considered when serializing, and a value won't be serialized at all if it is the default.
Markie
2009-10-23 15:18:40