Exemple #1
0
        public static string CombineResults(ValidationResult[] results)
        {
            if (results == null) throw new ArgumentNullException(nameof(results));

            if (results.Length == 0)
            {
                return string.Empty;
            }

            var buffer = new StringBuilder();

            foreach (var result in results)
            {
                if (result != ValidationResult.Success)
                {
                    if (buffer.Length > 0)
                    {
                        buffer.Append(@", ");
                    }
                    buffer.Append(result.ErrorMessage);
                }
            }

            return buffer.ToString();
        }
Exemple #2
0
        public static ValidationResult[] GetViolated(ValidationResult[] results)
        {
            if (results == null) throw new ArgumentNullException(nameof(results));
            if (results.Length == 0) throw new ArgumentOutOfRangeException(nameof(results));

            var totalViolations = 0;
            foreach (var result in results)
            {
                if (result != ValidationResult.Success)
                {
                    totalViolations++;
                }
            }
            if (totalViolations > 0)
            {
                var violations = new ValidationResult[totalViolations];

                var index = 0;
                foreach (var result in results)
                {
                    if (result != ValidationResult.Success)
                    {
                        violations[index++] = result;
                    }
                }

                return violations;
            }
            return new ValidationResult[0];
        }