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 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 GetNames() { BindingEnvironment environment = new BindingEnvironment(); environment.SetValue("one", 1); environment.SetValue("two", 2); var result = environment.GetNames(); Assert.AreEqual(2, result.Count); Assert.IsTrue(result.Contains("one")); Assert.IsTrue(result.Contains("two")); }