File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,16 @@ public override void Initialize(AnalysisContext context)
4040
4141 Location ? location = default ;
4242
43+ static bool IsDDICode ( SyntaxNode node , SemanticModel semantic )
44+ {
45+ if ( node . Ancestors ( ) . OfType < MethodDeclarationSyntax > ( ) . FirstOrDefault ( ) is { } method &&
46+ semantic . GetDeclaredSymbol ( method ) is { } declaration &&
47+ declaration . GetAttributes ( ) . Any ( attr => attr . AttributeClass ? . Name == "DDIAddServicesAttribute" ) )
48+ return true ;
49+
50+ return false ;
51+ }
52+
4353 startContext . RegisterSemanticModelAction ( semanticContext =>
4454 {
4555 var semantic = semanticContext . SemanticModel ;
@@ -48,9 +58,8 @@ public override void Initialize(AnalysisContext context)
4858 . DescendantNodes ( )
4959 . OfType < InvocationExpressionSyntax > ( )
5060 . Select ( invocation => new { Invocation = invocation , semantic . GetSymbolInfo ( invocation , semanticContext . CancellationToken ) . Symbol } )
51- // We don't consider invocations from methods that have the DDIAddServicesAttribute as user-provided, since we do that
52- // in our type/regex overloads. Users need to invoke those methods in turn.
53- . Where ( x => x . Symbol is IMethodSymbol method && ! method . GetAttributes ( ) . Any ( attr => attr . AttributeClass ? . Name == "DDIAddServicesAttribute" ) )
61+ // It has to be user-provided code, not our own extensions/overloads.
62+ . Where ( x => ! IsDDICode ( x . Invocation , semantic ) )
5463 . Select ( x => new { x . Invocation , Method = ( IMethodSymbol ) x . Symbol ! } ) ;
5564
5665 bool IsServiceCollectionExtension ( IMethodSymbol method ) => method . IsExtensionMethod &&
You can’t perform that action at this time.
0 commit comments