I am using DefaultValue
attribute for the proper PropertyGrid
behavior (it shows values different from default in bold). Now if I want to serialize
As long as you don't need attributes in your Xml, if you use the DataContractSerializer instead you will get the behavior you desire.
[DataContract]
public class Test
{
[DataMember]
[DefaultValue(false)]
public bool AllowNegative { get; set; }
}
void Main()
{
var sb2 = new StringBuilder();
var dcs = new DataContractSerializer(typeof(Test));
using(var writer = XmlWriter.Create(sb2))
{
dcs.WriteObject(writer, new Test());
}
Console.WriteLine(sb2.ToString());
}
produces (minus namespaces etc)
false