示例#1
0
 internal static void EmitDecimal(this ILGenerator il, decimal value)
 {
     if (Decimal.Truncate(value) == value)
     {
         if (Int32.MinValue <= value && value <= Int32.MaxValue)
         {
             int intValue = Decimal.ToInt32(value);
             il.EmitInt(intValue);
             il.EmitNew(typeof(Decimal).GetConstructor(new Type[] { typeof(int) }));
         }
         else if (Int64.MinValue <= value && value <= Int64.MaxValue)
         {
             long longValue = Decimal.ToInt64(value);
             il.EmitLong(longValue);
             il.EmitNew(typeof(Decimal).GetConstructor(new Type[] { typeof(long) }));
         }
         else
         {
             il.EmitDecimalBits(value);
         }
     }
     else
     {
         il.EmitDecimalBits(value);
     }
 }
示例#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);
            }
        }