Ejemplo n.º 1
0
        private static bool TryEmitILConstant(this ILGenerator il, object value, Type type)
        {
            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);
            }
        }