1- using System . Collections . Immutable ;
1+ using System ;
2+ using System . Collections . Immutable ;
23using System . Diagnostics . CodeAnalysis ;
4+ using System . Reflection ;
5+ using System . Threading ;
36using CodeContractNullability . ExternalAnnotations ;
47using CodeContractNullability . NullabilityAttributes ;
58using CodeContractNullability . SymbolAnalysis ;
@@ -19,6 +22,19 @@ public abstract class BaseAnalyzer : DiagnosticAnalyzer
1922 public const string DisableReportOnNullableValueTypesDiagnosticId = "XNUL" ;
2023
2124 protected const string Category = "Nullability" ;
25+
26+ [ NotNull ]
27+ [ ItemCanBeNull ]
28+ private static readonly Lazy < MethodInfo > LazyEnableConcurrentExecutionMethod =
29+ new Lazy < MethodInfo > ( ( ) => typeof ( AnalysisContext ) . GetMethod ( "EnableConcurrentExecution" ) ,
30+ LazyThreadSafetyMode . PublicationOnly ) ;
31+
32+ [ NotNull ]
33+ [ ItemCanBeNull ]
34+ private static readonly Lazy < MethodInfo > LazyConfigureGeneratedCodeAnalysisMethod =
35+ new Lazy < MethodInfo > ( ( ) => typeof ( AnalysisContext ) . GetMethod ( "ConfigureGeneratedCodeAnalysis" ) ,
36+ LazyThreadSafetyMode . PublicationOnly ) ;
37+
2238 private readonly bool appliesToItem ;
2339
2440 [ NotNull ]
@@ -89,9 +105,30 @@ public override void Initialize([NotNull] AnalysisContext context)
89105 {
90106 Guard . NotNull ( context , nameof ( context ) ) ;
91107
108+ TryEnableConcurrentExecution ( context ) ;
109+ TrySkipGeneratedCode ( context ) ;
110+
92111 context . RegisterCompilationStartAction ( StartAnalyzeCompilation ) ;
93112 }
94113
114+ private void TryEnableConcurrentExecution ( [ NotNull ] AnalysisContext context )
115+ {
116+ MethodInfo method = LazyEnableConcurrentExecutionMethod . Value ;
117+ if ( method != null )
118+ {
119+ method . Invoke ( context , new object [ 0 ] ) ;
120+ }
121+ }
122+
123+ private void TrySkipGeneratedCode ( [ NotNull ] AnalysisContext context )
124+ {
125+ MethodInfo method = LazyConfigureGeneratedCodeAnalysisMethod . Value ;
126+ if ( method != null )
127+ {
128+ method . Invoke ( context , new object [ ] { 0 } ) ;
129+ }
130+ }
131+
95132 private void StartAnalyzeCompilation ( [ NotNull ] CompilationStartAnalysisContext context )
96133 {
97134 Guard . NotNull ( context , nameof ( context ) ) ;
0 commit comments