/// <summary> /// recursively add validation records from inner exceptions. Deserialization errors get more specific the further in you go /// </summary> /// <param name="e"></param> /// <param name="xpath"></param> /// <param name="type"></param> /// <param name="result"></param> private void AddValidationRecordRecursive(Exception e, string xpath, ValidationRecord.ValidationType type, ValidateResult result) { //if the inner exception is null (this is the inner most error) then include the stacktrace //if there was an error with the format of the data then the stacktrace will show us which class it is in AddValidationRecord(type, result, xpath, string.Format("{0}{1}", e.Message, e.InnerException != null ? "" : (", StackTrace: " + e.StackTrace))); if (e.InnerException != null) { AddValidationRecordRecursive(e.InnerException, xpath, type, result); } }
public void AddValidationRecord(ValidationRecord.ValidationType vType, ValidateResult result, string xpath, string message) { ValidationRecord record = _validationRecords.Find(delegate(ValidationRecord vr) { return(vr.Message.Equals(message, StringComparison.CurrentCultureIgnoreCase) && vr.Type.ToString().Equals(vType.ToString(), StringComparison.CurrentCultureIgnoreCase) && vr.ValidateResult.ToString().Equals(result.ToString(), StringComparison.CurrentCultureIgnoreCase) && vr.XPath.Equals(xpath, StringComparison.CurrentCultureIgnoreCase)); }); if (record == null) { ValidationRecord vRec = new ValidationRecord(vType, result, xpath, message); _validationRecords.Add(vRec); } }