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


C# CalculationEngine.Recalculate方法代码示例

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


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

示例1: TestBatchLoad

        public void TestBatchLoad()
        {
            // Test that we can add expressions in any order
            CalculationEngine engine = new CalculationEngine();
            ExpressionContext context = new ExpressionContext();

            int interest = 2;
            context.Variables.Add("interest", interest);

            BatchLoader loader = engine.CreateBatchLoader();

            loader.Add("c", "a + b", context);
            loader.Add("a", "100 + interest", context);
            loader.Add("b", "a + 1 + a", context);
            // Test an expression with a reference in a string
            loader.Add("d", "\"str \\\" str\" + a + \"b\"", context);

            engine.BatchLoad(loader);

            int result = engine.GetResult<int>("b");
            Assert.AreEqual((100 + interest) + 1 + (100 + interest), result);

            interest = 300;
            context.Variables["interest"] = interest;
            engine.Recalculate("a");

            result = engine.GetResult<int>("b");
            Assert.AreEqual((100 + interest) + 1 + (100 + interest), result);

            result = engine.GetResult<int>("c");
            Assert.AreEqual((100 + interest) + 1 + (100 + interest) + (100 + interest), result);

            Assert.AreEqual("str \" str400b", engine.GetResult<string>("d"));
        }
开发者ID:jonimoreira,项目名称:TestTFS,代码行数:34,代码来源:CalcEngineTestFixture.cs

示例2: TestBasic

        public void TestBasic()
        {
            CalculationEngine ce = new CalculationEngine();
            ExpressionContext context = new ExpressionContext();
            VariableCollection variables = context.Variables;

            variables.Add("x", 100);
            ce.Add("a", "x * 2", context);

            variables.Add("y", 1);
            ce.Add("b", "a + y", context);

            ce.Add("c", "b * 2", context);

            ce.Recalculate("a");
            int result = ce.GetResult<int>("c");
            Assert.AreEqual(result, ((100 * 2) + 1) * 2);

            variables["x"] = 345;
            ce.Recalculate("a");
            result = ce.GetResult<int>("c");
            Assert.AreEqual(((345 * 2) + 1) * 2, result);
        }
开发者ID:jonimoreira,项目名称:TestTFS,代码行数:23,代码来源:CalcEngineTestFixture.cs

示例3: TestCircularReference1

        public void TestCircularReference1()
        {
            CalculationEngine ce = new CalculationEngine();
            ExpressionContext context = new ExpressionContext();
            VariableCollection variables = context.Variables;

            variables.Add("x", 100);
            ce.Add("a", "x * 2", context);

            variables.Add("y", 1);
            ce.Add("b", "a + y + b", context);

            ce.Recalculate("a");
        }
开发者ID:jonimoreira,项目名称:TestTFS,代码行数:14,代码来源:CalcEngineTestFixture.cs

示例4: TestWithReferenceTypes

        public void TestWithReferenceTypes()
        {
            CalculationEngine ce = new CalculationEngine();
            ExpressionContext context = new ExpressionContext();
            VariableCollection variables = context.Variables;

            variables.Add("x", "string");
            ce.Add("a", "x + \" \"", context);

            variables.Add("y", "word");
            ce.Add("b", "y", context);

            ce.Add("c", "a + b", context);

            ce.Recalculate("b", "a");

            string result = ce.GetResult<string>("c");
            Assert.AreEqual("string" + " " + "word", result);
        }
开发者ID:jonimoreira,项目名称:TestTFS,代码行数:19,代码来源:CalcEngineTestFixture.cs

示例5: TestRemove3

        public void TestRemove3()
        {
            CalculationEngine ce = new CalculationEngine();
            ExpressionContext context = new ExpressionContext();
            VariableCollection variables = context.Variables;

            ce.Add("a", "100", context);
            ce.Add("b", "200", context);
            ce.Add("c", "a + b", context);
            ce.Add("d", "300 + c", context);
            ce.Add("e", "c + d", context);

            ce.Remove("d");
            Assert.AreEqual(3, ce.Count);

            ce.Recalculate("c");
            ce.Remove("c");
            Assert.AreEqual(2, ce.Count);

            ce.Remove("a");
            Assert.AreEqual(1, ce.Count);

            ce.Remove("b");
            Assert.AreEqual(0, ce.Count);
        }
开发者ID:jonimoreira,项目名称:TestTFS,代码行数:25,代码来源:CalcEngineTestFixture.cs

示例6: TestRecalculateNonSource

        public void TestRecalculateNonSource()
        {
            // Test recalculate with a non-source
            CalculationEngine ce = new CalculationEngine();
            ExpressionContext context = new ExpressionContext();
            VariableCollection variables = context.Variables;

            variables.Add("x", 100);
            ce.Add("a", "x * 2", context);

            variables.Add("y", 1);
            ce.Add("b", "a + y", context);

            ce.Add("c", "b * 2", context);

            ce.Recalculate("a", "b");
            int result = ce.GetResult<int>("c");
            Assert.AreEqual(((100) * 2 + 1) * 2, result);
        }
开发者ID:jonimoreira,项目名称:TestTFS,代码行数:19,代码来源:CalcEngineTestFixture.cs

示例7: TestMutipleIdenticalReferences

        public void TestMutipleIdenticalReferences()
        {
            CalculationEngine ce = new CalculationEngine();
            ExpressionContext context = new ExpressionContext();
            VariableCollection variables = context.Variables;

            variables.Add("x", 100);
            ce.Add("a", "x * 2", context);

            ce.Add("b", "a + a + a", context);

            ce.Recalculate("a");
            int result = ce.GetResult<int>("b");
            Assert.AreEqual((100 * 2) * 3, result);
        }
开发者ID:jonimoreira,项目名称:TestTFS,代码行数:15,代码来源:CalcEngineTestFixture.cs

示例8: TestComplex

        public void TestComplex()
        {
            CalculationEngine ce = new CalculationEngine();

            ExpressionContext context = new ExpressionContext();

            VariableCollection variables = context.Variables;

            variables.Add("x", 100);
            ce.Add("a", "x * 2", context);

            variables.Add("y", 24);
            ce.Add("b", "y * 2", context);

            ce.Add("c", "a + b", context);

            ce.Add("d", "80", context);

            ce.Add("e", "a + b + c + d", context);

            ce.Recalculate("d");
            ce.Recalculate(new string[] {
                "a",
                "b"
            });

            int result = ce.GetResult<int>("e");
            Assert.AreEqual((100 * 2) + (24 * 2) + ((100 * 2) + (24 * 2)) + 80, result);
        }
开发者ID:jonimoreira,项目名称:TestTFS,代码行数:29,代码来源:CalcEngineTestFixture.cs


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