Ejemplo n.º 1
0
        /// <summary>
        /// Converts a parameter to an integer
        /// </summary>
        /// <param name="index">Index of parameter to convert</param>
        /// <returns></returns>
        public int ToInt(int index)
        {
            double?v = ConConverter.ToDouble(this[index]);

            if (!v.HasValue)
            {
                Command.ThrowNaNError(this[index], ErrorCode.NOT_A_NUMBER);
                throw new InvalidCastException("NaN");
            }

            if (Math.Round(v.Value) != v.Value)
            {
                Command.ThrowNoFloatsAllowedError(v.Value, ErrorCode.NUMBER_NOT_INTEGER);
                throw new InvalidCastException("Not an integer");
            }

            try
            {
                return((int)Math.Round(v.Value));
            }
            catch (Exception)
            {
                Command.ThrowNoFloatsAllowedError(v.Value, ErrorCode.NUMBER_NOT_INTEGER);
                throw new InvalidCastException("Conversion not possible");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts a parameter to a double
        /// </summary>
        /// <param name="index">Index of parameter to convert</param>
        /// <returns></returns>
        public double ToDouble(int index)
        {
            double?v = ConConverter.ToDouble(this[index]);

            if (!v.HasValue)
            {
                Command.ThrowNaNError(this[index], ErrorCode.NOT_A_NUMBER);
                throw new InvalidCastException("NaN");
            }

            return(v.Value);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Checks whether an argument can be represented as a double
 /// </summary>
 /// <param name="index">Index of parameter to check</param>
 /// <returns></returns>
 public bool IsDouble(int index)
 {
     return(ConConverter.ToDouble(this[index]).HasValue);
 }