public void EvaluateSimpleNewExpression() { IExpression dotexpr = new DotExpression(new DotExpression(new VariableExpression("System"), "Data"), "DataSet"); IExpression expression = new NewExpression(dotexpr, null); object result = expression.Evaluate(new Context()); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(System.Data.DataSet)); }
private static string AsName(IExpression expression) { if (expression is DotExpression) { DotExpression dot = (DotExpression)expression; return(AsName(dot.Expression) + "." + dot.Name); } return(null); }
public void EvaluateNewExpressionWithArguments() { IExpression dotexpr = new DotExpression(new DotExpression(new VariableExpression("System"), "IO"), "DirectoryInfo"); IExpression expression = new NewExpression(dotexpr, new IExpression[] { new ConstantExpression(".") }); object result = expression.Evaluate(new Context()); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(System.IO.DirectoryInfo)); DirectoryInfo di = (DirectoryInfo)result; DirectoryInfo current = new DirectoryInfo("."); Assert.AreEqual(current.FullName, di.FullName); }
private static IDictionary ResolveToDictionary(DotExpression expression, IContext context) { object obj = ResolveToObject(expression.Expression, context); if (obj is DynamicObject) { DynamicObject dynobj = (DynamicObject)obj; obj = dynobj.GetValue(expression.Name); if (obj == null || obj == Undefined.Instance) { obj = new Hashtable(); dynobj.SetValue(expression.Name, obj); } return (IDictionary)obj; } return (IDictionary)ObjectUtilities.GetValue(obj, expression.Name); }
public void ResolveDotExpressionToObject() { Context context = new Context(); IExpression expression = new DotExpression(new VariableExpression("Project"), "Title"); object obj = ExpressionUtilities.ResolveToObject(expression, context); Assert.IsNotNull(obj); Assert.IsInstanceOfType(obj, typeof(IObject)); object project = context.GetValue("Project"); Assert.IsNotNull(project); Assert.IsInstanceOfType(project, typeof(IObject)); object title = ((IObject)project).GetValue("Title"); Assert.IsNotNull(title); Assert.IsInstanceOfType(title, typeof(IObject)); Assert.AreEqual(obj, title); }
public void ResolveDotExpressionToList() { Context context = new Context(); IExpression expression = new DotExpression(new VariableExpression("Project"), "Entities"); object obj = ExpressionUtilities.ResolveToList(expression, context); Assert.IsNotNull(obj); Assert.IsInstanceOfType(obj, typeof(IList)); object project = context.GetValue("Project"); Assert.IsNotNull(project); Assert.IsInstanceOfType(project, typeof(IObject)); object entities = ((IObject)project).GetValue("Entities"); Assert.IsNotNull(entities); Assert.IsInstanceOfType(entities, typeof(IList)); Assert.AreEqual(obj, entities); }
private IExpression ParseTermExpression() { if (this.TryParse(TokenType.Name, "new")) return ParseNewExpression(); IExpression expression = this.ParseSimpleTermExpression(); while (this.TryParse(TokenType.Operator, ".") || this.TryParse(TokenType.Separator, "[", "(")) { if (this.TryParse(TokenType.Operator, ".")) { this.lexer.NextToken(); string name = this.ParseName(); IList<IExpression> arguments = null; if (this.TryParse(TokenType.Separator, "(")) arguments = this.ParseArgumentList(); expression = new DotExpression(expression, name, arguments); continue; } if (this.TryParse(TokenType.Separator, "(")) { IList<IExpression> arguments = this.ParseArgumentList(); expression = new InvokeExpression(expression, arguments); continue; } expression = new ArrayExpression(expression, this.ParseArrayArgumentList()); } return expression; }
private IExpression ParseQualifiedName() { string name = this.ParseName(); IExpression expression = new VariableExpression(name); while (this.TryParse(TokenType.Delimiter, ".")) { this.lexer.NextToken(); expression = new DotExpression(expression, this.ParseName()); } return expression; }
private static void SetValue(DotExpression expression, object value, IContext context) { if (expression.Arguments != null) throw new InvalidOperationException("Invalid left value"); object obj = ResolveToObject(expression.Expression, context); ObjectUtilities.SetValue(obj, expression.Name, value); }
private static IList ResolveToList(DotExpression expression, IContext context) { object obj = ResolveToObject(expression.Expression, context); if (obj is DynamicObject) { DynamicObject dynobj = (DynamicObject)obj; obj = dynobj.GetValue(expression.Name); if (obj == null || obj == Undefined.Instance) { obj = new ArrayList(); dynobj.SetValue(expression.Name, obj); } return (IList)obj; } return (IList)ObjectUtilities.GetValue(obj, expression.Name); }