public void EvaluateSimpleNewExpression() { IExpression expression = new NewExpression("System.Data.DataSet", null); object result = expression.Evaluate(new BindingEnvironment()); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(System.Data.DataSet)); }
public void EvaluateNewExpressionWithAliasedType() { IExpression expression = new NewExpression("Channel", null); BindingEnvironment environment = new BindingEnvironment(); environment.SetValue("Channel", typeof(Channel)); object result = expression.Evaluate(environment); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(Channel)); }
public void EvaluateNewExpressionWithArguments() { IExpression expression = new NewExpression("System.IO.DirectoryInfo", new IExpression[] { new ConstantExpression(".") }); object result = expression.Evaluate(new BindingEnvironment()); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(System.IO.DirectoryInfo)); DirectoryInfo di = (DirectoryInfo)result; DirectoryInfo current = new DirectoryInfo("."); Assert.AreEqual(current.FullName, di.FullName); }
// TODO Refactor private IExpression ParseNewExpression() { this.lexer.NextToken(); IExpression expression; bool isDynamic = false; if (this.TryPeekName()) { string typename = this.ParseQualifiedName(); if (this.TryParse(TokenType.Separator, "[")) return this.ParseNewArrayExpression(typename); ICollection<IExpression> arguments = this.ParseArgumentList(); expression = new NewExpression(typename, arguments); if (!this.TryParse(TokenType.Separator, "{")) return expression; } else { isDynamic = true; expression = new NewExpression("AjLanguage.Language.DynamicObject", null); } this.Parse(TokenType.Separator, "{"); List<string> names = new List<string>(); List<IExpression> expressions = new List<IExpression>(); bool wasMember = false; while (!this.TryParse(TokenType.Separator, "}")) { if (names.Count > 0 && !wasMember) this.Parse(TokenType.Separator, ","); if (isDynamic && this.TryParse(TokenType.Name, "var", "function", "sub")) { wasMember = true; Token token = this.lexer.NextToken(); if (token.Value == "var") this.ParseMemberVariable(names, expressions); else if (token.Value == "function" || token.Value == "sub") this.ParseMemberMethod(names, expressions, false); else throw new UnexpectedTokenException(token); } else { wasMember = false; names.Add(this.ParseName()); this.Parse(TokenType.Operator, "="); expressions.Add(this.ParseExpression()); } } this.Parse(TokenType.Separator, "}"); return new MultipleSetExpression(expression, names.ToArray(), expressions); }