Exemple #1
0
        // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
        private static void BuildListReport(ListReport listReport, string path, IErrorsCollection errorsCollection, Translator translator, int depth, IExecutionOptions executionOptions)
        {
            if (depth > executionOptions.MaxDepth)
            {
                throw new MaxDepthExceededException(executionOptions.MaxDepth);
            }

            if (errorsCollection.IsEmpty)
            {
                return;
            }

            if (errorsCollection.Errors.Any())
            {
                listReport.AddRange(errorsCollection.Errors
                                    .Select(m => string.IsNullOrWhiteSpace(path)
                        ? translator(m)
                        : $"{path}: {translator(m)}")
                                    .Distinct()
                                    .ToList()
                                    );
            }

            foreach (var memberPair in errorsCollection.Members)
            {
                var currentPath = string.IsNullOrEmpty(path) ? string.Empty : $"{path}.";

                BuildListReport(listReport, $"{currentPath}{memberPair.Key}", memberPair.Value, translator, depth + 1, executionOptions);
            }
        }