public void RedefineAttributeAsMethodUsingSetValue() { DefinedClass klass = new DefinedClass("Spam"); IFunction method = new NativeMethod(this.DummyMethod); klass.SetValue("foo", 1); klass.SetValue("foo", method); var result = klass.GetMethod("foo"); Assert.IsNotNull(result); Assert.AreEqual(method, result); Assert.IsTrue(klass.HasMethod("foo")); Assert.IsTrue(klass.HasValue("foo")); }
public void Execute(IContext context) { BindingEnvironment env = new BindingEnvironment(context); IList <IType> bases = null; if (this.baseExpressions != null && this.baseExpressions.Count > 0) { bases = new List <IType>(); foreach (var expr in this.baseExpressions) { bases.Add((IType)expr.Evaluate(context)); } } DefinedClass klass = new DefinedClass(this.name, bases, context); this.body.Execute(klass); foreach (var name in env.GetNames()) { var value = env.GetValue(name); var deffunc = value as DefinedFunction; if (deffunc != null) { klass.SetMethod(deffunc.Name, deffunc); } } klass.SetValue("__doc__", this.doc); context.SetValue(this.name, klass); }
public void GetValueFromClass() { DefinedClass klass = new DefinedClass("Spam"); DynamicObject dynobj = new DynamicObject(klass); klass.SetValue("one", 1); var result = dynobj.GetValue("one"); Assert.IsNotNull(result); Assert.AreEqual(1, result); Assert.IsTrue(dynobj.HasValue("one")); }
public void SetGetAttribute() { DefinedClass klass = new DefinedClass("Spam"); klass.SetValue("one", 1); var result = klass.GetValue("one"); Assert.IsNotNull(result); Assert.AreEqual(1, result); Assert.IsTrue(klass.HasValue("one")); }
public void GetValueFromSuperClass() { DefinedClass super = new DefinedClass("object"); super.SetValue("foo", 1); DefinedClass klass = new DefinedClass("Spam", new IType[] { super }); var result = klass.GetValue("foo"); Assert.IsNotNull(result); Assert.AreEqual(1, result); Assert.IsTrue(klass.HasValue("foo")); }
public void GetMethodFromSuperClass() { DefinedClass super = new DefinedClass("object"); IFunction method = new NativeMethod(this.DummyMethod); super.SetValue("foo", method); DefinedClass klass = new DefinedClass("Spam", new IType[] { super }); var result = klass.GetMethod("foo"); Assert.IsNotNull(result); Assert.IsTrue(klass.HasMethod("foo")); }
public void ReplaceMethodWithAttribute() { DefinedClass klass = new DefinedClass("Spam"); IFunction method = new NativeMethod(this.DummyMethod); klass.SetMethod("foo", method); klass.SetValue("foo", 1); var result = klass.GetMethod("foo"); Assert.IsNull(result); Assert.IsFalse(klass.HasMethod("foo")); Assert.AreEqual(1, klass.GetValue("foo")); Assert.IsTrue(klass.HasValue("foo")); }