@@ -102,21 +102,22 @@ public void HandleNamedTypeSymbol(SymbolAnalysisContext context)
102102
103103 // If the namedType has an instance-level CancellationToken property, then instance methods don't need a parameter.
104104 bool checkInstanceMethods = ! CanAccessCancellationTokenProperty ( source : namedType , target : namedType ) ;
105+ Settings settings = this . callingAnalyzer . Settings ;
105106
106107 // Look at each overload method group (including inherited methods).
107108 // If a method group has any eligible async/awaitable methods and none
108109 // of those are cancellable, then we'll report the "most eligible" method.
109110#pragma warning disable IDE0079 // Remove unnecessary suppression. False positive!
110111#pragma warning disable RS1024 // Compare symbols correctly. False positive! We're grouping by the Name not IMethodSymbol.
111112 IEnumerable < IGrouping < string , IMethodSymbol > > methodGroups = GetTypeAndBaseTypes ( namedType )
113+ . Where ( type => type . DeclaredAccessibility > Accessibility . Private || settings . CheckPrivateTypesForCancellation )
112114 . SelectMany ( type => type . GetMembers ( ) )
113115 . OfType < IMethodSymbol > ( )
114116 . Where ( method => checkInstanceMethods || method . IsStatic )
115117 . GroupBy ( m => m . Name , m => m , StringComparer . Ordinal ) ;
116118#pragma warning restore RS1024 // Compare symbols correctly
117119#pragma warning restore IDE0079 // Remove unnecessary suppression
118120
119- Settings settings = this . callingAnalyzer . Settings ;
120121 foreach ( IGrouping < string , IMethodSymbol > methodGroup in methodGroups )
121122 {
122123 List < IMethodSymbol > eligibleMethods = [ ] ;
@@ -302,7 +303,7 @@ private bool CanAccessCancellationTokenProperty(ITypeSymbol source, ITypeSymbol
302303 // per-operation intent. https://devblogs.microsoft.com/dotnet/net-4-cancellation-framework/
303304 && ! m . IsStatic
304305 // If m is an inherited property, we have to use its containing type not target.
305- && m . DeclaredAccessibility >= GetMinimumAccessibility ( tuple . Source , m . ContainingType ) )
306+ && m . DeclaredAccessibility >= GetMinimumAccessibilityToUseTargetMember ( tuple . Source , m . ContainingType ) )
306307 . Cast < IPropertySymbol > ( ) ;
307308 foreach ( IPropertySymbol propertySymbol in publicCancellationProperties )
308309 {
@@ -319,7 +320,7 @@ private bool CanAccessCancellationTokenProperty(ITypeSymbol source, ITypeSymbol
319320 return result ;
320321 }
321322
322- private Accessibility GetMinimumAccessibility ( ITypeSymbol source , ITypeSymbol target )
323+ private Accessibility GetMinimumAccessibilityToUseTargetMember ( ITypeSymbol source , ITypeSymbol target )
323324 {
324325 Accessibility result = Accessibility . Public ;
325326
0 commit comments