You can use XmlIgnoreAttribute with the <FieldName>Specified template to throw an exception if the property is left blank or null. During serialization, the NameSpecified property will be checked to determine whether this field should be displayed, so if Name properties are left blank or empty, an exception is thrown.
class Person { [XmlElement("name")] string Name { get; set; } [XmlIgnore] bool NameSpecified { get { if( String.IsNullOrEmpty(Name)) throw new AgrumentException(...); return true; } } }
user3443886
source share