Beispiel #1
0
        public void ParseEvaluatedEquations()
        {
            try
            {
                var query = from e in _equations
                            where e.GetCellValue() != null
                            select e;

                foreach (var equation in query)
                {
                    if (equation.GetCellValue() != null)
                    {
                        var query2 = from e in _equations
                                     where e.GetName() != equation.GetName() &&
                                     e.GetCellValue() == null
                                     select e;

                        foreach (var equation2 in query2)
                        {
                            //equation2._expression = equation2._expression.Replace(equation.GetName(), equation.GetCellValue().ToString());
                            CalcInfoEventArgs e = new CalcInfoEventArgs(
                                equation.GetName(),
                                equation.GetCellValue()
                                );
                            equation2.EvaluateExpression(e);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("spreadsheetinJson", ex);
            }
        }
Beispiel #2
0
        //private static string Expression { get; set; }

        public void EvaluateExpression(CalcInfoEventArgs e)
        {
            try
            {
                _expression = _expression.Replace(e._fieldName.ToString(), e._value.ToString());



                if (Regex.IsMatch(_expression, @"\$[A-Z]{1,2}[0-9]{1,9999}") == false)
                {
                    Expression <Func <double, double> > expr = x => x * x;

                    /*
                     * NReco.Linq.LambdaParser.CompiledExpression compiledExpr;
                     *
                     * var linqExpr = NReco.Linq.LambdaParser.Parse(_expression.ToString());
                     *
                     * compiledExpr = new NReco.Linq.LambdaParser.CompiledExpression()
                     * {
                     *  Parameters = NReco.Linq.LambdaParser.GetExpressionParameters(linqExpr)
                     * };
                     * var lambdaExpr = Expression.Lambda(linqExpr, compiledExpr.Parameters);
                     * compiledExpr.Lambda = lambdaExpr.Compile();
                     */

                    _evaluator = expr.Compile();

                    object value = _evaluator(2);
                    string name  = value.GetType().Name;

                    if (value == null)
                    {
                        _evaluation = null;
                        return;
                    }
                    if (name == "Int32")
                    {
                        _evaluation = Convert.ToInt32(value);
                    }
                    else
                    {
                        _evaluation = (double)value;
                    }


                    //return _expression;
                }
            }
            catch (Exception ex)
            {
                throw new Exception("evaluator", ex);
            }
        }
Beispiel #3
0
 public void ParseExpression(object sender, CalcInfoEventArgs e)
 {
     EvaluateExpression(e);
 }