@@ -9,6 +9,7 @@ namespace Asp.Versioning.ApiExplorer;
99using Microsoft . AspNetCore . Routing ;
1010using Microsoft . AspNetCore . Routing . Patterns ;
1111using Microsoft . AspNetCore . Routing . Template ;
12+ using System . Runtime . CompilerServices ;
1213using static Asp . Versioning . ApiVersionParameterLocation ;
1314using static System . Linq . Enumerable ;
1415using static System . StringComparison ;
@@ -304,7 +305,7 @@ routeInfo.Constraints is IEnumerable<IRouteConstraint> constraints &&
304305 continue ;
305306 }
306307
307- var token = $ " { parameter . Name } : { constraintName } " ;
308+ var token = FormatToken ( parameter . Name , constraintName ) ;
308309
309310 parameterDescription . Name = parameter . Name ;
310311 description . RelativePath = relativePath . Replace ( token , parameter . Name , Ordinal ) ;
@@ -375,7 +376,7 @@ routeInfo.Constraints is IEnumerable<IRouteConstraint> constraints &&
375376 } ,
376377 Source = BindingSource . Path ,
377378 } ;
378- var token = $ " { parameter . Name } : { constraintName } " ;
379+ var token = FormatToken ( parameter . Name ! , constraintName ! ) ;
379380
380381 description . RelativePath = relativePath . Replace ( token , parameter . Name , Ordinal ) ;
381382 description . ParameterDescriptions . Insert ( 0 , result ) ;
@@ -457,4 +458,18 @@ private static bool FirstParameterIsOptional(
457458
458459 return apiVersion == defaultApiVersion ;
459460 }
461+
462+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
463+ private static string FormatToken ( ReadOnlySpan < char > parameterName , ReadOnlySpan < char > constraintName )
464+ {
465+ var left = parameterName . Length ;
466+ var right = constraintName . Length ;
467+ Span < char > token = stackalloc char [ left + right + 1 ] ;
468+
469+ parameterName . CopyTo ( token [ ..left ] ) ;
470+ token [ left ] = ':' ;
471+ constraintName . CopyTo ( token . Slice ( left + 1 , right ) ) ;
472+
473+ return token . ToString ( ) ;
474+ }
460475}
0 commit comments