예제 #1
0
        /// <summary>
        /// Runs the specified <paramref name="analyzer"/> and returns an <see cref="ImmutableArray{T}"/> of produced <see cref="Diagnostic"/>s.
        /// </summary>
        /// <param name="analyzer"><see cref="DiagnosticAnalyzer"/> to run.</param>
        /// <param name="tree">A <see cref="CSharpSyntaxTree"/> the analysis should be performed on.</param>
        public static Task <ImmutableArray <Diagnostic> > RunAnalyzer(this DiagnosticAnalyzer analyzer, CSharpSyntaxTree?tree)
        {
            CSharpCompilation compilation = RoslynUtilities.CreateBaseCompilation();

            if (tree is not null)
            {
                compilation = compilation.AddSyntaxTrees(tree);
            }

            return(RunAnalyzer(analyzer, compilation));
        }
예제 #2
0
        /// <summary>
        /// Runs the specified <paramref name="analyzer"/> and returns an <see cref="ImmutableArray{T}"/> of produced <see cref="Diagnostic"/>s.
        /// </summary>
        /// <param name="analyzer"><see cref="DiagnosticAnalyzer"/> to run.</param>
        /// <param name="source">A <see cref="string"/> representing a <see cref="CSharpSyntaxTree"/> the analysis should be performed on.</param>
        public static Task <ImmutableArray <Diagnostic> > RunAnalyzer(this DiagnosticAnalyzer analyzer, string?source)
        {
            CSharpCompilation compilation = RoslynUtilities.CreateBaseCompilation();

            if (!string.IsNullOrWhiteSpace(source))
            {
                compilation = compilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(source !));
            }

            return(RunAnalyzer(analyzer, compilation));
        }