File tree 3 files changed +38
-8
lines changed
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata
3 files changed +38
-8
lines changed Original file line number Diff line number Diff line change @@ -338,6 +338,25 @@ private bool NumberHandingIsApplicable()
338
338
339
339
internal abstract object ? GetValueAsObject ( object obj ) ;
340
340
341
+ #if DEBUG
342
+ internal string GetDebugInfo ( int indent = 0 )
343
+ {
344
+ string ind = new string ( ' ' , indent ) ;
345
+ StringBuilder sb = new ( ) ;
346
+
347
+ sb . AppendLine ( $ "{ ind } {{") ;
348
+ sb . AppendLine ( $ "{ ind } Name: { Name } ,") ;
349
+ sb . AppendLine ( $ "{ ind } NameAsUtf8.Length: { ( NameAsUtf8Bytes ? . Length ?? - 1 ) } ,") ;
350
+ sb . AppendLine ( $ "{ ind } IsConfigured: { _isConfigured } ,") ;
351
+ sb . AppendLine ( $ "{ ind } IsIgnored: { IsIgnored } ,") ;
352
+ sb . AppendLine ( $ "{ ind } ShouldSerialize: { ShouldSerialize } ,") ;
353
+ sb . AppendLine ( $ "{ ind } ShouldDeserialize: { ShouldDeserialize } ,") ;
354
+ sb . AppendLine ( $ "{ ind } }}") ;
355
+
356
+ return sb . ToString ( ) ;
357
+ }
358
+ #endif
359
+
341
360
internal bool HasGetter { get ; set ; }
342
361
internal bool HasSetter { get ; set ; }
343
362
Original file line number Diff line number Diff line change @@ -187,7 +187,14 @@ internal JsonPropertyInfo GetProperty(
187
187
{
188
188
if ( propertyName . SequenceEqual ( info . NameAsUtf8Bytes ) )
189
189
{
190
- Debug . Assert ( key == GetKey ( info . NameAsUtf8Bytes . AsSpan ( ) ) , "key does not match re-computed value for the same sequence (case-insensitive)" ) ;
190
+ #if DEBUG
191
+ ulong recomputedKey = GetKey ( info . NameAsUtf8Bytes . AsSpan ( ) ) ;
192
+ if ( key != recomputedKey )
193
+ {
194
+ string propertyNameStr = JsonHelpers . Utf8GetString ( propertyName ) ;
195
+ Debug . Fail ( $ "key { key } [propertyName={ propertyNameStr } ] does not match re-computed value { recomputedKey } for the same sequence (case-insensitive). { info . GetDebugInfo ( ) } ") ;
196
+ }
197
+ #endif
191
198
192
199
// Use the existing byte[] reference instead of creating another one.
193
200
utf8PropertyName = info . NameAsUtf8Bytes ! ;
@@ -200,7 +207,14 @@ internal JsonPropertyInfo GetProperty(
200
207
}
201
208
else
202
209
{
203
- Debug . Assert ( key == GetKey ( info . NameAsUtf8Bytes . AsSpan ( ) ) , "key does not match re-computed value for the same sequence (case-sensitive)" ) ;
210
+ #if DEBUG
211
+ ulong recomputedKey = GetKey ( info . NameAsUtf8Bytes . AsSpan ( ) ) ;
212
+ if ( key != recomputedKey )
213
+ {
214
+ string propertyNameStr = JsonHelpers . Utf8GetString ( propertyName ) ;
215
+ Debug . Fail ( $ "key { key } [propertyName={ propertyNameStr } ] does not match re-computed value { recomputedKey } for the same sequence (case-sensitive). { info . GetDebugInfo ( ) } ") ;
216
+ }
217
+ #endif
204
218
utf8PropertyName = info . NameAsUtf8Bytes ;
205
219
}
206
220
}
Original file line number Diff line number Diff line change @@ -255,7 +255,7 @@ internal string GetDebugInfo()
255
255
bool propCacheInitialized = PropertyCache != null ;
256
256
257
257
StringBuilder sb = new ( ) ;
258
- sb . AppendLine ( $ " { jtiTypeName } { {") ;
258
+ sb . AppendLine ( " {") ;
259
259
sb . AppendLine ( $ " GetType: { jtiTypeName } ,") ;
260
260
sb . AppendLine ( $ " Type: { typeName } ,") ;
261
261
sb . AppendLine ( $ " ConverterStrategy: { strat } ,") ;
@@ -268,11 +268,8 @@ internal string GetDebugInfo()
268
268
foreach ( var property in PropertyCache ! . List )
269
269
{
270
270
JsonPropertyInfo pi = property . Value ! ;
271
- sb . AppendLine ( $ " { property . Key } : {{") ;
272
- sb . AppendLine ( $ " Ignored: { pi . IsIgnored } ,") ;
273
- sb . AppendLine ( $ " ShouldSerialize: { pi . ShouldSerialize } ,") ;
274
- sb . AppendLine ( $ " ShouldDeserialize: { pi . ShouldDeserialize } ,") ;
275
- sb . AppendLine ( " }," ) ;
271
+ sb . AppendLine ( $ " { property . Key } :") ;
272
+ sb . AppendLine ( $ "{ pi . GetDebugInfo ( indent : 6 ) } ,") ;
276
273
}
277
274
278
275
sb . AppendLine ( " }," ) ;
You can’t perform that action at this time.
0 commit comments