Beispiel #1
0
        internal static async Task <CommandResult> FixAsync(
            ProjectOrSolution projectOrSolution,
            IEnumerable <string> analyzerAssemblies,
            CodeFixerOptions codeFixerOptions,
            IFormatProvider formatProvider      = null,
            CancellationToken cancellationToken = default)
        {
            if (projectOrSolution.IsProject)
            {
                Project project = projectOrSolution.AsProject();

                Solution solution = project.Solution;

                var codeFixer = new CodeFixer(solution, SyntaxFactsServiceFactory.Instance, analyzerAssemblies: analyzerAssemblies, formatProvider: formatProvider, options: codeFixerOptions);

                WriteLine($"Fix '{project.Name}'", ConsoleColor.Cyan, Verbosity.Minimal);

                await codeFixer.FixProjectAsync(project, cancellationToken);
            }
            else
            {
                Solution solution = projectOrSolution.AsSolution();

                var codeFixer = new CodeFixer(solution, SyntaxFactsServiceFactory.Instance, analyzerAssemblies: analyzerAssemblies, options: codeFixerOptions);

                await codeFixer.FixSolutionAsync(cancellationToken);
            }

            return(CommandResult.Success);
        }
Beispiel #2
0
        internal static async Task <CommandResult> FixAsync(
            ProjectOrSolution projectOrSolution,
            IEnumerable <AnalyzerAssembly> analyzerAssemblies,
            CodeFixerOptions codeFixerOptions,
            IFormatProvider formatProvider      = null,
            CancellationToken cancellationToken = default)
        {
            if (projectOrSolution.IsProject)
            {
                Project project = projectOrSolution.AsProject();

                Solution solution = project.Solution;

                CodeFixer codeFixer = GetCodeFixer(solution);

                WriteLine($"Fix '{project.Name}'", ConsoleColor.Cyan, Verbosity.Minimal);

                Stopwatch stopwatch = Stopwatch.StartNew();

                await codeFixer.FixProjectAsync(project, cancellationToken);

                stopwatch.Stop();

                WriteLine($"Done fixing project '{project.FilePath}' in {stopwatch.Elapsed:mm\\:ss\\.ff}", Verbosity.Minimal);
            }
            else
            {
                Solution solution = projectOrSolution.AsSolution();

                CodeFixer codeFixer = GetCodeFixer(solution);

                await codeFixer.FixSolutionAsync(cancellationToken);
            }

            return(CommandResult.Success);

            CodeFixer GetCodeFixer(Solution solution)
            {
                return(new CodeFixer(
                           solution,
                           analyzerAssemblies: analyzerAssemblies,
                           formatProvider: formatProvider,
                           options: codeFixerOptions));
            }
        }
Beispiel #3
0
        internal static async Task <CommandResult> FixAsync(
            ProjectOrSolution projectOrSolution,
            IEnumerable <string> analyzerAssemblies,
            CodeFixerOptions codeFixerOptions,
            IFormatProvider formatProvider      = null,
            CancellationToken cancellationToken = default)
        {
            if (projectOrSolution.IsProject)
            {
                Project project = projectOrSolution.AsProject();

                Solution solution = project.Solution;

                CodeFixer codeFixer = GetCodeFixer(solution);

                WriteLine($"Fix '{project.Name}'", ConsoleColor.Cyan, Verbosity.Minimal);

                await codeFixer.FixProjectAsync(project, cancellationToken);
            }
            else
            {
                Solution solution = projectOrSolution.AsSolution();

                CodeFixer codeFixer = GetCodeFixer(solution);

                await codeFixer.FixSolutionAsync(cancellationToken);
            }

            return(CommandResult.Success);

            CodeFixer GetCodeFixer(Solution solution)
            {
                return(new CodeFixer(
                           solution,
                           analyzerAssemblies: AnalyzerAssemblyLoader.LoadFiles(analyzerAssemblies),
                           formatProvider: formatProvider,
                           options: codeFixerOptions));
            }
        }