@@ -31,15 +31,11 @@ internal static class WriteType<T, TSerializer>
31
31
internal static TypePropertyWriter [ ] PropertyWriters ;
32
32
private static readonly WriteObjectDelegate WriteTypeInfo ;
33
33
34
- private static bool IsIncluded
35
- {
36
- get { return ( JsConfig < T > . IncludeTypeInfo . GetValueOrDefault ( JsConfig . IncludeTypeInfo ) ) ; }
37
- }
34
+ private static bool IsIncluded =>
35
+ JsConfig < T > . IncludeTypeInfo . GetValueOrDefault ( JsConfig . IncludeTypeInfo ) ;
38
36
39
- private static bool IsExcluded
40
- {
41
- get { return ( JsConfig < T > . ExcludeTypeInfo . GetValueOrDefault ( JsConfig . ExcludeTypeInfo ) ) ; }
42
- }
37
+ private static bool IsExcluded =>
38
+ JsConfig < T > . ExcludeTypeInfo . GetValueOrDefault ( JsConfig . ExcludeTypeInfo ) ;
43
39
44
40
static WriteType ( )
45
41
{
@@ -188,7 +184,7 @@ private static bool Init()
188
184
propertyOrder ,
189
185
propertySuppressDefaultConfig ,
190
186
propertySuppressDefaultAttribute ,
191
- propertyInfo . GetValueGetter < T > ( ) ,
187
+ propertyInfo . GetPropertyGetterFn ( ) ,
192
188
Serializer . GetWriteFn ( propertyType ) ,
193
189
propertyType . GetDefaultValue ( ) ,
194
190
shouldSerialize ,
@@ -245,7 +241,7 @@ private static bool Init()
245
241
propertyOrder ,
246
242
propertySuppressDefaultConfig ,
247
243
propertySuppressDefaultAttribute ,
248
- fieldInfo . GetValueGetter < T > ( ) ,
244
+ fieldInfo . GetFieldGetterFn ( ) ,
249
245
Serializer . GetWriteFn ( propertyType ) ,
250
246
defaultValue ,
251
247
shouldSerialize ,
@@ -264,9 +260,9 @@ internal string PropertyName
264
260
{
265
261
get
266
262
{
267
- return ( JsConfig < T > . EmitCamelCaseNames . GetValueOrDefault ( JsConfig . EmitCamelCaseNames ) )
263
+ return JsConfig < T > . EmitCamelCaseNames . GetValueOrDefault ( JsConfig . EmitCamelCaseNames )
268
264
? propertyNameCLSFriendly
269
- : ( JsConfig < T > . EmitLowercaseUnderscoreNames . GetValueOrDefault ( JsConfig . EmitLowercaseUnderscoreNames ) )
265
+ : JsConfig < T > . EmitLowercaseUnderscoreNames . GetValueOrDefault ( JsConfig . EmitLowercaseUnderscoreNames )
270
266
? propertyNameLowercaseUnderscore
271
267
: propertyName ;
272
268
}
@@ -280,7 +276,7 @@ internal string PropertyName
280
276
internal readonly string propertyReferenceName ;
281
277
internal readonly string propertyNameCLSFriendly ;
282
278
internal readonly string propertyNameLowercaseUnderscore ;
283
- internal readonly Func < T , object > GetterFn ;
279
+ internal readonly GetMemberDelegate GetterFn ;
284
280
internal readonly WriteObjectDelegate WriteFn ;
285
281
internal readonly object DefaultValue ;
286
282
internal readonly Func < T , bool > shouldSerialize ;
@@ -289,7 +285,7 @@ internal string PropertyName
289
285
290
286
public TypePropertyWriter ( Type propertyType , string propertyName , string propertyDeclaredTypeName , string propertyNameCLSFriendly ,
291
287
string propertyNameLowercaseUnderscore , int propertyOrder , bool propertySuppressDefaultConfig , bool propertySuppressDefaultAttribute ,
292
- Func < T , object > getterFn , WriteObjectDelegate writeFn , object defaultValue ,
288
+ GetMemberDelegate getterFn , WriteObjectDelegate writeFn , object defaultValue ,
293
289
Func < T , bool > shouldSerialize ,
294
290
Func < T , string , bool ? > shouldSerializeDynamic ,
295
291
bool isEnum )
@@ -375,18 +371,18 @@ internal static string GetPropertyName(string propertyName)
375
371
: propertyName ;
376
372
}
377
373
378
- public static void WriteProperties ( TextWriter writer , object value )
374
+ public static void WriteProperties ( TextWriter writer , object instance )
379
375
{
380
- if ( value == null )
376
+ if ( instance == null )
381
377
{
382
378
writer . Write ( JsWriter . EmptyMap ) ;
383
379
return ;
384
380
}
385
381
386
- var valueType = value . GetType ( ) ;
382
+ var valueType = instance . GetType ( ) ;
387
383
if ( PropertyWriters != null && valueType != typeof ( T ) && ! typeof ( T ) . IsAbstract ( ) )
388
384
{
389
- WriteLateboundProperties ( writer , value , valueType ) ;
385
+ WriteLateboundProperties ( writer , instance , valueType ) ;
390
386
return ;
391
387
}
392
388
@@ -399,7 +395,7 @@ public static void WriteProperties(TextWriter writer, object value)
399
395
if ( WriteTypeInfo != null || JsState . IsWritingDynamic )
400
396
{
401
397
if ( JsConfig . PreferInterfaces && TryWriteSelfType ( writer ) ) i ++ ;
402
- else if ( TryWriteTypeInfo ( writer , value ) ) i ++ ;
398
+ else if ( TryWriteTypeInfo ( writer , instance ) ) i ++ ;
403
399
JsState . IsWritingDynamic = false ;
404
400
}
405
401
@@ -410,13 +406,13 @@ public static void WriteProperties(TextWriter writer, object value)
410
406
{
411
407
var propertyWriter = PropertyWriters [ index ] ;
412
408
413
- if ( propertyWriter . shouldSerialize != null && ! propertyWriter . shouldSerialize ( ( T ) value ) )
409
+ if ( propertyWriter . shouldSerialize != null && ! propertyWriter . shouldSerialize ( ( T ) instance ) )
414
410
continue ;
415
411
416
412
var dontSkipDefault = false ;
417
413
if ( propertyWriter . shouldSerializeDynamic != null )
418
414
{
419
- var shouldSerialize = propertyWriter . shouldSerializeDynamic ( ( T ) value , propertyWriter . PropertyName ) ;
415
+ var shouldSerialize = propertyWriter . shouldSerializeDynamic ( ( T ) instance , propertyWriter . PropertyName ) ;
420
416
if ( shouldSerialize . HasValue )
421
417
{
422
418
if ( shouldSerialize . Value )
@@ -426,7 +422,7 @@ public static void WriteProperties(TextWriter writer, object value)
426
422
}
427
423
}
428
424
429
- var propertyValue = propertyWriter . GetterFn ( ( T ) value ) ;
425
+ var propertyValue = propertyWriter . GetterFn ( instance ) ;
430
426
431
427
if ( ! dontSkipDefault )
432
428
{
@@ -476,25 +472,25 @@ private static void WriteLateboundProperties(TextWriter writer, object value, Ty
476
472
if ( ! JsConfig < T > . ExcludeTypeInfo . GetValueOrDefault ( ) ) JsState . IsWritingDynamic = false ;
477
473
}
478
474
479
- private static readonly char [ ] ArrayBrackets = new [ ] { '[' , ']' } ;
475
+ private static readonly char [ ] ArrayBrackets = { '[' , ']' } ;
480
476
481
- public static void WriteComplexQueryStringProperties ( string typeName , TextWriter writer , object value )
477
+ public static void WriteComplexQueryStringProperties ( string typeName , TextWriter writer , object instance )
482
478
{
483
479
var i = 0 ;
484
480
if ( PropertyWriters != null )
485
481
{
486
482
var len = PropertyWriters . Length ;
487
- for ( int index = 0 ; index < len ; index ++ )
483
+ for ( var index = 0 ; index < len ; index ++ )
488
484
{
489
485
var propertyWriter = PropertyWriters [ index ] ;
490
- if ( propertyWriter . shouldSerialize != null && ! propertyWriter . shouldSerialize ( ( T ) value ) ) continue ;
486
+ if ( propertyWriter . shouldSerialize != null && ! propertyWriter . shouldSerialize ( ( T ) instance ) ) continue ;
491
487
492
- var propertyValue = value != null ? propertyWriter . GetterFn ( ( T ) value ) : null ;
488
+ var propertyValue = instance != null ? propertyWriter . GetterFn ( instance ) : null ;
493
489
if ( propertyWriter . propertySuppressDefaultAttribute && Equals ( propertyWriter . DefaultValue , propertyValue ) )
494
490
continue ;
495
491
496
492
if ( ( propertyValue == null
497
- || ( propertyWriter . propertySuppressDefaultConfig && Equals ( propertyWriter . DefaultValue , propertyValue ) ) )
493
+ || propertyWriter . propertySuppressDefaultConfig && Equals ( propertyWriter . DefaultValue , propertyValue ) )
498
494
&& ! Serializer . IncludeNullValues )
499
495
continue ;
500
496
@@ -504,7 +500,7 @@ public static void WriteComplexQueryStringProperties(string typeName, TextWriter
504
500
if ( i ++ > 0 )
505
501
writer . Write ( '&' ) ;
506
502
507
- var propertyValueType = propertyValue != null ? propertyValue . GetType ( ) : null ;
503
+ var propertyValueType = propertyValue ? . GetType ( ) ;
508
504
if ( propertyValueType != null &&
509
505
propertyValueType . IsUserType ( ) &&
510
506
! propertyValueType . HasInterface ( typeof ( IEnumerable ) ) )
@@ -557,15 +553,15 @@ public static void WriteComplexQueryStringProperties(string typeName, TextWriter
557
553
}
558
554
}
559
555
560
- public static void WriteQueryString ( TextWriter writer , object value )
556
+ public static void WriteQueryString ( TextWriter writer , object instance )
561
557
{
562
558
try
563
559
{
564
560
JsState . QueryStringMode = true ;
565
561
var i = 0 ;
566
562
foreach ( var propertyWriter in PropertyWriters )
567
563
{
568
- var propertyValue = propertyWriter . GetterFn ( ( T ) value ) ;
564
+ var propertyValue = propertyWriter . GetterFn ( instance ) ;
569
565
if ( propertyValue == null ) continue ;
570
566
571
567
if ( i ++ > 0 )
0 commit comments