@@ -25,21 +25,20 @@ private static void Handle(SyntaxNodeAnalysisContext context)
2525 if ( ! context . IsExcludedFromAnalysis ( ) &&
2626 context . Node is AttributeSyntax attribute &&
2727 context . ContainingSymbol is IMethodSymbol method &&
28- attribute . TryFirstAncestor < MethodDeclarationSyntax > ( out var methodDeclaration ) &&
28+ attribute . TryFirstAncestor ( out MethodDeclarationSyntax methodDeclaration ) &&
2929 TryGetTemplate ( attribute , context , out var template ) )
3030 {
3131 foreach ( var component in template . Path )
3232 {
33- if ( TryGetParameterName ( component . Text , out var name ) )
33+ if ( component . Parameter is TemplateParameter parameter )
3434 {
35- if ( method . Parameters . TrySingle ( x => IsFromRoute ( x ) , out var single ) &&
36- single . Name != name )
35+ if ( method . Parameters . TryFirst ( x => IsFromRoute ( x ) && x . Name != parameter . Name . Text , out var single ) )
3736 {
3837 context . ReportDiagnostic (
3938 Diagnostic . Create (
4039 ASP001ParameterName . Descriptor ,
4140 single . Locations . Single ( ) ,
42- ImmutableDictionary < string , string > . Empty . Add ( nameof ( NameSyntax ) , name ) ) ) ;
41+ ImmutableDictionary < string , string > . Empty . Add ( nameof ( NameSyntax ) , parameter . Name . Text ) ) ) ;
4342 }
4443
4544 if ( ! method . Parameters . TryFirst ( x => IsFromRoute ( x ) , out _ ) )
@@ -54,51 +53,6 @@ context.ContainingSymbol is IMethodSymbol method &&
5453 }
5554 }
5655
57- private static bool TryGetParameterName ( string text , out string name )
58- {
59- var start = text . IndexOf ( '{' ) ;
60- if ( start < 0 ||
61- text . IndexOf ( '}' ) < start ||
62- text . IndexOf ( '{' , start ) > 0 )
63- {
64- name = null ;
65- return false ;
66- }
67-
68- start ++ ;
69- while ( start < text . Length &&
70- text [ start ] == ' ' )
71- {
72- start ++ ;
73- }
74-
75- var end = text . IndexOf ( '}' , start ) ;
76- if ( end < 0 )
77- {
78- name = null ;
79- return false ;
80- }
81-
82- while ( text [ end ] == ' ' )
83- {
84- end -- ;
85- }
86-
87- for ( var i = start ; i < end ; i ++ )
88- {
89- switch ( text [ i ] )
90- {
91- case '?' :
92- case ':' :
93- end = i ;
94- break ;
95- }
96- }
97-
98- name = text . Substring ( start , end - start ) ;
99- return true ;
100- }
101-
10256 private static bool TryGetTemplate ( AttributeSyntax attribute , SyntaxNodeAnalysisContext context , out UrlTemplate template )
10357 {
10458 if ( attribute . ArgumentList is AttributeArgumentListSyntax argumentList &&
0 commit comments