// Internal for unit testing
        internal CompilationResult GetCompilationFailedResult(RelativeFileInfo file, IEnumerable<RazorError> errors)
        {
            // If a SourceLocation does not specify a file path, assume it is produced
            // from parsing the current file.
            var messageGroups = errors
                .GroupBy(razorError =>
                razorError.Location.FilePath ?? file.RelativePath,
                StringComparer.Ordinal);

            var failures = new List<RazorCompilationFailure>();
            foreach (var group in messageGroups)
            {
                var filePath = group.Key;
                var fileContent = ReadFileContentsSafely(filePath);
                var compilationFailure = new RazorCompilationFailure(
                    filePath,
                    fileContent,
                    group.Select(parserError => new RazorCompilationMessage(parserError, filePath)));
                failures.Add(compilationFailure);
            }

            return CompilationResult.Failed(failures);
        }
Ejemplo n.º 2
0
        // Internal for unit testing
        internal CompilationResult GetCompilationFailedResult(RelativeFileInfo file, IEnumerable <RazorError> errors)
        {
            // If a SourceLocation does not specify a file path, assume it is produced
            // from parsing the current file.
            var messageGroups = errors
                                .GroupBy(razorError =>
                                         razorError.Location.FilePath ?? file.RelativePath,
                                         StringComparer.Ordinal);

            var failures = new List <RazorCompilationFailure>();

            foreach (var group in messageGroups)
            {
                var filePath           = group.Key;
                var fileContent        = ReadFileContentsSafely(filePath);
                var compilationFailure = new RazorCompilationFailure(
                    filePath,
                    fileContent,
                    group.Select(parserError => new RazorCompilationMessage(parserError, filePath)));
                failures.Add(compilationFailure);
            }

            return(CompilationResult.Failed(failures));
        }