当前位置: 首页>>代码示例>>C#>>正文


C# Expression.Evaluate方法代码示例

本文整理汇总了C#中NCalc.Expression.Evaluate方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.Evaluate方法的具体用法?C# Expression.Evaluate怎么用?C# Expression.Evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NCalc.Expression的用法示例。


在下文中一共展示了Expression.Evaluate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UnaryEvaluate

        public static IEnumerable<double> UnaryEvaluate(this string expression, string parameterName, Func<double[]> parameterFunc) {
            expression.ShouldNotBeWhiteSpace("expression");
            var expr = new NCalc.Expression(expression, EvaluateOptions.IgnoreCase | EvaluateOptions.IterateParameters);
            expr.Parameters["x"] = parameterFunc();

            return ((IList)expr.Evaluate()).Cast<object>().Select(result => result.AsDouble());
        }
开发者ID:debop,项目名称:NFramework,代码行数:7,代码来源:CalcExpression.cs

示例2: Test1

        public void Test1()
        {
            var expr = new Expression("cos([t])", EvaluateOptions.IgnoreCase);

            expr.Parameters["t"] = 0;
            var result = expr.Evaluate();

            Assert.AreEqual(1d, result);

            expr.Parameters["t"] = Math.PI;
            result = expr.Evaluate();

            Assert.AreEqual(-1d, result);
        }
开发者ID:JFFby,项目名称:KSKR,代码行数:14,代码来源:NCalcTest.cs

示例3: DynamicParametersTest

        public void DynamicParametersTest() {
            var expr = new Expression("Round(Pow(Pi, 2) + Pow(Pi, 2) + x, 2)");

            expr.Parameters["Pi2"] = new Expression("Pi * Pi");
            expr.Parameters["x"] = 10;

            expr.EvaluateParameter += delegate(string name, ParameterArgs args) {
                                          if(name == "Pi")
                                              args.Result = Math.PI;
                                      };

            Console.WriteLine("value = " + expr.Evaluate().AsDouble());
            expr.Evaluate().AsDouble().Should().Be.GreaterThan(0);
        }
开发者ID:debop,项目名称:NFramework,代码行数:14,代码来源:NCalcFixture.cs

示例4: HandleMessage

        public void HandleMessage(string command, string args, object clientData, Action<string, AnswerBehaviourType> sendMessageFunc)
        {
            Expression expr = new Expression(args);
            var exprAnswer = expr.Evaluate();
            string messageAuthor = string.Empty;
            string answer = string.Empty;
            

            var skypeData = clientData as ISkypeData;
            if (skypeData!=null)
            {
                messageAuthor = skypeData.FromName;
            }

            if (!string.IsNullOrEmpty(messageAuthor))
            {
                answer = string.Format("Мсье {0}, ответ равен : {1}", messageAuthor, exprAnswer);
            }
            else
            {
                answer = string.Format("Ответ равен : {0}", exprAnswer);
            }

            sendMessageFunc(answer, AnswerBehaviourType.Text);
            
        }
开发者ID:fnsmddlk,项目名称:HelloBot,代码行数:26,代码来源:Calculator.cs

示例5: Loading

        /// <summary>
        /// Setts up the Arcade.
        /// </summary>
        /// <param name='screen'>
        /// Screen.
        /// </param>
        public static void Loading(int arcadeOrArendelle)
        {
            Console.Title = " ";
            Console.Clear ();

            if (arcadeOrArendelle == 0) {

                string loadingText  = "A R C A D E  I D E  " + InterfaceView.ArcadeVersion () + " ";
                string show = "";

                for (int i = 0; i < loadingText.Length; i++) {

                    Console.Clear ();
                    show = show + loadingText[i].ToString();
                    InterfaceView.CenterWriter (-1, show);
                    System.Threading.Thread.Sleep (50);
                }

            } else {

                InterfaceView.CenterWriter (-1, "L O A D I N G  ");

            }

            // running a very easy problem with NCalc
            // so the runtime loads NCalc ( if we don't
            // do the very first Spaces.calculate will
            // take seconds!
            Expression vari = new Expression ("2*3+1");
            vari.Evaluate ();

            if (arcadeOrArendelle == 0)
                System.Threading.Thread.Sleep (1000);
        }
