public void AddError(CustomValidationError validationError) { if (ValidationErrors == null) { ValidationErrors = new Dictionary <string, IEnumerable <string> >(); } var fieldName = validationError.Field ?? "Generic"; if (ValidationErrors.ContainsKey(fieldName)) { var value = ValidationErrors[fieldName]; var enumerable = value as string[] ?? value.ToArray(); if (value != null && enumerable.Any()) { enumerable.Append(validationError.Message); } else { ValidationErrors[fieldName] = new List <string> { validationError.Message } }; } else { ValidationErrors[fieldName] = new List <string> { validationError.Message }; } }
public CustomException(CustomValidationError validationError) { Error = new CustomError(new List <CustomValidationError> { validationError }); }