@@ -84,13 +84,9 @@ private static Expression GenerateMethodBody(IExpression operation, ParameterExp
8484 }
8585 case ConstantExpression constantExpression :
8686 {
87- #if RECLASSNET64
88- // long -> IntPtr
89- return Expression . Convert ( Expression . Constant ( constantExpression . Value ) , typeof ( IntPtr ) ) ;
90- #else
91- // long -> int -> IntPtr
92- return Expression . Convert ( Expression . Convert ( Expression . Constant ( constantExpression . Value ) , typeof ( int ) ) , typeof ( IntPtr ) ) ;
93- #endif
87+ var convertFn = typeof ( IntPtrExtension ) . GetRuntimeMethod ( nameof ( IntPtrExtension . From ) , new [ ] { typeof ( long ) } ) ;
88+
89+ return Expression . Call ( null , convertFn , Expression . Constant ( constantExpression . Value ) ) ;
9490 }
9591 case ReadMemoryExpression readMemoryExpression :
9692 {
@@ -101,11 +97,10 @@ private static Expression GenerateMethodBody(IExpression operation, ParameterExp
10197
10298 var callExpression = Expression . Call ( processParameter , readRemoteIntFn , argument ) ;
10399
104- #if RECLASSNET64
105- return Expression . Convert ( callExpression , typeof ( IntPtr ) ) ;
106- #else
107- return Expression . Convert ( Expression . Convert ( callExpression , typeof ( int ) ) , typeof ( IntPtr ) ) ;
108- #endif
100+ var paramType = readMemoryExpression . ByteCount == 4 ? typeof ( int ) : typeof ( long ) ;
101+ var convertFn = typeof ( IntPtrExtension ) . GetRuntimeMethod ( nameof ( IntPtrExtension . From ) , new [ ] { paramType } ) ;
102+
103+ return Expression . Call ( null , convertFn , callExpression ) ;
109104 }
110105 }
111106
0 commit comments