You already found one solution:
Another one would be to add another property to control the
serialization of your property:
public class MyClass
{
[XmlIgnore]
public bool MyPropSpecified;
public bool MyProp;
}
The XmlSerializer will look for the fields/properties with have the same
name stem as others and end in "Specified" to decide whether or not to
add the element.
HTH,
Christoph Schittko
MVP XML
http://weblogs.asp.net/cschittko -----Original Message-----
From: Doug Holton [mailto:in****@spam.here]
Posted At: Friday, December 10, 2004 4:09 PM
Posted To: microsoft.public.dotnet.xml
Conversation: don't serialize boolean property if false?
Subject: Re: don't serialize boolean property if false?
Doug Holton wrote:
I've got a boolean class property that is almost always false.
How can I specify that a class property should not be included in
the xml serializer output if it is false?
I'm using [XmlAttribute]. [XmlIgnore] will never print it if it is
true either.
I found it:
[System.ComponentModel.DefaultValue(false)]