示例#1
0
        protected SXLexemVariable OnFunctionExecuting(SXLexemFunction function)
        {
            Func<int, int> getindex = i => (int)(function.Arguments[i].Calculate(_environment).Value as SXLexemNumber).Value;
            Func<int, Value.ValueType> gettype = i => Value.ParseValueType((function.Arguments[i].Calculate(_environment).Value as SXLexemText).Value);

            if (function.Name.Equals("rowcol", StringComparison.InvariantCultureIgnoreCase) || function.Name.Equals("rc", StringComparison.InvariantCultureIgnoreCase))
            {
                #region Get the Value on the exact Row and Column
                if (function.Arguments.Count == 2)
                    return this.GetValue(getindex(0), getindex(1));
                else if (function.Arguments.Count == 3)
                    return this.GetValue(getindex(0), getindex(1), gettype(2));
                #endregion
            }

            if (function.Name.Equals("cell", StringComparison.InvariantCultureIgnoreCase) || function.Name.Equals("c", StringComparison.InvariantCultureIgnoreCase))
            {
                #region Get the Value on the relative [Row] (row is optional) and Column
                if (function.Arguments.Count == 1)
                    return this.GetValue(_row, getindex(0));
                else if (function.Arguments.Count == 2)
                {
                    var second = function.Arguments[1].Calculate(_environment).Value;
                    if (second.Type == SXLexemValue.ValueType.Number)
                        return this.GetValue(_row + getindex(0), (int)(second as SXLexemNumber).Value);
                    else
                        return this.GetValue(_row, getindex(0), Value.ParseValueType((second as SXLexemText).Value));
                }
                else if (function.Arguments.Count == 3)
                    return this.GetValue(_row + getindex(0), getindex(1), gettype(2));
                #endregion
            }

            if (function.Name.Equals("getdate", StringComparison.InvariantCultureIgnoreCase))
            {
                if (function.Arguments.Count == 1)
                    return this.GetValue(_row, getindex(0), Value.ValueType.Date);
                else if (function.Arguments.Count == 2)
                    return this.GetValue(_row + getindex(0), getindex(1), Value.ValueType.Date);
            }

            if (function.Name.Equals("getnumber", StringComparison.InvariantCultureIgnoreCase))
            {
                if (function.Arguments.Count == 1)
                    return this.GetValue(_row, getindex(0), Value.ValueType.Number);
                else if (function.Arguments.Count == 2)
                    return this.GetValue(_row + getindex(0), getindex(1), Value.ValueType.Number);
            }

            if (function.Name.Equals("gettext", StringComparison.InvariantCultureIgnoreCase))
            {
                if (function.Arguments.Count == 1)
                    return this.GetValue(_row, getindex(0), Value.ValueType.Text);
                else if (function.Arguments.Count == 2)
                    return this.GetValue(_row + getindex(0), getindex(1), Value.ValueType.Text);
            }

            throw new CursorException(String.Format("Expression Function not recognized: {0}", function.Name));
        }
示例#2
0
        protected SXLexemVariable OnFunctionExecuting(SXLexemFunction function)
        {
            Func <int, int>             getindex = i => (int)(function.Arguments[i].Calculate(_environment).Value as SXLexemNumber).Value;
            Func <int, Value.ValueType> gettype  = i => Value.ParseValueType((function.Arguments[i].Calculate(_environment).Value as SXLexemText).Value);

            if (function.Name.Equals("rowcol", StringComparison.InvariantCultureIgnoreCase) || function.Name.Equals("rc", StringComparison.InvariantCultureIgnoreCase))
            {
                #region Get the Value on the exact Row and Column
                if (function.Arguments.Count == 2)
                {
                    return(this.GetValue(getindex(0), getindex(1)));
                }
                else if (function.Arguments.Count == 3)
                {
                    return(this.GetValue(getindex(0), getindex(1), gettype(2)));
                }
                #endregion
            }

            if (function.Name.Equals("cell", StringComparison.InvariantCultureIgnoreCase) || function.Name.Equals("c", StringComparison.InvariantCultureIgnoreCase))
            {
                #region Get the Value on the relative [Row] (row is optional) and Column
                if (function.Arguments.Count == 1)
                {
                    return(this.GetValue(_row, getindex(0)));
                }
                else if (function.Arguments.Count == 2)
                {
                    var second = function.Arguments[1].Calculate(_environment).Value;
                    if (second.Type == SXLexemValue.ValueType.Number)
                    {
                        return(this.GetValue(_row + getindex(0), (int)(second as SXLexemNumber).Value));
                    }
                    else
                    {
                        return(this.GetValue(_row, getindex(0), Value.ParseValueType((second as SXLexemText).Value)));
                    }
                }
                else if (function.Arguments.Count == 3)
                {
                    return(this.GetValue(_row + getindex(0), getindex(1), gettype(2)));
                }
                #endregion
            }

            if (function.Name.Equals("getdate", StringComparison.InvariantCultureIgnoreCase))
            {
                if (function.Arguments.Count == 1)
                {
                    return(this.GetValue(_row, getindex(0), Value.ValueType.Date));
                }
                else if (function.Arguments.Count == 2)
                {
                    return(this.GetValue(_row + getindex(0), getindex(1), Value.ValueType.Date));
                }
            }

            if (function.Name.Equals("getnumber", StringComparison.InvariantCultureIgnoreCase))
            {
                if (function.Arguments.Count == 1)
                {
                    return(this.GetValue(_row, getindex(0), Value.ValueType.Number));
                }
                else if (function.Arguments.Count == 2)
                {
                    return(this.GetValue(_row + getindex(0), getindex(1), Value.ValueType.Number));
                }
            }

            if (function.Name.Equals("gettext", StringComparison.InvariantCultureIgnoreCase))
            {
                if (function.Arguments.Count == 1)
                {
                    return(this.GetValue(_row, getindex(0), Value.ValueType.Text));
                }
                else if (function.Arguments.Count == 2)
                {
                    return(this.GetValue(_row + getindex(0), getindex(1), Value.ValueType.Text));
                }
            }

            throw new CursorException(String.Format("Expression Function not recognized: {0}", function.Name));
        }