Exemplo n.º 1
0
        public object Evaluate(IBindingEnvironment environment)
        {
            object value = environment.GetValue(this.typename);

            Type type = null;

            // TODO create a typed array for IClass instances, not IClassicObject array
            if (!(value is IClass))
                type = TypeUtilities.GetType(environment, this.typename);
            else
                type = typeof(IClassicObject);

            int[] parameters = null;

            if (this.arguments != null && this.arguments.Count > 0)
            {
                List<int> values = new List<int>();

                foreach (IExpression argument in this.arguments)
                    values.Add(Convert.ToInt32(argument.Evaluate(environment)));

                parameters = values.ToArray();
            }

            if (parameters.Length == 1)
                return System.Array.CreateInstance(type, parameters[0]);

            return System.Array.CreateInstance(type, parameters);
        }
Exemplo n.º 2
0
        public void Execute(IBindingEnvironment environment)
        {
            if (this.expression != null)
                Machine.CurrentFunctionStatus.ReturnValue = this.expression.Evaluate(environment);

            Machine.CurrentFunctionStatus.Returned = true;
        }
Exemplo n.º 3
0
 public void Execute(IBindingEnvironment environment)
 {
     while (Predicates.IsTrue(this.condition.Evaluate(environment)))
     {
         this.command.Execute(environment);
     }
 }
Exemplo n.º 4
0
        public object Evaluate(IBindingEnvironment environment)
        {
            object leftValue  = this.leftExpression.Evaluate(environment);
            object rightValue = this.rigthExpression.Evaluate(environment);

            return(this.Apply(leftValue, rightValue));
        }
Exemplo n.º 5
0
        public void Execute(IBindingEnvironment environment)
        {
            object leftvalue = this.LeftValue.Evaluate(environment);
            object value     = this.expression.Evaluate(environment);

            ((IReference)leftvalue).SetValue(value);
        }
Exemplo n.º 6
0
        public void Execute(IBindingEnvironment environment)
        {
            AgentClass dynclass = new AgentClass(this.name);

            int k = 0;

            if (this.memberExpressions != null)
            {
                foreach (IExpression expression in this.memberExpressions)
                {
                    string name  = this.memberNames[k++];
                    object value = null;

                    if (expression != null)
                    {
                        value = expression.Evaluate(environment);
                    }

                    if (value is ICallable && !(value is AgentFunction))
                    {
                        value = new AgentFunction((ICallable)value);
                    }

                    dynclass.SetMember(name, value);
                }
            }

            Machine.Current.Environment.SetValue(this.name, dynclass);
        }
Exemplo n.º 7
0
        public object Evaluate(IBindingEnvironment environment)
        {
            object value = environment.GetValue(this.name);

            Type type = null;

            if (!(value is IClass))
                type = TypeUtilities.GetType(environment, this.name);

            object[] parameters = null;

            if (this.arguments != null && this.arguments.Count > 0)
            {
                List<object> values = new List<object>();

                foreach (IExpression argument in this.arguments)
                    values.Add(argument.Evaluate(environment));

                parameters = values.ToArray();
            }

            if (value is IClass)
                return ((IClass)value).NewInstance(parameters);

            return Activator.CreateInstance(type, parameters);
        }
Exemplo n.º 8
0
        public object Evaluate(IBindingEnvironment environment)
        {
            ICallable callable;

            callable = (ICallable)this.expression.Evaluate(environment);

            List<object> parameters = new List<object>();

            foreach (IExpression expression in this.arguments)
            {
                object parameter = expression.Evaluate(environment);

                if (expression is VariableVariableExpression)
                {
                    if (parameter != null)
                        foreach (object ob in (IEnumerable)parameter)
                            parameters.Add(ob);
                }
                else
                    parameters.Add(parameter);
            }

            IHost host = (IHost)this.hostexpression.Evaluate(environment);

            return host.Invoke(callable, parameters.ToArray());
        }
