77using Microsoft . AspNetCore . WebUtilities ;
88using Microsoft . Extensions . Options ;
99using PowerUtils . Net . Constants ;
10- using PowerUtils . Text ;
1110
1211namespace PowerUtils . AspNetCore . ErrorHandler
1312{
@@ -22,16 +21,14 @@ internal static ProblemDetailsResponse Create(HttpContext httpContext)
2221 {
2322 var result = new ProblemDetailsResponse ( ) ;
2423
25- result . Status = httpContext . GetStatusCode ( ) ?? 0 ;
24+ result . Status = httpContext . GetStatusCode ( ) ?? 0 ; // Default value is 0
2625 result . Type = result . Status . GetStatusCodeLinkOrDefault ( ) ;
2726 result . Title = result . Status == 0 ? null : ReasonPhrases . GetReasonPhrase ( result . Status ) ;
2827
2928 result . Instance = httpContext . GetRequestEndpoint ( ) ;
3029
3130 result . TraceID = httpContext . GetCorrelationId ( ) ;
3231
33- result . Errors = new Dictionary < string , string > ( ) ;
34-
3532 return result ;
3633 }
3734
@@ -111,50 +108,9 @@ private string _formatPropertyName(string propertyName)
111108 => _options . Value . PropertyNamingPolicy switch
112109 {
113110 PropertyNamingPolicy . Original => propertyName ,
114- PropertyNamingPolicy . SnakeCase => _formatPropertyToSnakeCase ( propertyName ) ,
115- _ => _formatPropertyToCamelCase ( propertyName ) ,
111+ PropertyNamingPolicy . SnakeCase => propertyName . FormatToSnakeCase ( ) ,
112+ _ => propertyName . FormatToCamelCase ( ) ,
116113 } ;
117114
118- private static string _formatPropertyToCamelCase ( string propertyName )
119- {
120- if ( string . IsNullOrWhiteSpace ( propertyName ) )
121- {
122- return "" ;
123- }
124-
125- var propertyParts = propertyName . Split ( '.' ) ;
126- if ( propertyParts . Length == 1 )
127- {
128- return char . ToLowerInvariant ( propertyName [ 0 ] ) + propertyName [ 1 ..] ;
129- }
130-
131-
132- for ( var count = 0 ; count < propertyParts . Length ; count ++ )
133- {
134- // Prevent System.IndexOutOfRangeException: 'Index was outside the bounds of the array.' for cases "Hello."
135- if ( propertyParts [ count ] . Length == 0 )
136- {
137- continue ;
138- }
139-
140- propertyParts [ count ] = char . ToLowerInvariant ( propertyParts [ count ] [ 0 ] ) + propertyParts [ count ] [ 1 ..] ;
141- }
142-
143-
144- return string . Join ( "." , propertyParts ) ;
145- }
146-
147- private static string _formatPropertyToSnakeCase ( string propertyName )
148- {
149- var propertyParts = propertyName . Split ( '.' ) ;
150-
151- for ( var count = 0 ; count < propertyParts . Length ; count ++ )
152- {
153- propertyParts [ count ] = propertyParts [ count ] . ToSnakeCase ( ) ;
154- }
155-
156-
157- return string . Join ( "." , propertyParts ) ;
158- }
159115 }
160116}
0 commit comments