Beispiel #1
0
        /// <summary>
        /// Converts the specified values boxed type to its correpsonding integer
        /// type.
        /// </summary>
        /// <param name="Value">The value.</param>
        /// <param name="Round"></param>
        /// <returns>A boxed numeric object whos type is an integer type.</returns>
        public static object ToInteger(object Value, bool Round)
        {
            switch (LuaEmit.GetTypeCode(Value.GetType()))
            {
            case LuaEmitTypeCode.SByte:
                return(Value);

            case LuaEmitTypeCode.Int16:
                return(Value);

            case LuaEmitTypeCode.Int32:
                return(Value);

            case LuaEmitTypeCode.Int64:
                return(Value);

            case LuaEmitTypeCode.Byte:
                return(Value);

            case LuaEmitTypeCode.UInt16:
                return(Value);

            case LuaEmitTypeCode.UInt32:
                return(Value);

            case LuaEmitTypeCode.UInt64:
                return(Value);

            case LuaEmitTypeCode.Single:
                return(Round ? (int)Math.Round((float)Value) : (int)((float)Value));

            case LuaEmitTypeCode.Double:
                return(Round ? (long)Math.Round((double)Value) : (long)((double)Value));

            case LuaEmitTypeCode.Decimal:
                return(Round ? Math.Round((decimal)Value) : (decimal)Value);

            default:
                return(null);
            }
        }
Beispiel #2
0
        public static long UnboxToLong(object Value, bool Round)
        {
            switch (LuaEmit.GetTypeCode(Value.GetType()))
            {
            case LuaEmitTypeCode.SByte:
                return((long)((sbyte)Value));

            case LuaEmitTypeCode.Int16:
                return((long)((short)Value));

            case LuaEmitTypeCode.Int32:
                return((long)((int)Value));

            case LuaEmitTypeCode.Int64:
                return((long)Value);

            case LuaEmitTypeCode.Byte:
                return((long)((byte)Value));

            case LuaEmitTypeCode.UInt16:
                return((long)((ushort)Value));

            case LuaEmitTypeCode.UInt32:
                return((long)((uint)Value));

            case LuaEmitTypeCode.UInt64:
                return((long)((ulong)Value));

            case LuaEmitTypeCode.Single:
                return(Round ? (long)Math.Round((float)Value) : (long)((float)Value));

            case LuaEmitTypeCode.Double:
                return(Round ? (long)Math.Round((double)Value) : (long)((double)Value));

            case LuaEmitTypeCode.Decimal:
                return(Round ? (long)Math.Round((decimal)Value) : (long)((decimal)Value));

            default:
                return(0);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Converts the specified values boxed type to its correpsonding unsigned
        /// type.
        /// </summary>
        /// <param name="Value">The value.</param>
        /// <returns>A boxed numeric object whos type is unsigned.</returns>
        public static object ToUnsigned(object Value)
        {
            switch (LuaEmit.GetTypeCode(Value.GetType()))
            {
            case LuaEmitTypeCode.SByte:
                return((byte)((sbyte)Value));

            case LuaEmitTypeCode.Int16:
                return((ushort)((short)Value));

            case LuaEmitTypeCode.Int32:
                return((uint)((int)Value));

            case LuaEmitTypeCode.Int64:
                return((ulong)((long)Value));

            case LuaEmitTypeCode.Byte:
                return(Value);

            case LuaEmitTypeCode.UInt16:
                return(Value);

            case LuaEmitTypeCode.UInt32:
                return(Value);

            case LuaEmitTypeCode.UInt64:
                return(Value);

            case LuaEmitTypeCode.Single:
                return((UInt32)((float)Value));

            case LuaEmitTypeCode.Double:
                return((ulong)((double)Value));

            case LuaEmitTypeCode.Decimal:
                return((ulong)((decimal)Value));

            default:
                return(null);
            }
        }