コード例 #1
0
 private static void EmitDecimalBits(this ILGenerator il, decimal value)
 {
     int[] bits = Decimal.GetBits(value);
     il.EmitInt(bits[0]);
     il.EmitInt(bits[1]);
     il.EmitInt(bits[2]);
     il.EmitBoolean((bits[3] & 0x80000000) != 0);
     il.EmitByte((byte)(bits[3] >> 16));
     il.EmitNew(typeof(decimal).GetConstructor(new Type[] { typeof(int), typeof(int), typeof(int), typeof(bool), typeof(byte) }));
 }
コード例 #2
0
        internal static bool LoadObject(this ILGenerator il, object value, Type type)
        {
            if (type.IsEnum)
            {
                value = (int)value;
                type  = typeof(int);
            }

            switch (Type.GetTypeCode(type))
            {
            case TypeCode.Boolean:
                il.EmitBoolean((bool)value);
                return(true);

            case TypeCode.SByte:
                il.EmitSByte((sbyte)value);
                return(true);

            case TypeCode.Int16:
                il.EmitShort((short)value);
                return(true);

            case TypeCode.Int32:
                il.EmitInt((int)value);
                return(true);

            case TypeCode.Int64:
                il.EmitLong((long)value);
                return(true);

            case TypeCode.Single:
                il.EmitSingle((float)value);
                return(true);

            case TypeCode.Double:
                il.EmitDouble((double)value);
                return(true);

            case TypeCode.Char:
                il.EmitChar((char)value);
                return(true);

            case TypeCode.Byte:
                il.EmitByte((byte)value);
                return(true);

            case TypeCode.UInt16:
                il.EmitUShort((ushort)value);
                return(true);

            case TypeCode.UInt32:
                il.EmitUInt((uint)value);
                return(true);

            case TypeCode.UInt64:
                il.EmitULong((ulong)value);
                return(true);

            case TypeCode.Decimal:
                il.EmitDecimal((decimal)value);
                return(true);

            case TypeCode.String:
                il.EmitString((string)value);
                return(true);

            default:
                return(false);
            }
        }