@@ -84,7 +84,7 @@ private static void NamedSymbolAction(SonarSymbolReportingContext context, HashS
8484 var fieldLikeSymbols = new BidirectionalDictionary < ISymbol , SyntaxNode > ( ) ;
8585 if ( GatherSymbols ( namedType , context . Compilation , privateSymbols , removableInternalTypes , fieldLikeSymbols , context )
8686 && privateSymbols . Any ( )
87- && new CSharpSymbolUsageCollector ( context . Compilation , privateSymbols ) is var usageCollector
87+ && new CSharpSymbolUsageCollector ( context . Compilation , AssociatedSymbols ( privateSymbols ) ) is var usageCollector
8888 && VisitDeclaringReferences ( namedType , usageCollector , context , includeGeneratedFile : true ) )
8989 {
9090 foreach ( var diagnostic in DiagnosticsForUnusedPrivateMembers ( usageCollector , privateSymbols , SyntaxConstants . Private , fieldLikeSymbols ) )
@@ -98,6 +98,9 @@ private static void NamedSymbolAction(SonarSymbolReportingContext context, HashS
9898 }
9999 }
100100
101+ private static IEnumerable < ISymbol > AssociatedSymbols ( IEnumerable < ISymbol > privateSymbols ) =>
102+ privateSymbols . Select ( x => x is IMethodSymbol { AssociatedSymbol : IPropertySymbol property } ? property : x ) ;
103+
101104 private static bool GatherSymbols ( INamedTypeSymbol namedType ,
102105 Compilation compilation ,
103106 HashSet < ISymbol > privateSymbols ,
@@ -184,8 +187,8 @@ private static bool IsAccessorUsed(ISymbol symbol, CSharpSymbolUsageCollector us
184187 symbol is IMethodSymbol { } accessor
185188 && accessor . AssociatedSymbol is IPropertySymbol { } property
186189 && usageCollector . PropertyAccess . TryGetValue ( property , out var access )
187- && ( ( access is AccessorAccess . Get or AccessorAccess . Both && accessor . MethodKind == MethodKind . PropertyGet )
188- || ( access is AccessorAccess . Set or AccessorAccess . Both && accessor . MethodKind == MethodKind . PropertySet ) ) ;
190+ && ( ( access . HasFlag ( AccessorAccess . Get ) && accessor . MethodKind == MethodKind . PropertyGet )
191+ || ( access . HasFlag ( AccessorAccess . Set ) && accessor . MethodKind == MethodKind . PropertySet ) ) ;
189192
190193 private static string GetFieldAccessibilityForMessage ( ISymbol symbol ) =>
191194 symbol . DeclaredAccessibility == Accessibility . Private ? SyntaxConstants . Private : "private class" ;
@@ -436,11 +439,12 @@ public override void VisitMethodDeclaration(MethodDeclarationSyntax node)
436439
437440 base . VisitMethodDeclaration ( node ) ;
438441 }
442+
439443 public override void VisitAccessorDeclaration ( AccessorDeclarationSyntax node )
440444 {
441445 if ( node . Modifiers . Any ( SyntaxKind . PrivateKeyword ) )
442446 {
443- ConditionalStore ( GetDeclaredSymbol ( node ) , IsRemovableMember ) ;
447+ ConditionalStore ( GetDeclaredSymbol ( node ) , IsRemovable ) ;
444448 }
445449
446450 base . VisitAccessorDeclaration ( node ) ;
0 commit comments