ExcelFormulaParser.Engine.Excel.Functions.IntArgumentParser.Parse C# (CSharp) Method

Parse() public method

public Parse ( object obj ) : object
obj object
return object
        public override object Parse(object obj)
        {
            Require.That(obj).Named("argument").IsNotNull();
            int result;
            var objType = obj.GetType();
            if (objType == typeof(int))
            {
                return (int)obj;
            }
            if (objType == typeof(double) || objType == typeof(decimal))
            {
                return Convert.ToInt32(obj);
            }
            if (!int.TryParse(obj.ToString(), out result))
            {
                throw new ExcelFunctionException("Could not parse " + obj.ToString() + " to int", ExcelErrorCodes.Value);
            }
            return result;
        }

Usage Example

 public void IntParserShouldConvertToAnInteger()
 {
     var parser = new IntArgumentParser();
     var result = parser.Parse(3);
     Assert.AreEqual(3, result);
 }
All Usage Examples Of ExcelFormulaParser.Engine.Excel.Functions.IntArgumentParser::Parse
IntArgumentParser