@@ -9,6 +9,7 @@ namespace Asp.Versioning.ApiExplorer;
9
9
using Microsoft . AspNetCore . Routing ;
10
10
using Microsoft . AspNetCore . Routing . Patterns ;
11
11
using Microsoft . AspNetCore . Routing . Template ;
12
+ using System . Runtime . CompilerServices ;
12
13
using static Asp . Versioning . ApiVersionParameterLocation ;
13
14
using static System . Linq . Enumerable ;
14
15
using static System . StringComparison ;
@@ -304,7 +305,7 @@ routeInfo.Constraints is IEnumerable<IRouteConstraint> constraints &&
304
305
continue ;
305
306
}
306
307
307
- var token = $ " { parameter . Name } : { constraintName } " ;
308
+ var token = FormatToken ( parameter . Name , constraintName ) ;
308
309
309
310
parameterDescription . Name = parameter . Name ;
310
311
description . RelativePath = relativePath . Replace ( token , parameter . Name , Ordinal ) ;
@@ -375,7 +376,7 @@ routeInfo.Constraints is IEnumerable<IRouteConstraint> constraints &&
375
376
} ,
376
377
Source = BindingSource . Path ,
377
378
} ;
378
- var token = $ " { parameter . Name } : { constraintName } " ;
379
+ var token = FormatToken ( parameter . Name ! , constraintName ! ) ;
379
380
380
381
description . RelativePath = relativePath . Replace ( token , parameter . Name , Ordinal ) ;
381
382
description . ParameterDescriptions . Insert ( 0 , result ) ;
@@ -457,4 +458,18 @@ private static bool FirstParameterIsOptional(
457
458
458
459
return apiVersion == defaultApiVersion ;
459
460
}
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
+ }
460
475
}
0 commit comments