开发者ID:karyfoundation,项目名称:arcade,代码行数:40,代码来源:Loading.cs

示例6: buttonTest_Click

        private void buttonTest_Click(object sender, EventArgs e)
        {
            float textValue;
            float start;
            float end;
            try
            {
                textValue = float.Parse(textBoxTestInput.Text);
                start = float.Parse(textBoxRangeStart.Text);
                end = float.Parse(textBoxRangeEnd.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("不正确的输入", "Error");
                return;
            }

            if (textValue < start || textValue > end)
            {
                labelTestResult.Text = "not in range, did not cal";
                return;
            }

            String realExp = textBoxExp.Text.Replace("t", textBoxTestInput.Text);
            try
            {
                Expression ex = new Expression(realExp);
                labelTestResult.Text = ex.Evaluate().ToString();
            }
            catch(Exception excep)
            {
                MessageBox.Show(excep.ToString(), "Error");
            }
        }
开发者ID:tcsthyc,项目名称:grip_new,代码行数:34,代码来源:FunctionMaker.cs

示例7: Eval

 public static bool Eval(object parameterValue, string strExpression)
 {
     Expression expression = new Expression(strExpression);
     expression.Parameters["p"] = parameterValue;
     bool flag = true;
     return flag.Equals(expression.Evaluate());
 }
开发者ID:vanloc0301,项目名称:mychongchong,代码行数:7,代码来源:XMLSQLConditionsHelper.cs

示例8: CalculateTimeSliceTable

        public static EDataTable CalculateTimeSliceTable()
        {
            foreach (var simpleFormulaModel in _timeSliceFormulas)
            {
                _timeSliceTable.Columns.Add(simpleFormulaModel.Name, typeof(double));

                foreach (DataRow row in _timeSliceTable.Rows)
                {
                    _expression = new Expression(simpleFormulaModel.Formula);
                    foreach (var column in simpleFormulaModel.UsedColumns)
                    {
                        double rowValue;
                        if (double.TryParse(row[column].ToString(), out rowValue))
                            _expression.Parameters[column] = rowValue;
                    }
                    try
                    {
                        var result = _expression.Evaluate();
                        row[simpleFormulaModel.Name] = result;
                    }
                    catch (Exception)
                    {
                        row[simpleFormulaModel.Name] = -1;
                    }
                }
            }
            return _timeSliceTable;
        }
开发者ID:Ktullhu,项目名称:DataAdmin,代码行数:28,代码来源:CustomFormulaManager.cs

示例9: FunctionConverter

        /// <summary>
        /// Creates a new instance of the FunctionConverterClass
        /// </summary>
        /// <param name="function">The function as a string</param>
        /// <param name="length"></param>
        /// <param name="interval"></param>
        /// <param name="type">The type of data the function represents</param>
        public FunctionConverter(String function, double length, double interval, int type)
        {
            int size = Convert.ToInt32(length / interval) + 1;

            //_time = new List<double>();
            //_value = new List<double>();
            _time = new double[size];
            _value = new double[size];

            for (int i = 0; i < size; i++)
            {
                _time[i] = (i * interval);
                String TempString = function.Replace("x", System.Convert.ToString(_time[i]));
                Expression e = new Expression(TempString);
                try
                {
                    object result = e.Evaluate();
                    _value[i] = (Convert.ToDouble(result));
                }
                catch(Exception a)
                {
                    MessageBox.Show("Error caught: " + a.Message);
                }
            }

            SetProperties((FunctionType)type);
        }
开发者ID:MDSchechtman,项目名称:Aerotech-Motor-Sizer,代码行数:34,代码来源:FunctionConverter.cs

示例10: btnCalculate_Click

        private void btnCalculate_Click(object sender, EventArgs e)
        {
            #if !DEBUG
            try
            {
            #endif
            string format = txtFormat.Text;

            IEnumerable<string> expressions = GetExpressions(format);

            foreach (string expression in expressions)
            {
                Expression expr = new Expression(MakeParseable(expression)) { Parameters = GetParameters() };

                string result = expr.Evaluate().ToString();

                format = format.Replace(expression, result);
            }

            txtCalculated.Text = format;

            #if !DEBUG
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            #endif
        }
开发者ID:crdx,项目名称:Calc,代码行数:29,代码来源:MainForm.cs

示例11: IterationTest

        public void IterationTest() {
            var expr = new Expression("Sin(x)", EvaluateOptions.IgnoreCase | EvaluateOptions.IterateParameters);
            expr.Parameters["x"] = Enumerable.Range(0, 1000).Select(x => x / Math.PI).ToArray();

            foreach(var result in (IList)expr.Evaluate())
                Console.WriteLine(result.AsDouble());
        }
开发者ID:debop,项目名称:NFramework,代码行数:7,代码来源:NCalcFixture.cs

示例12: PlusMinusTest

        public void PlusMinusTest() {
            var expr = new Expression("2 + 3 * 5");
            expr.Evaluate().Should().Be(17);

            expr = new Expression("48/(2*(9+3))");
            expr.Evaluate().Should().Be(2d);
        }
开发者ID:debop,项目名称:NFramework,代码行数:7,代码来源:NCalcFixture.cs

示例13: RulesToDouble

        /// <summary>
        /// 公式轉數值
        /// </summary>
        /// <param name="rules">公式</param>
        /// <param name="array">陣列</param>
        /// <returns>數值</returns>
        public static double RulesToDouble(String rules, ref double[] array)
        {
            if (String.IsNullOrEmpty(rules))
                return 0.0d;

            String rule = rules
               .Replace("@3", array[3].ToString())
               .Replace("@4", array[4].ToString())
               .Replace("@5", array[5].ToString())
               .Replace("@6", array[6].ToString())
               .Replace("@7", array[7].ToString())
               .Replace("@8", array[8].ToString())
               .Replace("@9", array[9].ToString())
               .Replace("@10", array[10].ToString())
               .Replace("@11", array[11].ToString())
               .Replace("@12", array[12].ToString())
               .Replace("@2", array[2].ToString())
               .Replace("@1", array[1].ToString())
               .Replace("@0", array[0].ToString());

            try
            {
                Expression number = new Expression(rule);
                return Double.Parse(number.Evaluate().ToString());
            }
            catch
            {

            }
            return 0.0d;
        }
开发者ID:sh932111,项目名称:BrainProject,代码行数:37,代码来源:Rules.cs

示例14: Page_Load

 protected void Page_Load(object sender, EventArgs e)
 {
     string equation = getRandomEquation(5);
     lblRandomEquation.Text = equation;
     NCalc.Expression ex = new NCalc.Expression(equation);
     lblResult.Text = (ex.Evaluate().ToString());
 }
开发者ID:tjaank,项目名称:TestCSharpProject,代码行数:7,代码来源:Rohit.aspx.cs

示例15: Execute

 public async void Execute(Dictionary<string, object> context)
 {
     Update update = context["update"] as Update;
     CommandEntity commandEntity = context["commandEntity"] as CommandEntity;
     Expression mathExpression=new Expression(commandEntity.Parameter,EvaluateOptions.IgnoreCase);
     var message = mathExpression.Evaluate().ToString();
     await _bot.SendTextMessage(update.Message.Chat.Id,message);
 }
开发者ID:AlekseyKovalevsky,项目名称:BecomeSolidInCSharp,代码行数:8,代码来源:AiCalcCommand.cs


注:本文中的NCalc.Expression.Evaluate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。