예제 #1
0
        public void ClassHasNewMethod()
        {
            Machine      machine = new Machine();
            DynamicClass @class  = new DynamicClass((DynamicClass)machine.RootContext.GetLocalValue("Class"), "Dog", (DynamicClass)machine.RootContext.GetLocalValue("Object"));

            var result = @class.GetMethod("new");

            Assert.IsNotNull(result);
        }
예제 #2
0
        public void ApplyNewMethod()
        {
            Machine      machine = new Machine();
            DynamicClass @class  = new DynamicClass((DynamicClass)machine.RootContext.GetLocalValue("Class"), "Dog", (DynamicClass)machine.RootContext.GetLocalValue("Object"));

            var result = @class.GetMethod("new").Apply(@class, machine.RootContext, null);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(DynamicObject));

            var obj = (DynamicObject)result;

            Assert.AreSame(@class, obj.Class);
        }
예제 #3
0
        public void ApplyNewMethodCallingInitialize()
        {
            Machine      machine    = new Machine();
            DynamicClass @class     = new DynamicClass((DynamicClass)machine.RootContext.GetLocalValue("Class"), "Dog", (DynamicClass)machine.RootContext.GetLocalValue("Object"));
            IFunction    initialize = new DefinedFunction(new AssignInstanceVarExpression("age", new ConstantExpression(10)), new string[0], null);

            @class.SetInstanceMethod("initialize", initialize);

            var result = @class.GetMethod("new").Apply(@class, @class.Constants, new object[] { });

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(DynamicObject));

            var obj = (DynamicObject)result;

            Assert.AreSame(@class, obj.Class);
            Assert.AreEqual(10, obj.GetValue("age"));
        }
예제 #4
0
        public void UndefinedMethodIsNull()
        {
            DynamicClass @class = new DynamicClass("Dog");

            Assert.IsNull(@class.GetMethod("foo"));
        }