예제 #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 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");
        }