@@ -138,6 +138,7 @@ public override void WriteValue(CharSpan value)
138
138
{
139
139
WriteRawValue ( value ) ;
140
140
}
141
+
141
142
base . Flush ( ) ;
142
143
builder . Remove ( builderLength , 1 ) ;
143
144
return ;
@@ -266,6 +267,93 @@ public void WriteMember(object target, object? value, string name)
266
267
WriteOrSerialize ( value ) ;
267
268
}
268
269
270
+ /// <summary>
271
+ /// Writes a property name and value while respecting other custom serialization settings.
272
+ /// </summary>
273
+ public void WriteMember ( object target , string ? value , string name )
274
+ {
275
+ if ( value is null )
276
+ {
277
+ WriteNullMember ( name ) ;
278
+ return ;
279
+ }
280
+
281
+ var declaringType = target . GetType ( ) ;
282
+ if ( serialization . TryGetScrubOrIgnore ( declaringType , typeof ( string ) , name , out var scrubOrIgnore ) )
283
+ {
284
+ if ( scrubOrIgnore != ScrubOrIgnore . Ignore )
285
+ {
286
+ WriteRawOrStrictMember ( name , "Scrubbed" ) ;
287
+ }
288
+
289
+ return ;
290
+ }
291
+
292
+ if ( serialization . TryGetScrubOrIgnoreByInstance ( value , out scrubOrIgnore ) )
293
+ {
294
+ if ( scrubOrIgnore != ScrubOrIgnore . Ignore )
295
+ {
296
+ WriteRawOrStrictMember ( name , "Scrubbed" ) ;
297
+ }
298
+
299
+ return ;
300
+ }
301
+
302
+ var converter = VerifierSettings . GetMemberConverter ( declaringType , name ) ;
303
+ if ( converter is not null )
304
+ {
305
+ value = ( string ? ) converter ( target , value ) ;
306
+ if ( value is null )
307
+ {
308
+ return ;
309
+ }
310
+ }
311
+
312
+ WritePropertyName ( name ) ;
313
+ WriteValue ( value ) ;
314
+ }
315
+ /// <summary>
316
+ /// Writes a property name and value while respecting other custom serialization settings.
317
+ /// </summary>
318
+ public void WriteMember ( object target , CharSpan value , string name )
319
+ {
320
+ var declaringType = target . GetType ( ) ;
321
+ if ( serialization . TryGetScrubOrIgnore ( declaringType , typeof ( CharSpan ) , name , out var scrubOrIgnore ) )
322
+ {
323
+ if ( scrubOrIgnore != ScrubOrIgnore . Ignore )
324
+ {
325
+ WriteRawOrStrictMember ( name , "Scrubbed" ) ;
326
+ }
327
+
328
+ return ;
329
+ }
330
+
331
+ //TODO: support instance scrubbing for CharSpan?
332
+ // if (serialization.TryGetScrubOrIgnoreByInstance(value, out scrubOrIgnore))
333
+ // {
334
+ // if (scrubOrIgnore != ScrubOrIgnore.Ignore)
335
+ // {
336
+ // WriteRawOrStrictMember(name, "Scrubbed");
337
+ // }
338
+ //
339
+ // return;
340
+ // }
341
+
342
+ //TODO: support converters for CharSpan?
343
+ // var converter = VerifierSettings.GetMemberConverter(declaringType, name);
344
+ // if (converter is not null)
345
+ // {
346
+ // value = (string?) converter(target, value);
347
+ // if (value is null)
348
+ // {
349
+ // return;
350
+ // }
351
+ // }
352
+
353
+ WritePropertyName ( name ) ;
354
+ WriteValue ( value ) ;
355
+ }
356
+
269
357
void WriteRawOrStrictMember ( string name , string value )
270
358
{
271
359
WritePropertyName ( name ) ;
@@ -288,21 +376,21 @@ void WriteNullMember(string name)
288
376
}
289
377
}
290
378
291
- void WriteOrSerialize ( object converted )
379
+ void WriteOrSerialize ( object value )
292
380
{
293
- if ( converted is string convertedString )
381
+ if ( value is string stringValue )
294
382
{
295
- WriteValue ( convertedString ) ;
383
+ WriteValue ( stringValue ) ;
296
384
return ;
297
385
}
298
386
299
- if ( converted . GetType ( ) . IsPrimitive )
387
+ if ( value . GetType ( ) . IsPrimitive )
300
388
{
301
- WriteValue ( converted ) ;
389
+ WriteValue ( value ) ;
302
390
return ;
303
391
}
304
392
305
- settings . Serializer . Serialize ( this , converted ) ;
393
+ settings . Serializer . Serialize ( this , value ) ;
306
394
}
307
395
308
396
/// <summary>
0 commit comments