示例#1
0
 public override void Evaluate(IScriptContext context)
 {
     _condition.Evaluate(context);
     if ((bool)context.Result)
     {
         _statement.Evaluate(context);
     }
     else
     if (_elseStatement != null)
     {
         _elseStatement.Evaluate(context);
     }
 }
        public override void Evaluate(IScriptContext context)
        {
            var switchValue = context.Result;

            _cond.Evaluate(context);
            if (switchValue.Equals(context.Result))
            {
                _statement.Evaluate(context);
                context.SetBreak(true);
            }
            else
            {
                context.Result = switchValue;
            }
        }
示例#3
0
 public override void Evaluate(IScriptContext context)
 {
     try
     {
         _tryBlock.Evaluate(context);
     }
     catch (Exception e)
     {
         context.SetItem(_expName, e);
         _catchBlock.Evaluate(context);
     }
     finally
     {
         _finallyBlock.Evaluate(context);
     }
 }
示例#4
0
        public override void Evaluate(IScriptContext context)
        {
            _expr.Evaluate(context);

            if (context.Result == null)
            {
                throw new NullReferenceException(string.Format(Strings.NullReferenceInCode, Code(context)));
            }

            var         enumeration = context.Result as IEnumerable;
            IEnumerator enumerator  = null;

            if (enumeration != null)
            {
                enumerator = enumeration.GetEnumerator();
            }
            else
            {
                IBinding bind = RuntimeHost.Binder.BindToMethod(context.Result, "GetEnumerator", new Type[0], new object[0]);
                if (bind != null)
                {
                    enumerator = bind.Invoke(context, null) as IEnumerator;
                }
            }

            if (enumerator == null)
            {
                throw new ScriptExecutionException(string.Format(Strings.ForEachMethodNotFound, context.Result));
            }

            enumerator.Reset();

            while (enumerator.MoveNext())
            {
                context.SetItem(_name.Text, enumerator.Current);
                _statement.Evaluate(context);
                if (context.IsBreak() || context.IsReturn())
                {
                    context.SetBreak(false);
                    break;
                }
                if (context.IsContinue())
                {
                    context.SetContinue(false);
                }
            }
        }
示例#5
0
        public override void Evaluate(IScriptContext context)
        {
            var result = RuntimeHost.NullValue;

            //Create local scope
            var scope = RuntimeHost.ScopeFactory.Create(ScopeTypes.Local, context.Scope);

            context.CreateScope(scope);

            try
            {
                _init.Evaluate(context);
                _cond.Evaluate(context);
                bool condBool = context.Result == null ? true : (bool)context.Result;

                while (condBool)
                {
                    _statement.Evaluate(context);
                    result = context.Result;

                    if (context.IsBreak() || context.IsReturn())
                    {
                        context.SetBreak(false);
                        break;
                    }

                    if (context.IsContinue())
                    {
                        context.SetContinue(false);
                    }


                    _next.Evaluate(context);
                    _cond.Evaluate(context);
                    condBool = context.Result == null ? true : (bool)context.Result;
                }

                context.Result = result;
            }
            finally
            {
                context.RemoveLocalScope();
            }
        }