Exemplo n.º 9
0
        public object Evaluate(IBindingEnvironment environment)
        {
            ICallable callable = (ICallable)environment.GetValue(this.name);

            if (callable == null)
                callable = (ICallable)Machine.Current.Environment.GetValue(this.name);

            List<object> parameters = new List<object>();

            foreach (IExpression expression in this.arguments)
            {
                object parameter = expression.Evaluate(environment);

                if (expression is VariableVariableExpression)
                {
                    if (parameter != null)
                        foreach (object obj in (IEnumerable)parameter)
                            parameters.Add(obj);
                }
                else
                    parameters.Add(parameter);
            }

            if (callable is ILocalCallable)
                return callable.Invoke(environment, parameters.ToArray());

            return callable.Invoke(parameters.ToArray());
        }
Exemplo n.º 10
0
        public object Evaluate(IBindingEnvironment environment)
        {
            object value = environment.GetValue(this.name);

            Type type = null;

            if (!(value is IClass))
            {
                type = TypeUtilities.GetType(environment, this.name);
            }

            object[] parameters = null;

            if (this.arguments != null && this.arguments.Count > 0)
            {
                List <object> values = new List <object>();

                foreach (IExpression argument in this.arguments)
                {
                    values.Add(argument.Evaluate(environment));
                }

                parameters = values.ToArray();
            }

            if (value is IClass)
            {
                return(((IClass)value).NewInstance(parameters));
            }

            return(Activator.CreateInstance(type, parameters));
        }
Exemplo n.º 11
0
        public object Evaluate(IBindingEnvironment environment)
        {
            ICallable callable = (ICallable) environment.GetValue(this.name);

            if (callable == null)
                callable = (ICallable)Machine.Current.Environment.GetValue(this.name);

            List<object> parameters = new List<object>();

            foreach (IExpression expression in this.arguments)
            {
                object parameter = expression.Evaluate(environment);

                if (expression is VariableVariableExpression)
                {
                    if (parameter != null)
                        foreach (object obj in (IEnumerable)parameter)
                            parameters.Add(obj);
                }
                else
                    parameters.Add(parameter);
            }

            if (callable is ILocalCallable)
                return callable.Invoke(environment, parameters.ToArray());

            return callable.Invoke(parameters.ToArray());
        }
Exemplo n.º 12
0
        public object Evaluate(IBindingEnvironment environment)
        {
            object value = environment.GetValue(this.typename);

            Type type = null;

            // TODO create a typed array for IClass instances, not IClassicObject array
            if (!(value is IClass))
            {
                type = TypeUtilities.GetType(environment, this.typename);
            }
            else
            {
                type = typeof(IClassicObject);
            }

            List <object> elements = new List <object>();

            if (this.values != null && this.values.Count > 0)
            {
                foreach (IExpression argument in this.values)
                {
                    elements.Add(argument.Evaluate(environment));
                }
            }

            System.Array array = System.Array.CreateInstance(type, elements.Count);

            for (int k = 0; k < elements.Count; k++)
            {
                array.SetValue(elements[k], k);
            }

            return(array);
        }
Exemplo n.º 13
0
        public object Evaluate(IBindingEnvironment environment)
        {
            ICallable callable;

            callable = (ICallable)this.expression.Evaluate(environment);

            List <object> parameters = new List <object>();

            foreach (IExpression expression in this.arguments)
            {
                object parameter = expression.Evaluate(environment);

                if (expression is VariableVariableExpression)
                {
                    if (parameter != null)
                    {
                        foreach (object ob in (IEnumerable)parameter)
                        {
                            parameters.Add(ob);
                        }
                    }
                }
                else
                {
                    parameters.Add(parameter);
                }
            }

            IHost host = (IHost)this.hostexpression.Evaluate(environment);

            return(host.Invoke(callable, parameters.ToArray()));
        }
Exemplo n.º 14
0
 public void Execute(IBindingEnvironment environment)
 {
     Thread thread = new Thread(new ParameterizedThreadStart(this.ExecuteGo));
     GoCommandParameter parameter = new GoCommandParameter() { Machine = Machine.Current, Environment = new LocalBindingEnvironment(environment) };
     thread.IsBackground = true;
     thread.Start(parameter);
 }
