11using System ;
22using System . Linq ;
33using Microsoft . CodeAnalysis ;
4+ using ServiceScan . SourceGenerator . Extensions ;
45using ServiceScan . SourceGenerator . Model ;
56using static ServiceScan . SourceGenerator . DiagnosticDescriptors ;
67
@@ -16,14 +17,12 @@ public partial class DependencyInjectionGenerator
1617 if ( ! method . IsPartialDefinition )
1718 return Diagnostic . Create ( NotPartialDefinition , method . Locations [ 0 ] ) ;
1819
19- var attributeData = context . Attributes . Select ( a => AttributeModel . Create ( a , method ) ) . ToArray ( ) ;
20+ var position = context . TargetNode . SpanStart ;
21+ var attributeData = context . Attributes . Select ( a => AttributeModel . Create ( a , method , context . SemanticModel ) ) . ToArray ( ) ;
2022 var hasCustomHandlers = attributeData . Any ( a => a . CustomHandler != null ) ;
2123
22- for ( var i = 0 ; i < context . Attributes . Length ; i ++ )
24+ foreach ( var attribute in attributeData )
2325 {
24- var attribute = AttributeModel . Create ( context . Attributes [ i ] , method ) ;
25- attributeData [ i ] = attribute ;
26-
2726 if ( ! attribute . HasSearchCriteria )
2827 return Diagnostic . Create ( MissingSearchCriteria , attribute . Location ) ;
2928
@@ -35,8 +34,7 @@ public partial class DependencyInjectionGenerator
3534
3635 if ( attribute . KeySelector != null )
3736 {
38- var keySelectorMethod = method . ContainingType . GetMembers ( ) . OfType < IMethodSymbol > ( )
39- . FirstOrDefault ( m => m . IsStatic && m . Name == attribute . KeySelector ) ;
37+ var keySelectorMethod = method . ContainingType . GetMethod ( attribute . KeySelector , context . SemanticModel , position , isStatic : true ) ;
4038
4139 if ( keySelectorMethod is not null )
4240 {
@@ -53,8 +51,7 @@ public partial class DependencyInjectionGenerator
5351
5452 if ( attribute . CustomHandler != null )
5553 {
56- var customHandlerMethod = method . ContainingType . GetMembers ( ) . OfType < IMethodSymbol > ( )
57- . FirstOrDefault ( m => m . Name == attribute . CustomHandler ) ;
54+ var customHandlerMethod = method . ContainingType . GetMethod ( attribute . CustomHandler , context . SemanticModel , position ) ;
5855
5956 if ( customHandlerMethod != null )
6057 {
@@ -80,7 +77,7 @@ public partial class DependencyInjectionGenerator
8077 }
8178 }
8279
83- if ( attributeData [ i ] . HasErrors )
80+ if ( attribute . HasErrors )
8481 return null ;
8582 }
8683
0 commit comments