XmlSerializer, "Specified" suffix and IReflect
I will extend answer of Martin Peck.
You can avoid serialization of the fields/properties with "Specified" suffix.
You should define that "*Specified" properties in your class and apply [XmlIgnoreAttribute()]
to them.
Here is an example:
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://yournamespace.com")]
public partial class YourObject
{
private long sessionTimeoutInSecondsField;
private bool sessionTimeoutInSecondsFieldSpecified;
public long sessionTimeoutInSeconds
{
get
{
return this.sessionTimeoutInSecondsField;
}
set
{
this.sessionTimeoutInSecondsField = value;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool sessionTimeoutInSecondsSpecified
{
get
{
return this.sessionTimeoutInSecondsFieldSpecified;
}
set
{
this.sessionTimeoutInSecondsFieldSpecified = value;
}
}
}
If you want to take control of your xml serialization then you have two options. The first (which might not be appropriate here) it to use the attributes in the System.Xml.Serialization namespace to exclude properties. If you really need to do determine what gets serialized at runtime this might not be the best course of action.
See Attributes That Control XML Serialization
The other way to do this is to implement the IXmlSerializable interface on your class and implement the ReadXml and WriteXml methods. This allows you to take control of exactly how your xml looks. See this question for additional info:
custom xml serialization
However, as mentioned here Mixing custom and basic serialization? once you implement IXmlSerializable you are responsible for all the serialization logic for your type.