XmlSerializer supports the ShouldSerialize{Foo}()
pattern, so you can add a method:
public bool ShouldSerializeID() {return ID.HasValue;}
There is also the {Foo}Specified
pattern – not sure if XmlSerializer supports that one.
More Related Contents:
- Serializing private member data
- XmlSerializer – There was an error reflecting type
- Error Deserializing Xml to Object – xmlns=” was not expected
- Deserializing XML File with multiple element attributes – attributes are not deserializing
- How do you use XMLSerialize for Enum typed properties in c#?
- How to deserialize an array of values with a fixed schema to a strongly typed data class?
- Read XML Attribute using XmlDocument
- XML serialization of interface property
- How would you compare two XML Documents?
- Format a date in XML via XSLT
- Escape invalid XML characters in C#
- XML Serialization and Inherited Types
- How does WCF deserialization instantiate objects without calling a constructor?
- How to read attribute value from XmlNode in C#?
- how to use XPath with XDocument?
- How to prevent blank xmlns attributes in output from .NET’s XmlDocument?
- Is it possible to do .NET binary serialization of an object when you don’t have the source code of the class?
- XML Deserialization of collection property with code defaults
- C# automatic property deserialization of JSON
- How can I serialize internal classes using XmlSerializer?
- Cannot deserialize JSON array into type – Json.NET
- Why are interfaces not [Serializable]?
- End of Stream encountered before parsing was completed?
- How to save shapes which I draw on a Panel as binary
- Convert an object to an XML string
- Checking if an object is a number
- How to analyse contents of binary serialization stream?
- Trouble serializing and deserializing multiple objects
- How can I remove empty xmlns attribute from node created by XElement
- Remove empty string properties from json serialized object