public void GetIndexedValuesFromDynamicObject()
        {
            DynamicObject obj = new DynamicObject();
            obj.SetValue("Name", "Adam");
            obj.SetValue("GetAge", new Function(new string[] { "n" }, null));

            Assert.AreEqual("Adam", ObjectUtilities.GetIndexedValue(obj, new object[] { "Name" }));

            object f = ObjectUtilities.GetIndexedValue(obj, new object[] { "GetAge" });
            Assert.IsNotNull(f);
            Assert.IsInstanceOfType(f, typeof(Function));
        }
        public void GetValueFromDynamicObject()
        {
            DynamicObject dynobj = new DynamicObject();
            dynobj.SetValue("FirstName", "Adam");

            Assert.AreEqual("Adam", ObjectUtilities.GetValue(dynobj, "FirstName"));
        }
Exemple #3
0
        public void EvaluateCallObject()
        {
            Machine machine = new Machine();
            ICommand body = new ReturnCommand(new ArithmeticBinaryExpression(ArithmeticOperator.Add, new VariableExpression("x"), new DotExpression(new VariableExpression("this"), "Age")));
            Function function = new Function(new string[] { "x" }, body);
            DynamicObject person = new DynamicObject();
            person.SetValue("Age", 30);

            Assert.AreEqual(40, function.Call(person, new object[] { 10 }));
        }
Exemple #4
0
        public void EvaluateArrayDotExpression()
        {
            BindingEnvironment environment = new BindingEnvironment();

            DynamicObject data = new DynamicObject();
            data.SetValue("Numbers", new string[] { "one", "two", "three" });

            environment.SetValue("data", data);

            IExpression expression = new ArrayExpression(new DotExpression(new VariableExpression("data"), "Numbers"), new IExpression[] { new ConstantExpression(1) });

            object result = expression.Evaluate(environment);

            Assert.IsNotNull(result);
            Assert.AreEqual("two", result);
        }
        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);
        }