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); }
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); }
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")); }
public void UndefinedMethodIsNull() { DynamicClass @class = new DynamicClass("Dog"); Assert.IsNull(@class.GetMethod("foo")); }