Example #1
0
 public void ShouldReturnSameInstanceOfIntParserWhenCalledTwice()
 {
     var parsers = new ArgumentParsers();
     var parser1 = parsers.GetParser(DataType.Integer);
     var parser2 = parsers.GetParser(DataType.Integer);
     Assert.AreEqual(parser1, parser2);
 }
Example #2
0
        /// <summary>
        /// Returns the value of the argument att the position of the 0-based
        /// <paramref name="index"/> as an integer.
        /// </summary>
        /// <param name="arguments">The list of function arguments where our input to parse is.</param>
        /// <param name="index">The index of the arguments to try to parse to an integer.</param>
        /// <returns>Value of the argument as an integer.</returns>
        /// <exception cref="ExcelErrorValueException"></exception>
        protected int ArgToInt(IEnumerable <FunctionArgument> arguments, int index)
        {
            var val = arguments.ElementAt(index).ValueFirst;

            if (val == null)
            {
                return(0);
            }
            return((int)_argumentParsers.GetParser(DataType.Integer).Parse(val));
        }
Example #3
0
        /// <summary>
        /// If the argument is a boolean value its value will be returned.
        /// If the argument is an integer value, true will be returned if its
        /// value is not 0, otherwise false.
        /// </summary>
        /// <param name="arguments"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        protected bool ArgToBool(IEnumerable <FunctionArgument> arguments, int index)
        {
            var obj = arguments.ElementAt(index).Value ?? string.Empty;

            return((bool)_argumentParsers.GetParser(DataType.Boolean).Parse(obj));
        }