@@ -184,7 +184,7 @@ private static bool Init()
184
184
propertyOrder ,
185
185
propertySuppressDefaultConfig ,
186
186
propertySuppressDefaultAttribute ,
187
- propertyInfo . GetPropertyGetterFn ( ) ,
187
+ propertyInfo . GetPropertyGetterFn < T > ( ) ,
188
188
Serializer . GetWriteFn ( propertyType ) ,
189
189
propertyType . GetDefaultValue ( ) ,
190
190
shouldSerialize ,
@@ -241,7 +241,7 @@ private static bool Init()
241
241
propertyOrder ,
242
242
propertySuppressDefaultConfig ,
243
243
propertySuppressDefaultAttribute ,
244
- fieldInfo . GetFieldGetterFn ( ) ,
244
+ fieldInfo . GetFieldGetterFn < T > ( ) ,
245
245
Serializer . GetWriteFn ( propertyType ) ,
246
246
defaultValue ,
247
247
shouldSerialize ,
@@ -276,7 +276,7 @@ internal string PropertyName
276
276
internal readonly string propertyReferenceName ;
277
277
internal readonly string propertyNameCLSFriendly ;
278
278
internal readonly string propertyNameLowercaseUnderscore ;
279
- internal readonly GetMemberDelegate GetterFn ;
279
+ internal readonly GetMemberDelegate < T > GetterFn ;
280
280
internal readonly WriteObjectDelegate WriteFn ;
281
281
internal readonly object DefaultValue ;
282
282
internal readonly Func < T , bool > shouldSerialize ;
@@ -285,7 +285,7 @@ internal string PropertyName
285
285
286
286
public TypePropertyWriter ( Type propertyType , string propertyName , string propertyDeclaredTypeName , string propertyNameCLSFriendly ,
287
287
string propertyNameLowercaseUnderscore , int propertyOrder , bool propertySuppressDefaultConfig , bool propertySuppressDefaultAttribute ,
288
- GetMemberDelegate getterFn , WriteObjectDelegate writeFn , object defaultValue ,
288
+ GetMemberDelegate < T > getterFn , WriteObjectDelegate writeFn , object defaultValue ,
289
289
Func < T , bool > shouldSerialize ,
290
290
Func < T , string , bool ? > shouldSerializeDynamic ,
291
291
bool isEnum )
@@ -401,18 +401,19 @@ public static void WriteProperties(TextWriter writer, object instance)
401
401
402
402
if ( PropertyWriters != null )
403
403
{
404
+ var typedInstance = ( T ) instance ;
404
405
var len = PropertyWriters . Length ;
405
406
for ( int index = 0 ; index < len ; index ++ )
406
407
{
407
408
var propertyWriter = PropertyWriters [ index ] ;
408
409
409
- if ( propertyWriter . shouldSerialize != null && ! propertyWriter . shouldSerialize ( ( T ) instance ) )
410
+ if ( propertyWriter . shouldSerialize != null && ! propertyWriter . shouldSerialize ( typedInstance ) )
410
411
continue ;
411
412
412
413
var dontSkipDefault = false ;
413
414
if ( propertyWriter . shouldSerializeDynamic != null )
414
415
{
415
- var shouldSerialize = propertyWriter . shouldSerializeDynamic ( ( T ) instance , propertyWriter . PropertyName ) ;
416
+ var shouldSerialize = propertyWriter . shouldSerializeDynamic ( typedInstance , propertyWriter . PropertyName ) ;
416
417
if ( shouldSerialize . HasValue )
417
418
{
418
419
if ( shouldSerialize . Value )
@@ -422,7 +423,7 @@ public static void WriteProperties(TextWriter writer, object instance)
422
423
}
423
424
}
424
425
425
- var propertyValue = propertyWriter . GetterFn ( instance ) ;
426
+ var propertyValue = propertyWriter . GetterFn ( typedInstance ) ;
426
427
427
428
if ( ! dontSkipDefault )
428
429
{
@@ -479,13 +480,14 @@ public static void WriteComplexQueryStringProperties(string typeName, TextWriter
479
480
var i = 0 ;
480
481
if ( PropertyWriters != null )
481
482
{
483
+ var typedInstance = ( T ) instance ;
482
484
var len = PropertyWriters . Length ;
483
485
for ( var index = 0 ; index < len ; index ++ )
484
486
{
485
487
var propertyWriter = PropertyWriters [ index ] ;
486
- if ( propertyWriter . shouldSerialize != null && ! propertyWriter . shouldSerialize ( ( T ) instance ) ) continue ;
488
+ if ( propertyWriter . shouldSerialize != null && ! propertyWriter . shouldSerialize ( typedInstance ) ) continue ;
487
489
488
- var propertyValue = instance != null ? propertyWriter . GetterFn ( instance ) : null ;
490
+ var propertyValue = instance != null ? propertyWriter . GetterFn ( typedInstance ) : null ;
489
491
if ( propertyWriter . propertySuppressDefaultAttribute && Equals ( propertyWriter . DefaultValue , propertyValue ) )
490
492
continue ;
491
493
@@ -559,9 +561,10 @@ public static void WriteQueryString(TextWriter writer, object instance)
559
561
{
560
562
JsState . QueryStringMode = true ;
561
563
var i = 0 ;
564
+ var typedInstance = ( T ) instance ;
562
565
foreach ( var propertyWriter in PropertyWriters )
563
566
{
564
- var propertyValue = propertyWriter . GetterFn ( instance ) ;
567
+ var propertyValue = propertyWriter . GetterFn ( typedInstance ) ;
565
568
if ( propertyValue == null ) continue ;
566
569
567
570
if ( i ++ > 0 )
0 commit comments