示例#1
0
        void ExternalVariableTest()
        {
            var srm = new ScriptRunningMachine();

            srm["a"] = 10;
            srm.Run("var b = a + 20; ");

            TestCaseAssertion.AssertEquals(srm["b"], 30d);
        }
示例#2
0
        public void ExtendedObjectValue()
        {
            var extObj = new MyObjectValue();

            SRM["extObj"] = extObj;

            SRM.Run("extObj.testProp = 'a';");
            TestCaseAssertion.AssertTrue(extObj.ValueSetted);              // true
            TestCaseAssertion.AssertTrue(!extObj.ValueGetted);             // false

            SRM.Run("var a = extObj.testProp;");
            TestCaseAssertion.AssertTrue(extObj.ValueSetted);              // true
            TestCaseAssertion.AssertTrue(extObj.ValueGetted);              // true

            extObj = new MyObjectValue();

            //SRM.Run("extObj.testProp = 'a';");
            TestCaseAssertion.AssertTrue(!extObj.ValueSetted);             // true
            TestCaseAssertion.AssertTrue(!extObj.ValueGetted);             // false
        }
示例#3
0
        public void ExtendedVariableAccessor()
        {
            var srm = new ScriptRunningMachine();

            var ctx = srm.CreateContext();

            ctx.ExternalVariableGetter = (id) =>
            {
                if (id.StartsWith("$"))
                {
                    return(id.Substring(1));
                }
                else
                {
                    return(null);
                }
            };

            string result = Convert.ToString(srm.CalcExpression("$A1", ctx));

            TestCaseAssertion.AssertEquals(result, "A1");
        }