• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# NCalc.Expression类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



Expression类属于NCalc命名空间,在下文中一共展示了Expression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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


示例3: 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


示例4: 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


示例5: 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


示例6: 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


示例7: 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


示例8: Evaluate

        public override Value Evaluate(FSharpList<Value> args)
        {
            var e = new Expression(Formula);

            var functionLookup = new Dictionary<string, Value>();

            foreach (var arg in args.Select((arg, i) => new { Value = arg, Index = i }))
            {
                var parameter = InPortData[arg.Index].NickName;
                if (arg.Value.IsFunction)
                    functionLookup[parameter] = arg.Value;
                else
                    e.Parameters[parameter] = ((Value.Number)arg.Value).Item;
            }

            e.EvaluateFunction += delegate(string name, FunctionArgs fArgs)
            {
                if (functionLookup.ContainsKey(name))
                {
                    var func = ((Value.Function)functionLookup[name]).Item;
                    fArgs.Result = ((Value.Number)func.Invoke(
                        Utils.SequenceToFSharpList(
                            fArgs.Parameters.Select<Expression, Value>(
                                p => Value.NewNumber(Convert.ToDouble(p.Evaluate())))))).Item;
                }
                else
                {
                    fArgs.HasResult = false;
                }
            };

            return Value.NewNumber(Convert.ToDouble(e.Evaluate()));
        }
开发者ID:epeter61,项目名称:Dynamo,代码行数:33,代码来源:dynEquation.cs


示例9: 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


示例10: Evaluate

        public void Evaluate(Expression exp, Expression derExp, double a, double b, double tolerance)
        {
            addToLog("Starting Newton Method");
            double expX, derExpX, result;
            double current = a;
            double previous = 0;

            while (true)
            {
                iteration++;
                // Functions
                expX = evaluate(exp, current);
                derExpX = evaluate(derExp, current);
                result = current - (expX / derExpX);

                // log
                addToLog(newLine + "Iteration: " + iteration);
                addToLog("F(x)= " + RoundDigit(expX, 4) + tab
                    + "F'(x)= " + RoundDigit(derExpX, 4) + tab
                    + "x= " + RoundDigit(result, 4));

                // swaps
                previous = current;
                current = result;

                bool withinTolerance = inTolerance(tolerance, previous, current);
                if (withinTolerance)
                    break;
            }
            addToLog("ROOT FOUND: " + result);
        }
开发者ID:patrick-hill,项目名称:NU_MAT320_AIOCalulator,代码行数:31,代码来源:Newton.cs


示例11: 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


示例12: textBox_TextChanged

        private void textBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            var textBox = sender as TextBox;

            if (textBox != null)
            {
                if (textBox.Text != "")
                {
                    expression = new Expression(textBox.Text);

                    var paras = GetParametersInExpression(textBox.Text).Distinct().ToList();

                    if (paras.Any())
                    {
                        RemoveAllInputPortsFromNode(paras);

                        var filteredParas = paras.Where(parameter => InputPorts.All(p => p.Name != parameter)).ToList();

                        foreach (var parameter in filteredParas)
                            AddInputPortToNode(parameter, typeof (object));
                    }
                }
                else
                {
                    expression = null;
                    RemoveAllInputPortsFromNode();
                }
            }

            Calculate();
        }
开发者ID:tumcms,项目名称:TUM.CMS.VPLControl,代码行数:31,代码来源:ExpressionNode.cs


示例13: 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


示例14: 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


示例15: 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


示例16: RuleEngineRule

 public RuleEngineRule(string id, string name, string expression)
 {
     Id = id;
     Name = name;
     RuleExpression = expression;
     Expression = new Expression(expression);
 }
开发者ID:EmptyCubes,项目名称:More,代码行数:7,代码来源:RuleEngineRule.cs


示例17: 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


示例18: BoundInstruction

 public BoundInstruction(InstructionDefinition insn, byte[] bytes, int curOffset, SectionInfo section)
 {
     _section = section;
     _curAbsoluteOffset = curOffset + _section.SectionOffset;
     this.Instruction = insn;
     InitializeBoundData(bytes);
     _boundValues['A'] = curOffset;
     _pcRelBranchExpr = new Expression("A+o*2");
 }
开发者ID:thubble,项目名称:videocore-elf-dis,代码行数:9,代码来源:IV_BASE.cs


示例19: RegisterFunction

        /// <summary>
        /// Registers a known <see cref="IExpressionFunction"/> against the <paramref name="ncalcExpression"/>.
        /// </summary>
        /// <param name="ncalcExpression">A <see cref="NCalc.Expression"/> to register the <see cref="IExpressionFunction"/> for.</param>
        /// <param name="function">The name of the function to register.</param>
        public void RegisterFunction(Expression ncalcExpression, string function)
        {
            IExpressionFunction type = this.implementingTypes.FirstOrDefault(t => t.FunctionName.Equals(function));
            if (type == null)
            {
                throw new IndexOutOfRangeException(string.Format(ExceptionMessages.Culture, ExceptionMessages.UnknownCalculationFunction, typeof(IExpressionFunction), function));
            }

            type.Register(ncalcExpression);
        }
开发者ID:cgavieta,项目名称:WORKPAC2016-poc,代码行数:15,代码来源:CalculationFunctionRegistrar.cs


示例20: Configure

        /// <summary>
        /// Initializes this class. This must be called before calling Execute().
        /// </summary>
        public void Configure(EvaluationControlPointInput evalInput, Expression expression)
        {
            this.OutputIsValid = false;

            this.evalInput = evalInput;
            this.expression = expression;

            this.expression.EvaluateFunction += FunctionHandler;
            SetExpressionBaseParameters((EvaluationInput) evalInput);
        }
开发者ID:hedoluna,项目名称:midi-shape-shifter,代码行数:13,代码来源:EvaluationControlPointJob.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# NETRuby.NetRuby类代码示例发布时间:2022-05-26
下一篇:
C# Math.BigInteger类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap