So, I have the following method:
private int? myIntField
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public int? IntField{
get {
return this.myIntField;
}
set {
this.myIntField= value;
}
}
Now, I am deserializing the xml from the message, if for some reason I get a line, for example "here is the int field: 55444" instead of 55444, the error I get in response is: Input string was not in a correct format.which is not very specific, especially considering that I will have more than one int field that I need to check.
I originally planned something like this:
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;
}
}
Where CheckValue runs try-parsein Int32, and if it fails, it returns null and adds the error to the list. However, I cannot cover this setting for the generated classes.
Is there a way to input a specific error if I get strings instead of int, DateTimes, etc.?
source
share