22// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
33// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
44// </copyright>
5+
6+ #nullable enable
7+
58#if ! NETFRAMEWORK
69
710using System ;
@@ -18,15 +21,15 @@ internal class AspNetCoreResourceNameHelper
1821 internal static string SimplifyRoutePattern (
1922 RoutePattern routePattern ,
2023 RouteValueDictionary routeValueDictionary ,
21- string areaName ,
22- string controllerName ,
23- string actionName ,
24+ string ? areaName ,
25+ string ? controllerName ,
26+ string ? actionName ,
2427 bool expandRouteParameters )
2528 {
26- var maxSize = routePattern . RawText . Length
27- + ( string . IsNullOrEmpty ( areaName ) ? 0 : Math . Max ( areaName . Length - 4 , 0 ) ) // "area".Length
28- + ( string . IsNullOrEmpty ( controllerName ) ? 0 : Math . Max ( controllerName . Length - 10 , 0 ) ) // "controller".Length
29- + ( string . IsNullOrEmpty ( actionName ) ? 0 : Math . Max ( actionName . Length - 6 , 0 ) ) // "action".Length
29+ var maxSize = ( routePattern . RawText ? . Length ?? 0 )
30+ + ( string . IsNullOrEmpty ( areaName ) ? 0 : Math . Max ( areaName ! . Length - 4 , 0 ) ) // "area".Length
31+ + ( string . IsNullOrEmpty ( controllerName ) ? 0 : Math . Max ( controllerName ! . Length - 10 , 0 ) ) // "controller".Length
32+ + ( string . IsNullOrEmpty ( actionName ) ? 0 : Math . Max ( actionName ! . Length - 6 , 0 ) ) // "action".Length
3033 + 1 ; // '/' prefix
3134
3235 var sb = StringBuilderCache . Acquire ( maxSize ) ;
@@ -129,15 +132,15 @@ internal static string SimplifyRoutePattern(
129132 internal static string SimplifyRouteTemplate (
130133 RouteTemplate routePattern ,
131134 RouteValueDictionary routeValueDictionary ,
132- string areaName ,
133- string controllerName ,
134- string actionName ,
135+ string ? areaName ,
136+ string ? controllerName ,
137+ string ? actionName ,
135138 bool expandRouteParameters )
136139 {
137- var maxSize = routePattern . TemplateText . Length
138- + ( string . IsNullOrEmpty ( areaName ) ? 0 : Math . Max ( areaName . Length - 4 , 0 ) ) // "area".Length
139- + ( string . IsNullOrEmpty ( controllerName ) ? 0 : Math . Max ( controllerName . Length - 10 , 0 ) ) // "controller".Length
140- + ( string . IsNullOrEmpty ( actionName ) ? 0 : Math . Max ( actionName . Length - 6 , 0 ) ) // "action".Length
140+ var maxSize = ( routePattern . TemplateText ? . Length ?? 0 )
141+ + ( string . IsNullOrEmpty ( areaName ) ? 0 : Math . Max ( areaName ! . Length - 4 , 0 ) ) // "area".Length
142+ + ( string . IsNullOrEmpty ( controllerName ) ? 0 : Math . Max ( controllerName ! . Length - 10 , 0 ) ) // "controller".Length
143+ + ( string . IsNullOrEmpty ( actionName ) ? 0 : Math . Max ( actionName ! . Length - 6 , 0 ) ) // "action".Length
141144 + 1 ; // '/' prefix
142145
143146 var sb = StringBuilderCache . Acquire ( maxSize ) ;
@@ -228,7 +231,7 @@ internal static string SimplifyRouteTemplate(
228231 return string . IsNullOrEmpty ( simplifiedRoute ) ? "/" : simplifiedRoute . ToLowerInvariant ( ) ;
229232 }
230233
231- private static bool IsIdentifierSegment ( object value , [ NotNullWhen ( false ) ] out string valueAsString )
234+ private static bool IsIdentifierSegment ( object ? value , [ NotNullWhen ( true ) ] out string ? valueAsString )
232235 {
233236 valueAsString = value as string ?? value ? . ToString ( ) ;
234237 if ( valueAsString is null )
0 commit comments