Exemplo n.º 15
0
        public object Evaluate(IBindingEnvironment environment)
        {
            object leftValue = this.leftExpression.Evaluate(environment);
            object rightValue = this.rigthExpression.Evaluate(environment);

            return this.Apply(leftValue, rightValue);
        }
Exemplo n.º 16
0
        public object Evaluate(IBindingEnvironment environment)
        {
            object value = environment.GetValue(this.typename);

            Type type = null;

            // TODO create a typed array for IClass instances, not IClassicObject array
            if (!(value is IClass))
                type = TypeUtilities.GetType(environment, this.typename);
            else
                type = typeof(IClassicObject);

            List<object> elements = new List<object>();

            if (this.values != null && this.values.Count > 0)
            {
                foreach (IExpression argument in this.values)
                    elements.Add(argument.Evaluate(environment));
            }

            System.Array array = System.Array.CreateInstance(type, elements.Count);

            for (int k = 0; k < elements.Count; k++)
                array.SetValue(elements[k], k);

            return array;
        }
Exemplo n.º 17
0
        public void Execute(IBindingEnvironment environment)
        {
            object leftvalue = this.LeftValue.Evaluate(environment);
            object value = this.expression.Evaluate(environment);

            ((IReference)leftvalue).SetValue(value);
        }
Exemplo n.º 18
0
        public object Evaluate(IBindingEnvironment environment, ref object obj)
        {
            obj = this.Expression.Evaluate(environment);

            object[] parameters = null;

            if (this.arguments != null)
            {
                List <object> values = new List <object>();

                foreach (IExpression argument in this.arguments)
                {
                    values.Add(argument.Evaluate(environment));
                }

                parameters = values.ToArray();
            }

            // TODO if undefined, do nothing
            if (obj == null)
            {
                return(null);
            }

            return(ObjectUtilities.GetIndexedValue(obj, parameters));
        }
Exemplo n.º 19
0
        public void Execute(IBindingEnvironment environment)
        {
            object value = this.expression.Evaluate(environment);

            object[]      indexes = null;
            List <object> values  = new List <object>();

            foreach (IExpression expression in this.arguments)
            {
                values.Add(expression.Evaluate(environment));
            }

            indexes = values.ToArray();

            object obj = null;

            if (ObjectUtilities.IsNumber(indexes[0]))
            {
                obj = ExpressionUtilities.ResolveToList(this.leftValue, environment);
            }
            else
            {
                obj = ExpressionUtilities.ResolveToDictionary(this.leftValue, environment);
            }

            ObjectUtilities.SetIndexedValue(obj, indexes, value);
        }
Exemplo n.º 20
0
        public object Invoke(IBindingEnvironment environment, object[] arguments)
        {
            int argcount = 0;

            if (arguments != null)
            {
                argcount = arguments.Length;
            }

            if (this.arity != argcount)
            {
                if (!this.hasvariableparameters || this.arity - 1 > argcount)
                {
                    throw new InvalidOperationException("Invalid number of arguments");
                }
            }

            BindingEnvironment newenv = new BindingEnvironment(environment);

            if (this.hasvariableparameters)
            {
                for (int k = 0; k < this.arity - 1; k++)
                {
                    newenv.SetLocalValue(this.parameterNames[k], arguments[k]);
                }
                if (argcount == 0)
                {
                    newenv.SetLocalValue(this.parameterNames[0], new object[] { });
                }
                else
                {
                    object[] pars = new object[argcount - this.arity + 1];
                    Array.Copy(arguments, argcount - pars.Length, pars, 0, pars.Length);
                    newenv.SetLocalValue(this.parameterNames[this.arity - 1], pars);
                }
            }
            else
            {
                for (int k = 0; k < argcount; k++)
                {
                    newenv.SetLocalValue(this.parameterNames[k], arguments[k]);
                }
            }

            FunctionStatus fstatus = Machine.CurrentFunctionStatus;

            Machine.CurrentFunctionStatus = new FunctionStatus();

            try
            {
                this.body.Execute(newenv);

                return(Machine.CurrentFunctionStatus.ReturnValue);
            }
            finally
            {
                Machine.CurrentFunctionStatus = fstatus;
            }
        }
