@@ -3332,15 +3332,40 @@ private static bool EmitNewArrayInit(NewArrayExpression expr, IReadOnlyList<PE>
33323332 return true ;
33333333 }
33343334
3335- private static bool TryEmitArrayIndex ( Type exprType , ILGenerator il , ParentFlags parent , ref ClosureInfo closure )
3335+ private static bool TryEmitArrayIndex ( Type type , ILGenerator il , ParentFlags parent , ref ClosureInfo closure )
33363336 {
3337- if ( ! exprType . IsValueType )
3337+ if ( ! type . IsValueType )
3338+ {
33383339 il . Emit ( OpCodes . Ldelem_Ref ) ;
3340+ return true ;
3341+ }
3342+ if ( type == typeof ( Int32 ) )
3343+ il . Emit ( OpCodes . Ldelem_I4 ) ;
3344+ else if ( type == typeof ( Int64 ) )
3345+ il . Emit ( OpCodes . Ldelem_I8 ) ;
3346+ else if ( type == typeof ( Int16 ) )
3347+ il . Emit ( OpCodes . Ldelem_I2 ) ;
3348+ else if ( type == typeof ( SByte ) )
3349+ il . Emit ( OpCodes . Ldelem_I1 ) ;
3350+ else if ( type == typeof ( Single ) )
3351+ il . Emit ( OpCodes . Ldelem_R4 ) ;
3352+ else if ( type == typeof ( Double ) )
3353+ il . Emit ( OpCodes . Ldelem_R8 ) ;
3354+ else if ( type == typeof ( IntPtr ) )
3355+ il . Emit ( OpCodes . Ldelem_I ) ;
3356+ else if ( type == typeof ( UIntPtr ) )
3357+ il . Emit ( OpCodes . Ldelem_I ) ;
3358+ else if ( type == typeof ( Byte ) )
3359+ il . Emit ( OpCodes . Ldelem_U1 ) ;
3360+ else if ( type == typeof ( UInt16 ) )
3361+ il . Emit ( OpCodes . Ldelem_U2 ) ;
3362+ else if ( type == typeof ( UInt32 ) )
3363+ il . Emit ( OpCodes . Ldelem_U4 ) ;
33393364 else if ( ( parent & ( ParentFlags . MemberAccess | ParentFlags . Call ) ) == 0 )
3340- il . Emit ( OpCodes . Ldelem , exprType ) ;
3365+ il . Emit ( OpCodes . Ldelem , type ) ;
33413366 else
33423367 {
3343- il . Emit ( OpCodes . Ldelema , exprType ) ;
3368+ il . Emit ( OpCodes . Ldelema , type ) ;
33443369 closure . LastEmitIsAddress = true ;
33453370 }
33463371 return true ;
@@ -3917,10 +3942,31 @@ private static bool TryEmitIndexAssign(IndexExpression indexExpr, Type instType,
39173942
39183943 if ( indexExpr . Arguments . Count == 1 ) // one dimensional array
39193944 {
3920- if ( elementType . IsValueType )
3921- il . Emit ( OpCodes . Stelem , elementType ) ;
3922- else
3945+ if ( ! elementType . IsValueType )
3946+ {
39233947 il . Emit ( OpCodes . Stelem_Ref ) ;
3948+ return true ;
3949+ }
3950+
3951+ if ( elementType == typeof ( Int32 ) )
3952+ il . Emit ( OpCodes . Stelem_I4 ) ;
3953+ else if ( elementType == typeof ( Int64 ) )
3954+ il . Emit ( OpCodes . Stelem_I8 ) ;
3955+ else if ( elementType == typeof ( Int16 ) )
3956+ il . Emit ( OpCodes . Stelem_I2 ) ;
3957+ else if ( elementType == typeof ( SByte ) )
3958+ il . Emit ( OpCodes . Stelem_I1 ) ;
3959+ else if ( elementType == typeof ( Single ) )
3960+ il . Emit ( OpCodes . Stelem_R4 ) ;
3961+ else if ( elementType == typeof ( Double ) )
3962+ il . Emit ( OpCodes . Stelem_R8 ) ;
3963+ else if ( elementType == typeof ( IntPtr ) )
3964+ il . Emit ( OpCodes . Stelem_I ) ;
3965+ else if ( elementType == typeof ( UIntPtr ) )
3966+ il . Emit ( OpCodes . Stelem_I ) ;
3967+ else
3968+ il . Emit ( OpCodes . Stelem , elementType ) ;
3969+ //todo: UInt64 as there is no OpCodes? Stelem_Ref?
39243970 return true ;
39253971 }
39263972
0 commit comments