@@ -57,40 +57,41 @@ public override void Initialize(AnalysisContext context)
5757 /// </summary>
5858 private static void AnalyzeSymbol ( SymbolAnalysisContext context )
5959 {
60- if ( context . Symbol is not IPropertySymbol property )
61- {
62- return ;
63- }
60+ var property = ( IPropertySymbol ) context . Symbol ;
6461
6562 // not raising a violation for when:
6663 // property is overridden because the issue can only be fixed in the base type
6764 // property is the implementation of any interface member
68- if ( property . IsOverride || property . IsImplementationOfAnyInterfaceMember ( ) )
65+ if ( property . IsOverride || GetRule ( property ) is not DiagnosticDescriptor descriptor || property . IsImplementationOfAnyInterfaceMember ( ) )
6966 {
7067 return ;
7168 }
7269
7370 Debug . Assert ( context . Options . MatchesConfiguredVisibility ( MakeMoreAccessibleRule , property , context . Compilation ) == context . Options . MatchesConfiguredVisibility ( AddGetterRule , property , context . Compilation ) ) ;
71+ Debug . Assert ( descriptor == MakeMoreAccessibleRule || descriptor == AddGetterRule ) ;
7472
73+ // Only analyze externally visible properties by default
74+ if ( context . Options . MatchesConfiguredVisibility ( descriptor , property , context . Compilation ) )
75+ {
76+ context . ReportDiagnostic ( property . CreateDiagnostic ( descriptor , property . Name ) ) ;
77+ }
78+ }
79+
80+ private static DiagnosticDescriptor ? GetRule ( IPropertySymbol property )
81+ {
7582 // We handled the non-CA1044 cases earlier. Now, we handle CA1044 cases
7683 // If there is no getter then it is not accessible
7784 if ( property . IsWriteOnly )
7885 {
79- // Only analyze externally visible properties by default
80- if ( context . Options . MatchesConfiguredVisibility ( AddGetterRule , property , context . Compilation ) )
81- {
82- context . ReportDiagnostic ( property . CreateDiagnostic ( AddGetterRule , property . Name ) ) ;
83- }
86+ return AddGetterRule ;
8487 }
8588 // Otherwise if there is a setter, check for its relative accessibility
8689 else if ( ! property . IsReadOnly && ( property . GetMethod ! . DeclaredAccessibility < property . SetMethod ! . DeclaredAccessibility ) )
8790 {
88- // Only analyze externally visible properties by default
89- if ( context . Options . MatchesConfiguredVisibility ( MakeMoreAccessibleRule , property , context . Compilation ) )
90- {
91- context . ReportDiagnostic ( property . CreateDiagnostic ( MakeMoreAccessibleRule , property . Name ) ) ;
92- }
91+ return MakeMoreAccessibleRule ;
9392 }
93+
94+ return null ;
9495 }
9596 }
9697}
0 commit comments