private void HandleDynamicValidatorException(IDynamicValidatorException e) { if (Column == null) { // IDynamicValidatorException only applies to column exceptions return; } List <string> columnNames = GetValidationColumnNames(Column); foreach (string name in columnNames) { // see if the exception wraps any child exceptions relevant to this column Exception inner; if (e.InnerExceptions.TryGetValue(name, out inner)) { // Stop as soon as we find the first exception. ValidationException = inner; return; } } }
/// <summary> /// Called when an exception happens. Typically, this sets the ValidationException /// </summary> /// <param name="exception">The exception</param> protected virtual void ValidateException(Exception exception) { if (exception == null) { return; } ValidationException = null; // IDynamicValidatorExceptions are used by LinqDataSource to wrap exceptions caused by problems // with setting model properties (columns), such as exceptions thrown from the OnXYZChanging // methods IDynamicValidatorException e = exception as IDynamicValidatorException; if (e != null) { HandleDynamicValidatorException(e); } else { // It's not a column specific exception. e.g. it could be coming from // OnValidate (DLinq), or could be caused by a database error. // We only want to use it if it's a ValidationException, otherwise we // could end up displaying sensitive database errors to the end user if (Column == null && exception is ValidationException) { if (exception.InnerException == null) { ValidationException = exception; } else { ValidationException = exception.InnerException; } } } }
private void HandleDynamicValidatorException(IDynamicValidatorException e) { if (Column == null) { // IDynamicValidatorException only applies to column exceptions return; } List<string> columnNames = GetValidationColumnNames(Column); foreach (string name in columnNames) { // see if the exception wraps any child exceptions relevant to this column Exception inner; if (e.InnerExceptions.TryGetValue(name, out inner)) { // Stop as soon as we find the first exception. ValidationException = inner; return; } } }