Exemplo n.º 21
0
 public LocalBindingEnvironment(IBindingEnvironment parent)
     : base(parent)
 {
     if (parent == null)
     {
         throw new ArgumentNullException("parent");
     }
 }
Exemplo n.º 22
0
        public object Evaluate(IBindingEnvironment environment)
        {
            object leftValue = this.leftExpression.Evaluate(environment);

            if (Predicates.IsFalse(leftValue))
                return false;

            return Predicates.IsTrue(this.rigthExpression.Evaluate(environment));
        }
Exemplo n.º 23
0
        public void Execute(IBindingEnvironment environment)
        {
            object value = null;

            if (this.expression != null)
                value = this.expression.Evaluate(environment);

            environment.SetLocalValue(this.name, value);
        }
Exemplo n.º 24
0
        public void SendInvoke(ICallable function, IBindingEnvironment environment, object[] arguments)
        {
            AgentTask task = new AgentTask()
            {
                Callable = function, Environment = environment, Arguments = arguments
            };

            this.channel.Send(task);
        }
Exemplo n.º 25
0
        public void Execute(IBindingEnvironment environment)
        {
            object result = this.condition.Evaluate(environment);

            if (Predicates.IsTrue(result))
                this.thenCommand.Execute(environment);
            else if (this.elseCommand != null)
                this.elseCommand.Execute(environment);
        }
Exemplo n.º 26
0
        public void Execute(IBindingEnvironment environment)
        {
            if (this.expression != null)
            {
                Machine.CurrentFunctionStatus.ReturnValue = this.expression.Evaluate(environment);
            }

            Machine.CurrentFunctionStatus.Returned = true;
        }
Exemplo n.º 27
0
        public static object ResolveToObject(IExpression expression, IBindingEnvironment environment)
        {
            if (expression is VariableExpression)
                return ResolveToObject((VariableExpression)expression, environment);

            if (expression is DotExpression)
                return ResolveToObject((DotExpression)expression, environment);

            return expression.Evaluate(environment);
        }
Exemplo n.º 28
0
        public object Invoke(IBindingEnvironment environment, object[] arguments)
        {
            AgentObject agent = (AgentObject)((ObjectEnvironment)environment).Object;

            agent.SendInvoke(this.function, environment, arguments);
            // TODO if function, return a Future
            return(null);
            // Direct code
//            return this.function.Invoke(environment, arguments);
        }
Exemplo n.º 29
0
        public static IDictionary ResolveToDictionary(IExpression expression, IBindingEnvironment environment)
        {
            if (expression is VariableExpression)
                return ResolveToDictionary((VariableExpression)expression, environment);

            if (expression is DotExpression)
                return ResolveToDictionary((DotExpression)expression, environment);

            return (IDictionary)expression.Evaluate(environment);
        }
Exemplo n.º 30
0
        public object Invoke(IBindingEnvironment environment, object[] arguments)
        {
            AgentObject agent = (AgentObject)((ObjectEnvironment)environment).Object;
            agent.SendInvoke(this.function, environment, arguments);

            // TODO if function, return a Future
            return null;

            // Direct code
            //            return this.function.Invoke(environment, arguments);
        }
Exemplo n.º 31
0
        public void Execute(IBindingEnvironment environment)
        {
            Thread             thread    = new Thread(new ParameterizedThreadStart(this.ExecuteGo));
            GoCommandParameter parameter = new GoCommandParameter()
            {
                Machine = Machine.Current, Environment = new LocalBindingEnvironment(environment)
            };

            thread.IsBackground = true;
            thread.Start(parameter);
        }
Exemplo n.º 32
0
        public void Execute(IBindingEnvironment environment)
        {
            object value = null;

            if (this.expression != null)
            {
                value = this.expression.Evaluate(environment);
            }

            environment.SetLocalValue(this.name, value);
        }
Exemplo n.º 33
0
        private static void SetValue(DotExpression expression, object value, IBindingEnvironment environment)
        {
            if (expression.Arguments != null)
            {
                throw new InvalidOperationException("Invalid left value");
            }

            object obj = ResolveToObject(expression.Expression, environment);

            ObjectUtilities.SetValue(obj, expression.Name, value);
        }
