@@ -195,30 +195,30 @@ private static PooledList<ParameterPair> GetPairs(UrlTemplate template, IMethodS
195195
196196 private static bool HasWrongType ( ParameterPair pair , out string correctType , out Location constraintLocation , out string correctConstraint )
197197 {
198- if ( pair . Route is TemplateParameter parameter &&
199- parameter . Constraints is ImmutableArray < RouteConstraint > constraints &&
200- pair . Symbol is IParameterSymbol symbol )
198+ if ( pair . Route is TemplateParameter templateParameter &&
199+ templateParameter . Constraints is ImmutableArray < RouteConstraint > constraints &&
200+ pair . Symbol is IParameterSymbol parameterSymbol )
201201 {
202202 foreach ( var constraint in constraints )
203203 {
204204 // https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-2.2#route-constraint-reference
205205 if ( TryGetType ( constraint . Span , out var type ) )
206206 {
207- correctType = symbol . Type == type ? null : type . Alias ?? type . FullName ;
207+ correctType = parameterSymbol . Type == type ? null : type . Alias ?? type . FullName ;
208208 constraintLocation = constraint . Span . GetLocation ( ) ;
209- correctConstraint = null ;
209+ correctConstraint = GetCorrectConstraintType ( constraint ) ;
210210 return correctType != null ;
211211 }
212212 }
213213
214214 if ( ! constraints . TryFirst ( x => x . Span . Equals ( "?" , StringComparison . Ordinal ) , out _ ) &&
215- symbol . Type . OriginalDefinition . SpecialType == SpecialType . System_Nullable_T &&
216- symbol . Type is INamedTypeSymbol namedType &&
215+ parameterSymbol . Type . OriginalDefinition . SpecialType == SpecialType . System_Nullable_T &&
216+ parameterSymbol . Type is INamedTypeSymbol namedType &&
217217 namedType . TypeArguments . TrySingle ( out var typeArg ) )
218218 {
219219 correctType = typeArg . ToString ( ) ;
220- constraintLocation = parameter . Name . GetLocation ( ) ;
221- correctConstraint = $ "{ parameter . Name } ?";
220+ constraintLocation = templateParameter . Name . GetLocation ( ) ;
221+ correctConstraint = $ "{ templateParameter . Name } ?";
222222 return true ;
223223 }
224224 }
@@ -294,6 +294,23 @@ bool TryGetType(Span constraint, out QualifiedType type)
294294 type = null ;
295295 return false ;
296296 }
297+
298+ string GetCorrectConstraintType ( RouteConstraint constraint )
299+ {
300+ if ( constraint . Span . Equals ( "bool" , StringComparison . Ordinal ) ||
301+ constraint . Span . Equals ( "decimal" , StringComparison . Ordinal ) ||
302+ constraint . Span . Equals ( "double" , StringComparison . Ordinal ) ||
303+ constraint . Span . Equals ( "float" , StringComparison . Ordinal ) ||
304+ constraint . Span . Equals ( "int" , StringComparison . Ordinal ) ||
305+ constraint . Span . Equals ( "long" , StringComparison . Ordinal ) ||
306+ constraint . Span . Equals ( "datetime" , StringComparison . Ordinal ) ||
307+ constraint . Span . Equals ( "guid" , StringComparison . Ordinal ) )
308+ {
309+ return parameterSymbol . Type . ToDisplayString ( SymbolDisplayFormat . MinimallyQualifiedFormat ) . ToLower ( ) ;
310+ }
311+
312+ return null ;
313+ }
297314 }
298315
299316 private static bool HasWrongSyntax ( PathSegment segment , out Location location , out string correctSyntax )
0 commit comments