I am using XmlSerializer to write and read an object to xml in C#. I currently use the attributes XmlElement
and XmlIgnore
to manipulate the serialization of the object.
If my xml file is missing an xml element that I require, my object still deserializes (xml -> object) just fine. How do I indicate (preferably via Attributes) that a certain field is "required"?
Here is a sample method of what I am using currently:
[XmlElement(ElementName="numberOfWidgets")]
public int NumberThatIsRequired {
set ...;
get ...;
}
My ideal solution would be to add something like an XmlRequired
attribute.
Also, is there a good reference for what Attributes are available to manipulate the behavior of XmlSerializer?