예제 #1
0
        //NOTE: This code contains bug, when dealing with multi-dimensional arrays
        //private static void SetArrayValue(object obj, ScriptArrayResolution scriptArrayResolution, IScriptContext context, object value)
        //{
        //  scriptArrayResolution.Evaluate(context);

        //  var indexParameters = (object[])context.Result;
        //  // Denis: don't remove (dynamic) casting whatever R# tells you
        //  ((dynamic)obj)[(dynamic)indexParameters[0]] = (dynamic)value;
        //}

        //private static void GetArrayValue(object obj, ScriptArrayResolution scriptArrayResolution, IScriptContext context)
        //{
        //  scriptArrayResolution.Evaluate(context);

        //  var param = (object[])context.Result;
        //  context.Result = ((dynamic)obj)[(dynamic)param[0]];
        //}
        #endregion

        #region Name Part
        private void EvaluateNamePart(IScriptContext context)
        {
            _namePart.Evaluate(context);
            object obj             = context.Result;
            bool   firstResolution = false;

            if (_modifiers == null)
            {
                context.Result = GetMemberValue(obj, _identifier);
                return;
            }

            Type[] genericArguments = null;
            foreach (ScriptAst node in _modifiers)
            {
                //NOTE: Generic modifier should be the first among other modifiers in the list
                var generic = node as ScriptGenericsPostfix;
                if (generic != null)
                {
                    if (genericArguments != null)
                    {
                        throw new ScriptSyntaxErrorException(string.Format(Strings.WrongSequenceOfModifiers, Code(context)));
                    }

                    generic.Execute(context);
                    genericArguments = (Type[])context.Result;
                    continue;
                }

                var functionCall = node as ScriptFunctionCall;
                if (functionCall != null)
                {
                    CallClassMethod(obj, _identifier, functionCall, genericArguments, context);
                    obj = context.Result;
                    continue;
                }

                var arrayResolution = node as ScriptArrayResolution;
                if (arrayResolution != null)
                {
                    if (!firstResolution)
                    {
                        obj             = GetMemberValue(obj, _identifier);
                        firstResolution = true;
                    }

                    GetArrayValue(obj, arrayResolution, context);
                    obj = context.Result;
                    continue;
                }
            }
        }
예제 #2
0
        public override void Evaluate(IScriptContext context)
        {
            _name.Evaluate(context);

            context.CreateScope(RuntimeHost.ScopeFactory.Create(ScopeTypes.Using, context.Scope, context.Result));
            _statement.Evaluate(context);
            context.RemoveLocalScope();
        }
예제 #3
0
        private object MinusEqual(IScriptContext context)
        {
            object rez = context.Result;

            _nameExpr.Evaluate(context);

            var rezName = context.Result;

            var handling = OnHandleOperator(this, context, "-=", rezName, rez);

            rez = handling.Cancel ? handling.Result : _minus.Evaluate(rezName, rez);

            //if (!(rezName is EventInfo))
            //{
            //  rez = RuntimeHost.GetBinaryOperator("-").Evaluate(rezName, rez);
            //}
            //else
            //{
            //  rez = new RemoveDelegate((IInvokable)rez);
            //}
            _nameExpr.Assign(rez, context);
            return(rez);
        }