コード例 #1
0
        public void RegisterExprEvalIgnoredByParent()
        {
            var             c     = new ScopeContext(new RootContext());
            object          r     = null;
            Action <object> saver = o => r = o;
            var             es    = new PlotLingoLib.Statements.ExpressionStatement(new StringValue("hi"));

            c.AddExpressionStatementEvaluationCallback(saver);
            es.Evaluate(c.Parent);
            Assert.IsNull(r, "result of running");
        }
コード例 #2
0
        public void RegisterExprEvalWorksInScope()
        {
            var             c     = new ScopeContext(new RootContext());
            object          r     = null;
            Action <object> saver = o => r = o;
            var             es    = new PlotLingoLib.Statements.ExpressionStatement(new StringValue("hi"));

            c.AddExpressionStatementEvaluationCallback(saver);
            es.Evaluate(c);
            Assert.AreEqual("hi", r, "result of running");
        }
コード例 #3
0
        /// <summary>
        /// Execute the expression list.
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public object Evaluate(IScopeContext c)
        {
            var             newcontext = new ScopeContext(c);
            object          result     = null;
            Action <object> saver      = a => { result = a; };

            newcontext.AddExpressionStatementEvaluationCallback(saver);
            try
            {
                foreach (var s in Statements)
                {
                    s.Evaluate(newcontext);
                }

                return(result);
            }
            finally
            {
                c.RemoveExpressionStatementEvaluationCallback(saver);
            }
        }