Пример #1
0
        public static object Evaluate(string expression, _7Sharp.AdditionalFunctionEventHandler handler)
        {
            FunctionEval functionEval = new FunctionEval(expression);

            if (handler != null)
            {
                functionEval.AdditionalFunctionEventHandler += handler;
            }
            return(functionEval.Evaluate());
        }
Пример #2
0
        public string Replace()
        {
            StringBuilder stringBuilder = new StringBuilder(this.Expression);

            for (Match match = DefinedRegex.Function.Match(this.Expression); match.Success; match = DefinedRegex.Function.Match(stringBuilder.ToString()))
            {
                int num   = 1;
                int index = match.Index + match.Length;
                while (num > 0)
                {
                    if (index >= stringBuilder.Length)
                    {
                        throw new ArgumentException("Missing ')' in Expression");
                    }
                    if (stringBuilder[index] == ')')
                    {
                        --num;
                    }
                    if (stringBuilder[index] == '(')
                    {
                        ++num;
                    }
                    ++index;
                }
                string       str          = stringBuilder.ToString(match.Index, index - match.Index);
                FunctionEval functionEval = new FunctionEval(str);
                // ISSUE: reference to a compiler-generated field
                functionEval.AdditionalFunctionEventHandler += this.AdditionalFunctionEventHandler;
                functionEval._variables = this._variables;
                stringBuilder.Replace(str, string.Concat(functionEval.Evaluate()));
            }
            for (Match match = DefinedRegex.Variable.Match(stringBuilder.ToString()); match.Success; match = DefinedRegex.Variable.Match(stringBuilder.ToString()))
            {
                stringBuilder.Replace(match.Value, string.Concat(this._variables[(object)match.Groups["Variable"].Value]));
            }
            return(stringBuilder.ToString());
        }