Beispiel #1
0
        /// <summary>
        /// Executes the compilation end actions.
        /// </summary>
        /// <param name="actions"><see cref="AnalyzerActions"/> whose compilation end actions are to be executed.</param>
        /// <param name="compilation">Compilation to be used in the analysis.</param>
        /// <param name="analyzerOptions">Analyzer options.</param>
        /// <param name="addDiagnostic">Delegate to add diagnostics.</param>
        /// <param name="continueOnAnalyzerException">Predicate to decide if exceptions from the action should be handled or not.</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        public static void ExecuteCompilationEndActions(
            AnalyzerActions actions,
            Compilation compilation,
            AnalyzerOptions analyzerOptions,
            Action <Diagnostic> addDiagnostic,
            Func <Exception, DiagnosticAnalyzer, bool> continueOnAnalyzerException,
            CancellationToken cancellationToken)
        {
            VerifyArguments(compilation, actions, analyzerOptions, addDiagnostic, continueOnAnalyzerException);

            HostCompilationStartAnalysisScope compilationScope = new HostCompilationStartAnalysisScope(new HostSessionStartAnalysisScope());

            foreach (var endAction in actions.CompilationEndActions)
            {
                cancellationToken.ThrowIfCancellationRequested();
                ExecuteAndCatchIfThrows(endAction.Analyzer, addDiagnostic, continueOnAnalyzerException, () =>
                {
                    var context = new CompilationEndAnalysisContext(compilation, analyzerOptions, addDiagnostic, cancellationToken);
                    endAction.Action(context);
                }, cancellationToken);
            }
        }
Beispiel #2
0
            public static void AnalyzeCompilation(CompilationEndAnalysisContext context)
            {
                var diagnostics = context.Compilation.GetDeclarationDiagnostics(cancellationToken: context.CancellationToken);

                ReportDiagnostics(diagnostics, context.ReportDiagnostic, location => !IsSourceLocation(location));
            }