XML deserialization - throwing custom errors

So I have the following method:\[code\]private int? myIntField[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]public int? IntField{ get { return this.myIntField; } set { this.myIntField= value; } }\[/code\]Now, I am deserializing xml from a post, if for whatever reason I am getting a string, such as "here is the int field: 55444" instead of 55444, the error I get in response is: \[code\]Input string was not in a correct format.\[/code\] which isn't very specific, especially considering I will have more than one int field I need to verify.Originally, I was planning something like this:\[code\]private string myIntField[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]public int? IntField{ get { return this.myIntField.CheckValue(); } set { this.myIntField= value; } }\[/code\]Where CheckValue performs a \[code\]try-parse\[/code\] to an Int32, and if it fails it returns a null and adds an error to a list. However, I can't seem to nail this set-up for the generated classes. Is there I way I can throw a specific error if I am getting strings in place of ints, DateTimes, etc?
 
Back
Top