@@ -40,25 +40,25 @@ public class VSMEF001PropertyMustHaveSetter : DiagnosticAnalyzer
4040 public override void Initialize ( AnalysisContext context )
4141 {
4242 context . EnableConcurrentExecution ( ) ;
43- context . ConfigureGeneratedCodeAnalysis ( GeneratedCodeAnalysisFlags . ReportDiagnostics ) ;
43+ context . ConfigureGeneratedCodeAnalysis ( GeneratedCodeAnalysisFlags . Analyze | GeneratedCodeAnalysisFlags . ReportDiagnostics ) ;
4444
45- context . RegisterCompilationStartAction ( compilationContext =>
45+ context . RegisterCompilationStartAction ( context =>
4646 {
4747 // Only scan further if the compilation references the assemblies that define the attributes we'll be looking for.
48- if ( compilationContext . Compilation . ReferencedAssemblyNames . Any ( i => string . Equals ( i . Name , "System.ComponentModel.Composition" , StringComparison . OrdinalIgnoreCase ) || string . Equals ( i . Name , "System.Composition.AttributedModel" , StringComparison . OrdinalIgnoreCase ) ) )
48+ if ( context . Compilation . ReferencedAssemblyNames . Any ( i => string . Equals ( i . Name , "System.ComponentModel.Composition" , StringComparison . OrdinalIgnoreCase ) || string . Equals ( i . Name , "System.Composition.AttributedModel" , StringComparison . OrdinalIgnoreCase ) ) )
4949 {
50- INamedTypeSymbol ? mefV1ImportAttribute = compilationContext . Compilation . GetTypeByMetadataName ( "System.ComponentModel.Composition.ImportAttribute" ) ;
51- INamedTypeSymbol ? mefV2ImportAttribute = compilationContext . Compilation . GetTypeByMetadataName ( "System.Composition.ImportAttribute" ) ;
52- compilationContext . RegisterSymbolAction (
53- symbolContext => this . AnalyzePropertyDeclaration ( symbolContext , mefV1ImportAttribute , mefV2ImportAttribute ) ,
50+ INamedTypeSymbol ? mefV1ImportAttribute = context . Compilation . GetTypeByMetadataName ( "System.ComponentModel.Composition.ImportAttribute" ) ;
51+ INamedTypeSymbol ? mefV2ImportAttribute = context . Compilation . GetTypeByMetadataName ( "System.Composition.ImportAttribute" ) ;
52+ context . RegisterSymbolAction (
53+ context => AnalyzePropertyDeclaration ( context , mefV1ImportAttribute , mefV2ImportAttribute ) ,
5454 SymbolKind . Property ) ;
5555 }
5656 } ) ;
5757 }
5858
59- private void AnalyzePropertyDeclaration ( SymbolAnalysisContext symbolContext , INamedTypeSymbol mefV1ImportAttribute , INamedTypeSymbol mefV2ImportAttribute )
59+ private static void AnalyzePropertyDeclaration ( SymbolAnalysisContext context , INamedTypeSymbol mefV1ImportAttribute , INamedTypeSymbol mefV2ImportAttribute )
6060 {
61- var property = ( IPropertySymbol ) symbolContext . Symbol ;
61+ var property = ( IPropertySymbol ) context . Symbol ;
6262
6363 // If this property defines a setter, they aren't a candidate for a diagnostic.
6464 if ( property . SetMethod is object )
@@ -79,7 +79,7 @@ private void AnalyzePropertyDeclaration(SymbolAnalysisContext symbolContext, INa
7979 if ( Equals ( attributeData . AttributeClass , mefV1ImportAttribute ) ||
8080 Equals ( attributeData . AttributeClass , mefV2ImportAttribute ) )
8181 {
82- symbolContext . ReportDiagnostic ( Diagnostic . Create ( Descriptor , location ) ) ;
82+ context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , location ) ) ;
8383 }
8484 }
8585 }
0 commit comments