@@ -66,7 +66,7 @@ context.ContainingSymbol is IMethodSymbol method &&
6666
6767 foreach ( var pair in pairs )
6868 {
69- if ( TryGetCorrectParameterType ( pair , out var typeName ) &&
69+ if ( HasWrongType ( pair , out var typeName ) &&
7070 methodDeclaration . TryFindParameter ( pair . Method ? . Name , out parameterSyntax ) )
7171 {
7272 context . ReportDiagnostic (
@@ -78,6 +78,22 @@ context.ContainingSymbol is IMethodSymbol method &&
7878 typeName ) ) ) ;
7979 }
8080 }
81+
82+ foreach ( var segment in template . Path )
83+ {
84+ if ( HasWrongSyntax ( segment , out var location , out var syntax ) )
85+ {
86+ context . ReportDiagnostic (
87+ Diagnostic . Create (
88+ ASP004ParameterSyntax . Descriptor ,
89+ location ,
90+ syntax == null
91+ ? ImmutableDictionary < string , string > . Empty
92+ : ImmutableDictionary < string , string > . Empty . Add (
93+ nameof ( Text ) ,
94+ syntax ) ) ) ;
95+ }
96+ }
8197 }
8298 }
8399 }
@@ -142,7 +158,7 @@ private static PooledList<ParameterPair> GetPairs(UrlTemplate template, IMethodS
142158 return list ;
143159 }
144160
145- private static bool TryGetCorrectParameterType ( ParameterPair pair , out string typeName )
161+ private static bool HasWrongType ( ParameterPair pair , out string correctType )
146162 {
147163 if ( pair . Template ? . Constraints is ImmutableArray < RouteConstraint > constraints &&
148164 pair . Method is IParameterSymbol parameter )
@@ -153,31 +169,31 @@ private static bool TryGetCorrectParameterType(ParameterPair pair, out string ty
153169 switch ( constraint . Span . Text )
154170 {
155171 case "bool" :
156- typeName = constraint . Span . Text ;
172+ correctType = constraint . Span . Text ;
157173 return parameter . Type != KnownSymbol . Boolean ;
158174 case "decimal" :
159- typeName = constraint . Span . Text ;
175+ correctType = constraint . Span . Text ;
160176 return parameter . Type != KnownSymbol . Decimal ;
161177 case "double" :
162- typeName = constraint . Span . Text ;
178+ correctType = constraint . Span . Text ;
163179 return parameter . Type != KnownSymbol . Double ;
164180 case "float" :
165- typeName = constraint . Span . Text ;
181+ correctType = constraint . Span . Text ;
166182 return parameter . Type != KnownSymbol . Float ;
167183 case "int" :
168- typeName = constraint . Span . Text ;
184+ correctType = constraint . Span . Text ;
169185 return parameter . Type != KnownSymbol . Int32 ;
170186 case "long" :
171- typeName = constraint . Span . Text ;
187+ correctType = constraint . Span . Text ;
172188 return parameter . Type != KnownSymbol . Int64 ;
173189 case "datetime" when parameter . Type != KnownSymbol . DateTime :
174- typeName = "System.DateTime" ;
190+ correctType = "System.DateTime" ;
175191 return true ;
176192 case "guid" when parameter . Type != KnownSymbol . Guid :
177- typeName = "System.Guid" ;
193+ correctType = "System.Guid" ;
178194 return true ;
179195 case "alpha" when parameter . Type != KnownSymbol . String :
180- typeName = "string" ;
196+ correctType = "string" ;
181197 return true ;
182198 case "required" :
183199 continue ;
@@ -186,19 +202,43 @@ private static bool TryGetCorrectParameterType(ParameterPair pair, out string ty
186202 text . StartsWith ( "length(" , StringComparison . OrdinalIgnoreCase ) ||
187203 text . StartsWith ( "minlength(" , StringComparison . OrdinalIgnoreCase ) ||
188204 text . StartsWith ( "maxlength(" , StringComparison . OrdinalIgnoreCase ) ) :
189- typeName = "string" ;
205+ correctType = "string" ;
190206 return true ;
191207 case string text when parameter . Type != KnownSymbol . Int64 &&
192208 ( text . StartsWith ( "min(" , StringComparison . OrdinalIgnoreCase ) ||
193209 text . StartsWith ( "max(" , StringComparison . OrdinalIgnoreCase ) ||
194210 text . StartsWith ( "range(" , StringComparison . OrdinalIgnoreCase ) ) :
195- typeName = "long" ;
211+ correctType = "long" ;
196212 return true ;
197213 }
198214 }
199215 }
200216
201- typeName = null ;
217+ correctType = null ;
218+ return false ;
219+ }
220+
221+ private static bool HasWrongSyntax ( PathSegment segment , out Location location , out string correctSyntax )
222+ {
223+ var text = segment . Span . Text ;
224+ if ( text . StartsWith ( "{" , StringComparison . Ordinal ) &&
225+ ! text . EndsWith ( "}" , StringComparison . Ordinal ) )
226+ {
227+ location = segment . Span . GetLocation ( ) ;
228+ correctSyntax = text + "}" ;
229+ return true ;
230+ }
231+
232+ if ( ! text . StartsWith ( "{" , StringComparison . Ordinal ) &&
233+ text . EndsWith ( "}" , StringComparison . Ordinal ) )
234+ {
235+ location = segment . Span . GetLocation ( ) ;
236+ correctSyntax = "{" + text ;
237+ return true ;
238+ }
239+
240+ location = null ;
241+ correctSyntax = null ;
202242 return false ;
203243 }
204244 }
0 commit comments