@@ -100,28 +100,29 @@ public ReadOnlyPropertyAssignmentInspection(IDeclarationFinderProvider declarati
100100
101101 protected override bool IsResultReference ( IdentifierReference reference , DeclarationFinder finder )
102102 {
103- if ( ! reference . Declaration . DeclarationType . HasFlag ( DeclarationType . Property )
104- //Ignore expressions found within Property declaration contexts
105- || reference . Declaration . Context . Contains ( reference . Context ) )
103+ if ( ! reference . Declaration . DeclarationType . HasFlag ( DeclarationType . Property ) )
106104 {
107105 return false ;
108106 }
109107
110- var propertyDeclarations = finder . MatchName ( reference . Declaration . IdentifierName )
111- . Where ( d => d . DeclarationType . HasFlag ( DeclarationType . Property )
112- && d . QualifiedModuleName == reference . QualifiedModuleName ) ;
113-
114- if ( reference . IsSetAssignment )
108+ //Ignore assignment expressions found within Property Get declaration contexts
109+ if ( ! IsReadOnlyPropertyReference ( reference , finder )
110+ || ( reference . Declaration . Context ? . Contains ( reference . Context ) ?? false ) )
115111 {
116- return ! propertyDeclarations . Any ( pd => pd . DeclarationType . HasFlag ( DeclarationType . PropertySet ) ) ;
112+ return false ;
117113 }
118114
119- if ( reference . IsAssignment && ! reference . IsSetAssignment )
120- {
121- return ! propertyDeclarations . Any ( pd => pd . DeclarationType . HasFlag ( DeclarationType . PropertyLet ) ) ;
122- }
115+ return reference . IsAssignment ;
116+ }
117+
118+ private bool IsReadOnlyPropertyReference ( IdentifierReference reference , DeclarationFinder finder )
119+ {
120+ var propertyDeclarations = finder . MatchName ( reference . Declaration . IdentifierName )
121+ . Where ( d => d . DeclarationType . HasFlag ( DeclarationType . Property )
122+ && d . QualifiedModuleName == reference . QualifiedModuleName ) ;
123123
124- return false ;
124+ return propertyDeclarations . Count ( ) == 1
125+ && propertyDeclarations . First ( ) . DeclarationType . HasFlag ( DeclarationType . PropertyGet ) ;
125126 }
126127
127128 protected override string ResultDescription ( IdentifierReference reference )
@@ -131,4 +132,4 @@ protected override string ResultDescription(IdentifierReference reference)
131132 InspectionResults . ReadOnlyPropertyAssignmentInspection , identifierName ) ;
132133 }
133134 }
134- }
135+ }
0 commit comments