How to avoid serialization default values?

There is such thing as Specified property. I can't find msdn documentation on it but this article should be helpful. Basically you have to write something like this:

//this property would not be serialized if it contains String.Empty value
public string PropertyName   {   get; set;  }


[XmlIgnore]
public bool PropertyNameSpecified
{
    get  { return PropertyName != String.Empty; }
}

Ok I found it myself. It is [DefaultValue(false)]. If I mark some property with this attr then it will be serialized only if is different than value in ().

System.ComponentModel.DefaultValueAttribute

Tags:

C#