Exemplo n.º 34
0
        public object Evaluate(IBindingEnvironment environment)
        {
            object leftValue = this.leftExpression.Evaluate(environment);

            if (Predicates.IsFalse(leftValue))
            {
                return(false);
            }

            return(Predicates.IsTrue(this.rigthExpression.Evaluate(environment)));
        }
Exemplo n.º 35
0
        public static Type GetType(IBindingEnvironment environment, string name)
        {
            object obj = environment.GetValue(name);

            if (obj == null && Machine.Current != null)
                obj = Machine.Current.Environment.GetValue(name);

            if (obj != null && obj is Type)
                return (Type)obj;

            return GetType(name);
        }
Exemplo n.º 36
0
        public object Evaluate(IBindingEnvironment environment)
        {
            if (this.expression == null)
                return null;

            object obj = this.expression.Evaluate(environment);

            if (obj == null)
                return null;

            return ((IReference)obj).GetValue();
        }
Exemplo n.º 37
0
        public void Execute(IBindingEnvironment environment)
        {
            LocalBindingEnvironment local = new LocalBindingEnvironment(environment);

            foreach (ICommand command in this.commands)
            {
                if (Machine.CurrentFunctionStatus.Returned)
                    return;

                command.Execute(local);
            }
        }
Exemplo n.º 38
0
        public void Execute(IBindingEnvironment environment)
        {
            object result = this.condition.Evaluate(environment);

            if (Predicates.IsTrue(result))
            {
                this.thenCommand.Execute(environment);
            }
            else if (this.elseCommand != null)
            {
                this.elseCommand.Execute(environment);
            }
        }
Exemplo n.º 39
0
        public bool ShowDialog(IAction action, IBindingEnvironment bindingEnvironment)
        {
            if (action == null)
            {
                return(false);
            }
            _action             = action;
            _bindingEnvironment = bindingEnvironment;
            Text = action.Name;
            DialogResult dlg = ShowDialog();

            return(dlg == DialogResult.OK);
        }
Exemplo n.º 40
0
        public object Invoke(IBindingEnvironment environment, object[] arguments)
        {
            if (arguments == null || arguments.Length != 1)
                throw new InvalidOperationException("Invalid number of parameters");

            string text = (string)arguments[0];

            Parser parser = new Parser(text);

            IExpression expression = parser.ParseExpression();

            return expression.Evaluate(environment);
        }
Exemplo n.º 41
0
        public static object ResolveToList(IExpression expression, IBindingEnvironment environment)
        {
            if (expression is VariableExpression)
            {
                return(ResolveToList((VariableExpression)expression, environment));
            }

            if (expression is DotExpression)
            {
                return(ResolveToList((DotExpression)expression, environment));
            }

            return(expression.Evaluate(environment));
        }
Exemplo n.º 42
0
        public static IDictionary ResolveToDictionary(IExpression expression, IBindingEnvironment environment)
        {
            if (expression is VariableExpression)
            {
                return(ResolveToDictionary((VariableExpression)expression, environment));
            }

            if (expression is DotExpression)
            {
                return(ResolveToDictionary((DotExpression)expression, environment));
            }

            return((IDictionary)expression.Evaluate(environment));
        }
Exemplo n.º 43
0
        public Function(string[] parameterNames, ICommand body, IBindingEnvironment environment, bool isdefault, bool hasvariableparameters)
        {
            this.parameterNames = parameterNames;
            this.body = body;
            this.hasvariableparameters = hasvariableparameters;

            if (parameterNames == null)
                this.arity = 0;
            else
                this.arity = parameterNames.Length;

            this.environment = environment;
            this.isdefault = isdefault;
        }
Exemplo n.º 44
0
        public void Execute(IBindingEnvironment environment)
        {
            LocalBindingEnvironment local = new LocalBindingEnvironment(environment);

            foreach (ICommand command in this.commands)
            {
                if (Machine.CurrentFunctionStatus.Returned)
                {
                    return;
                }

                command.Execute(local);
            }
        }
