@@ -237,6 +237,24 @@ private static void HandlePrimitive(FieldInfo field, out BinaryReflectiveWriteAc
237
237
? GetRawReader ( field , r => r . ReadDouble ( ) )
238
238
: GetReader ( field , ( f , r ) => r . ReadDouble ( f ) ) ;
239
239
}
240
+ else if ( type == typeof ( IntPtr ) )
241
+ {
242
+ writeAction = raw
243
+ ? GetRawWriter < IntPtr > ( field , ( w , o ) => w . WriteLong ( ( long ) o ) )
244
+ : GetWriter < IntPtr > ( field , ( f , w , o ) => w . WriteLong ( f , ( long ) o ) ) ;
245
+ readAction = raw
246
+ ? GetRawReader ( field , r => ( IntPtr ) r . ReadLong ( ) )
247
+ : GetReader ( field , ( f , r ) => ( IntPtr ) r . ReadLong ( f ) ) ;
248
+ }
249
+ else if ( type == typeof ( UIntPtr ) )
250
+ {
251
+ writeAction = raw
252
+ ? GetRawWriter < UIntPtr > ( field , ( w , o ) => w . WriteLong ( ( long ) o ) )
253
+ : GetWriter < UIntPtr > ( field , ( f , w , o ) => w . WriteLong ( f , ( long ) o ) ) ;
254
+ readAction = raw
255
+ ? GetRawReader ( field , r => ( UIntPtr ) r . ReadLong ( ) )
256
+ : GetReader ( field , ( f , r ) => ( UIntPtr ) r . ReadLong ( f ) ) ;
257
+ }
240
258
else
241
259
{
242
260
throw new IgniteException ( string . Format ( "Unsupported primitive type '{0}' [Field={1}, " +
@@ -268,7 +286,8 @@ private static void HandleArray(FieldInfo field, out BinaryReflectiveWriteAction
268
286
return ;
269
287
}
270
288
271
- Type elemType = field . FieldType . GetElementType ( ) ;
289
+ var elemType = field . FieldType . GetElementType ( ) ;
290
+ Debug . Assert ( elemType != null ) ;
272
291
273
292
if ( elemType == typeof ( bool ) )
274
293
{
@@ -478,8 +497,8 @@ private static void HandleOther(FieldInfo field, out BinaryReflectiveWriteAction
478
497
! new [ ] { typeof ( long ) , typeof ( ulong ) } . Contains ( Enum . GetUnderlyingType ( nullableType ?? type ) ) )
479
498
{
480
499
writeAction = raw
481
- ? GetRawWriter < object > ( field , ( w , o ) => w . WriteEnum ( o ) , true )
482
- : GetWriter < object > ( field , ( f , w , o ) => w . WriteEnum ( f , o ) , true ) ;
500
+ ? GetRawWriter < object > ( field , ( w , o ) => w . WriteEnum ( o ) )
501
+ : GetWriter < object > ( field , ( f , w , o ) => w . WriteEnum ( f , o ) ) ;
483
502
readAction = raw ? GetRawReader ( field , MthdReadEnumRaw ) : GetReader ( field , MthdReadEnum ) ;
484
503
}
485
504
else if ( type == typeof ( IDictionary ) || type == typeof ( Hashtable ) )
@@ -510,6 +529,21 @@ private static void HandleOther(FieldInfo field, out BinaryReflectiveWriteAction
510
529
writeAction = GetWriter < DateTime ? > ( field , ( f , w , o ) => w . WriteTimestamp ( f , o ) ) ;
511
530
readAction = GetReader ( field , ( f , r ) => r . ReadTimestamp ( f ) ) ;
512
531
}
532
+ else if ( type . IsPointer )
533
+ unsafe
534
+ {
535
+ // Expression trees do not work with pointers properly, use reflection.
536
+ var fieldName = BinaryUtils . CleanFieldName ( field . Name ) ;
537
+ writeAction = raw
538
+ ? ( BinaryReflectiveWriteAction ) ( ( o , w ) =>
539
+ w . GetRawWriter ( ) . WriteLong ( ( long ) Pointer . Unbox ( field . GetValue ( o ) ) ) )
540
+ : ( ( o , w ) => w . WriteLong ( fieldName , ( long ) Pointer . Unbox ( field . GetValue ( o ) ) ) ) ;
541
+
542
+ readAction = raw
543
+ ? ( BinaryReflectiveReadAction ) ( ( o , r ) =>
544
+ field . SetValue ( o , Pointer . Box ( ( void * ) r . GetRawReader ( ) . ReadLong ( ) , field . FieldType ) ) )
545
+ : ( ( o , r ) => field . SetValue ( o , Pointer . Box ( ( void * ) r . ReadLong ( fieldName ) , field . FieldType ) ) ) ;
546
+ }
513
547
else
514
548
{
515
549
writeAction = raw ? GetRawWriter ( field , MthdWriteObjRaw ) : GetWriter ( field , MthdWriteObj ) ;
@@ -561,8 +595,7 @@ private static bool IsTimestamp(FieldInfo field, bool forceTimestamp, bool raw)
561
595
/// Gets the reader with a specified write action.
562
596
/// </summary>
563
597
private static BinaryReflectiveWriteAction GetWriter < T > ( FieldInfo field ,
564
- Expression < Action < string , IBinaryWriter , T > > write ,
565
- bool convertFieldValToObject = false )
598
+ Expression < Action < string , IBinaryWriter , T > > write )
566
599
{
567
600
Debug . Assert ( field != null ) ;
568
601
Debug . Assert ( field . DeclaringType != null ) ; // non-static
@@ -573,8 +606,10 @@ private static BinaryReflectiveWriteAction GetWriter<T>(FieldInfo field,
573
606
var targetParamConverted = Expression . Convert ( targetParam , field . DeclaringType ) ;
574
607
Expression fldExpr = Expression . Field ( targetParamConverted , field ) ;
575
608
576
- if ( convertFieldValToObject )
577
- fldExpr = Expression . Convert ( fldExpr , typeof ( object ) ) ;
609
+ if ( field . FieldType != typeof ( T ) )
610
+ {
611
+ fldExpr = Expression . Convert ( fldExpr , typeof ( T ) ) ;
612
+ }
578
613
579
614
// Call Writer method
580
615
var writerParam = Expression . Parameter ( typeof ( IBinaryWriter ) ) ;
@@ -589,8 +624,7 @@ private static BinaryReflectiveWriteAction GetWriter<T>(FieldInfo field,
589
624
/// Gets the reader with a specified write action.
590
625
/// </summary>
591
626
private static BinaryReflectiveWriteAction GetRawWriter < T > ( FieldInfo field ,
592
- Expression < Action < IBinaryRawWriter , T > > write ,
593
- bool convertFieldValToObject = false )
627
+ Expression < Action < IBinaryRawWriter , T > > write )
594
628
{
595
629
Debug . Assert ( field != null ) ;
596
630
Debug . Assert ( field . DeclaringType != null ) ; // non-static
@@ -601,8 +635,8 @@ private static BinaryReflectiveWriteAction GetRawWriter<T>(FieldInfo field,
601
635
var targetParamConverted = Expression . Convert ( targetParam , field . DeclaringType ) ;
602
636
Expression fldExpr = Expression . Field ( targetParamConverted , field ) ;
603
637
604
- if ( convertFieldValToObject )
605
- fldExpr = Expression . Convert ( fldExpr , typeof ( object ) ) ;
638
+ if ( field . FieldType != typeof ( T ) )
639
+ fldExpr = Expression . Convert ( fldExpr , typeof ( T ) ) ;
606
640
607
641
// Call Writer method
608
642
var writerParam = Expression . Parameter ( typeof ( IBinaryWriter ) ) ;
@@ -677,7 +711,9 @@ private static BinaryReflectiveReadAction GetReader<T>(FieldInfo field,
677
711
Expression readExpr = Expression . Invoke ( read , fldNameParam , readerParam ) ;
678
712
679
713
if ( typeof ( T ) != field . FieldType )
714
+ {
680
715
readExpr = Expression . Convert ( readExpr , field . FieldType ) ;
716
+ }
681
717
682
718
// Assign field value
683
719
var targetParam = Expression . Parameter ( typeof ( object ) ) ;
0 commit comments