protected internal void EmitLdelemHelper(Type elementType)
{
OpCode op;
if (elementType.IsPrimitive)
{
switch (Type.GetTypeCode(elementType))
{
case TypeCode.SByte:
case TypeCode.Boolean:
op = OpCodes.Ldelem_I1;
break;
case TypeCode.Byte:
op = OpCodes.Ldelem_U1;
break;
case TypeCode.Int16:
op = OpCodes.Ldelem_I2;
break;
case TypeCode.UInt16:
case TypeCode.Char:
op = OpCodes.Ldelem_U2;
break;
case TypeCode.Int32:
op = OpCodes.Ldelem_I4;
break;
case TypeCode.UInt32:
op = OpCodes.Ldelem_U4;
break;
case TypeCode.Int64:
case TypeCode.UInt64:
op = OpCodes.Ldelem_I8;
break;
case TypeCode.Single:
op = OpCodes.Ldelem_R4;
break;
case TypeCode.Double:
op = OpCodes.Ldelem_R8;
break;
default:
throw new NotSupportedException();
}
}
else if (elementType.IsValueType)
{
IL.Emit(OpCodes.Ldelema, elementType);
IL.Emit(OpCodes.Ldobj, elementType);
return;
}
else
op = OpCodes.Ldelem_Ref;
IL.Emit(op);
}