Exemplo n.º 45
0
        public object Evaluate(IBindingEnvironment environment)
        {
            object    obj = null;
            ICallable callable;

            if (this.expression is ArrayExpression)
            {
                callable = (ICallable)((ArrayExpression)this.expression).Evaluate(environment, ref obj);
            }
            else
            {
                callable = (ICallable)this.expression.Evaluate(environment);
            }

            List <object> parameters = new List <object>();

            foreach (IExpression expression in this.arguments)
            {
                object parameter = expression.Evaluate(environment);

                if (expression is VariableVariableExpression)
                {
                    if (parameter != null)
                    {
                        foreach (object ob in (IEnumerable)parameter)
                        {
                            parameters.Add(ob);
                        }
                    }
                }
                else
                {
                    parameters.Add(parameter);
                }
            }

            if (obj != null && obj is DynamicObject)
            {
                DynamicObject dobj = (DynamicObject)obj;
                return(dobj.Invoke(callable, parameters.ToArray()));
            }

            if (callable is ILocalCallable)
            {
                return(callable.Invoke(environment, parameters.ToArray()));
            }

            return(callable.Invoke(parameters.ToArray()));
        }
Exemplo n.º 46
0
        public void Execute(IBindingEnvironment environment)
        {
            IBindingEnvironment newenv = new LocalBindingEnvironment(environment);

            if (this.initialCommand != null)
                this.initialCommand.Execute(newenv);

            while (this.condition == null || Predicates.IsTrue(this.condition.Evaluate(newenv)))
            {
                if (this.body != null)
                    this.body.Execute(newenv);
                if (this.endCommand != null)
                    this.endCommand.Execute(newenv);
            }
        }
Exemplo n.º 47
0
        public object Invoke(IBindingEnvironment environment, object[] arguments)
        {
            if (arguments == null || arguments.Length != 1)
            {
                throw new InvalidOperationException("Invalid number of parameters");
            }

            string text = (string)arguments[0];

            Parser parser = new Parser(text);

            IExpression expression = parser.ParseExpression();

            return(expression.Evaluate(environment));
        }
Exemplo n.º 48
0
        public static void SetValue(IExpression expression, object value, IBindingEnvironment environment)
        {
            if (expression is VariableExpression)
            {
                SetValue((VariableExpression)expression, value, environment);
                return;
            }

            if (expression is DotExpression)
            {
                SetValue((DotExpression)expression, value, environment);
                return;
            }

            throw new InvalidOperationException("Invalid left value");
        }
Exemplo n.º 49
0
        public void Execute(IBindingEnvironment environment)
        {
            if (Machine.CurrentTransaction != null)
            {
                this.command.Execute(environment);
                return;
            }

            using (Transaction trans = new Transaction(Machine.Current))
            {
                Machine.CurrentTransaction = trans;
                this.command.Execute(environment);
                Machine.CurrentTransaction = null;
                trans.Complete();
            }
        }
Exemplo n.º 50
0
        public object Invoke(IBindingEnvironment environment, object[] arguments)
        {
            if (arguments == null || arguments.Length != 1)
                throw new InvalidOperationException("Invalid number of parameters");

            string text = (string)arguments[0];

            Parser parser = new Parser(text);

            ICommand command;

            while ((command = parser.ParseCommand()) != null)
                command.Execute(environment);

            return null;
        }
Exemplo n.º 51
0
        private static IDictionary ResolveToDictionary(VariableExpression expression, IBindingEnvironment environment)
        {
            string name = expression.VariableName;

            object obj = environment.GetValue(name);

            if (obj == null)
            {
                obj = new Hashtable();

                // TODO Review if Local or not
                environment.SetValue(name, obj);
            }

            return (IDictionary)obj;
        }
Exemplo n.º 52
0
        public void Execute(IBindingEnvironment environment)
        {
            if (Machine.CurrentTransaction != null)
            {
                this.command.Execute(environment);
                return;
            }

            using (Transaction trans = new Transaction(Machine.Current))
            {
                Machine.CurrentTransaction = trans;
                this.command.Execute(environment);
                Machine.CurrentTransaction = null;
                trans.Complete();
            }
        }
Exemplo n.º 53
0
        public void Execute(IBindingEnvironment environment)
        {
            IBindingEnvironment newenv = environment;

            if (this.localvar)
            {
                newenv = new LocalBindingEnvironment(environment);
                newenv.SetLocalValue(this.name, null);
            }

            foreach (object result in (IEnumerable)this.expression.Evaluate(newenv))
            {
                newenv.SetValue(this.name, result);
                this.command.Execute(newenv);
            }
        }
Exemplo n.º 54
0
        public object Evaluate(IBindingEnvironment environment)
        {
            if (this.expression == null)
            {
                return(null);
            }

            object obj = this.expression.Evaluate(environment);

            if (obj == null)
            {
                return(null);
            }

            return(((IReference)obj).GetValue());
        }
Exemplo n.º 55
0
        public void Execute(IBindingEnvironment environment)
        {
            IBindingEnvironment newenv = environment;

            if (this.localvar)
            {
                newenv = new LocalBindingEnvironment(environment);
                newenv.SetLocalValue(this.name, null);
            }

            foreach (object result in (IEnumerable)this.expression.Evaluate(newenv))
            {
                newenv.SetValue(this.name, result);
                this.command.Execute(newenv);
            }
        }
Exemplo n.º 56
0
        public static Type GetType(IBindingEnvironment environment, string name)
        {
            object obj = environment.GetValue(name);

            if (obj == null && Machine.Current != null)
            {
                obj = Machine.Current.Environment.GetValue(name);
            }

            if (obj != null && obj is Type)
            {
                return((Type)obj);
            }

            return(GetType(name));
        }
Exemplo n.º 57
0
        public object Evaluate(IBindingEnvironment environment)
        {
            object obj = this.leftObject.Evaluate(environment);

            int k = 0;

            foreach (IExpression expression in this.expressions)
            {
                string name = this.propertyNames[k++];

                object value = expression.Evaluate(environment);

                ObjectUtilities.SetValue(obj, name, value);
            }

            return obj;
        }
Exemplo n.º 58
0
        public object Evaluate(IBindingEnvironment environment)
        {
            object obj = null;

            // TODO refactor compare to Add, case sensitive? IsListVerb(this.name)?
            if (this.type == null)
                if (this.name == "Add")
                    obj = ExpressionUtilities.ResolveToList(this.expression, environment);
                else
                    obj = this.expression.Evaluate(environment);

            object[] parameters = null;

            if (this.arguments != null)
            {
                List<object> values = new List<object>();

                foreach (IExpression argument in this.arguments)
                {
                    object value = argument.Evaluate(environment);

                    if (argument is VariableVariableExpression)
                    {
                        if (value != null)
                            foreach (object val in (IEnumerable)value)
                                values.Add(val);
                    }
                    else
                        values.Add(value);
                }

                parameters = values.ToArray();
            }

            if (this.type != null)
                return TypeUtilities.InvokeTypeMember(this.type, this.name, parameters);

            if (obj is Type)
                return TypeUtilities.InvokeTypeMember((Type)obj, this.name, parameters);

            // TODO if undefined, do nothing
            if (obj == null)
                return null;

            return ObjectUtilities.GetValue(obj, this.name, parameters);
        }
Exemplo n.º 59
0
        public void Execute(IBindingEnvironment environment)
        {
            DynamicObject dynobj = new DynamicObject();

            int k = 0;

            if (this.memberExpressions != null)
                foreach (IExpression expression in this.memberExpressions)
                {
                    string name = this.memberNames[k++];
                    object value = null;

                    if (expression != null)
                        value = expression.Evaluate(environment);

                    dynobj.SetValue(name, value);
                }

            environment.SetValue(this.name, dynobj);
        }
Exemplo n.º 60
0
        public void Execute(IBindingEnvironment environment)
        {
            DynamicClass dynclass = new DynamicClass(this.name);

            int k = 0;

            if (this.memberExpressions != null)
                foreach (IExpression expression in this.memberExpressions)
                {
                    string name = this.memberNames[k++];
                    object value = null;

                    if (expression != null)
                        value = expression.Evaluate(environment);

                    dynclass.SetMember(name, value);
                }

            Machine.Current.Environment.SetValue(this.name, dynclass);
        }