public static void Evaluate(ParsedExpressionList expressionList, SDFState state) { Object lastExpressionObject = null; foreach (Object o in expressionList) { if (o is ParsedExpressionList) { if (lastExpressionObject != null) { state += lastExpressionObject; try { Evaluate((ParsedExpressionList) o, state); } finally { state -= lastExpressionObject; } lastExpressionObject = null; } } else { ParsedExpression expression = (ParsedExpression) o; MethodInfo method = expression.Expression.GetType().GetMethod("Evaluate"); lastExpressionObject = method.Invoke(expression.Expression, new Object[] { state, expression.ExpressionName, expression.Arguments }); } } }
public void TestStateAccess() { registry.AddType(typeof(stringfromstate)); this.state += "stringydingy"; Assert.AreEqual("stringydingy", TokenString.Eval(registry, state, "$[stringfromstate]")); }
public void SetUp() { this.registry = new TokenStringRegistry(); this.state = new SDFState(); }
public void Evaluate(SDFState state, string name, Hashtable arguments) { ((TokenResult) state[typeof(TokenResult)]).Result = arguments["result"].ToString(); }
private void EvaluateChildExpressions(SDFState state) { this.rootExpressionChildren.Evaluate(state); }
public void Evaluate(SDFState state, string name, Hashtable arguments) { }
public void PostCreateExpression(SDFState state, string name, Hashtable arguments, ParsedExpressionList children) { ((ExpressionRegistry) state[typeof(ExpressionRegistry)]).AddAssembly(arguments["filename"].ToString()); }
public object Evaluate(SDFState state, string name, Hashtable arguments) { return arguments["string"].ToString(); }
public static void Load(ParsedExpressionList expressionList, SDFState state, ProvidedStatePile parentExpressionStatePile) { ExpressionRegistry expressions = (ExpressionRegistry) state[typeof(ExpressionRegistry)]; ParsedExpression expression = null; TokenStringRegistry tokenStringRegistry = (TokenStringRegistry) state[typeof(TokenStringRegistry)]; foreach (Object o in expressionList) { if (o is ParsedExpressionList) { MaybeCallPostCreateExpression(state, expression, (ParsedExpressionList) o); parentExpressionStatePile.AddProvidedStateFromObject(expression.Expression); expression = null; Load((ParsedExpressionList) o, state, parentExpressionStatePile); parentExpressionStatePile.RemoveLastProvidedState(); } else { if (expression != null) { MaybeCallPostCreateExpression(state, expression, null); } expression = (ParsedExpression) o; BindArguments(expression.Arguments, tokenStringRegistry); { object newObject = null; object foundObject = expressions[expression.ExpressionName]; Type type = foundObject as Type; if ((foundObject != null) && (type == null)) { type = foundObject.GetType(); } if (type == null) { throw new SDFException(String.Format("Unknown expression '{0}'", expression.ExpressionName)); } { MethodInfo method = type.GetMethod("CreateExpression"); if (method != null) { newObject = method.Invoke(foundObject, new Object[] { state, expression.ExpressionName, expression.Arguments }); type = newObject.GetType(); } else { newObject = type.GetConstructor(new Type[0]).Invoke(null); } } { // On the class, see if there are SDFArgument attributes foreach (SDFArgumentAttribute argument in type.GetCustomAttributes(typeof(SDFArgumentAttribute), false)) { // If the argument is required, then whine if it wasn't specified if ((argument.Required) && (!expression.Arguments.Contains(argument.Name))) { throw new SDFException(String.Format("Rquired argument '{0}' was not specified", argument.Name)); } } } // Set arguments to properties if required { // For each property, check to see if it has an SDFArgument attribute foreach (PropertyInfo property in type.GetProperties()) { foreach (SDFArgumentAttribute argument in property.GetCustomAttributes(typeof(SDFArgumentAttribute), false)) { // If the argument is required, then whine if it wasn't specified if ((argument.Required) && (!expression.Arguments.Contains(property.Name))) { throw new SDFException(String.Format("Rquired argument '{0}' was not specified", property.Name)); } // Set the property property.GetSetMethod().Invoke(newObject, new Object[] { expression.Arguments[property.Name] }); } } } { MethodInfo method = type.GetMethod("Evaluate"); // Now check to see if there's any required state foreach (SDFStateRequiredAttribute stateRequired in method.GetCustomAttributes(typeof(SDFStateRequiredAttribute), false)) { if ((state[stateRequired.RequiredType] == null) && (!parentExpressionStatePile.Contains(stateRequired.RequiredType))) { throw new SDFException(String.Format("Required state '{0}' was not found", stateRequired.RequiredType.Name)); } } } expression.Expression = newObject; } } } if (expression != null) { MaybeCallPostCreateExpression(state, expression, null); expression = null; } }
public void SetUp() { this.output = new StandardOutputRedirector(); this.state = new SDFState(); SDF.Eval(this.state, "LoadExpressions filename='SDF.Print.dll'"); }
public static void Eval(SDFState state, string eval) { ParsedExpressionList expressionList = ExpressionParser.Parse(eval); Load(expressionList, state, new ProvidedStatePile()); expressionList.Evaluate(state); }
private static void MaybeCallPostCreateExpression(SDFState state, ParsedExpression expression, ParsedExpressionList children) { MethodInfo postCreateMethod = expression.Expression.GetType().GetMethod("PostCreateExpression"); if (postCreateMethod != null) { postCreateMethod.Invoke(expression.Expression, new Object[] { state, expression.ExpressionName, expression.Arguments, children }); } }
public string Evaluate(SDFState state, ArrayList arguments) { return (string) state[typeof(string)]; }
public string Evaluate(SDFState state, ArrayList arguments) { return "dogdude"; }
public object CreateExpression(SDFState state, string name, Hashtable arguments) { return new ObjectBasedFactoryInstance(); }
public void TestExpressionRequiredStatePresent() { this.state += "hear me roar"; ((ExpressionRegistry) this.state[typeof(ExpressionRegistry)]).AddType(typeof(FooWithRequiredState)); SDF.Eval(this.state, "FooWithRequiredState"); Assert.AreEqual("I am FooWithRequiredState hear me roar\n", this.output.ToString()); }
public void Evaluate(SDFState state, string name, Hashtable arguments) { Console.WriteLine("Dude this is {0}", arguments["message"]); }
public static object CreateExpression(SDFState state, string name, Hashtable arguments) { return new FooAsFactory(name); }
public void Evaluate(SDFState state, string name, Hashtable arguments) { if (name != GetType().Name) { this.rootExpressionChildren.Evaluate(state); } }
public void Evaluate(SDFState state, string name, Hashtable arguments) { System.Console.WriteLine("I am {0}", this.name); }
public static object CreateExpression(SDFState state, string name, Hashtable arguments) { TokenExpression o = new TokenExpression(); ((TokenStringRegistry) state[typeof(TokenStringRegistry)]).AddObject(arguments["name"].ToString(), o.Token); return o; }
public void Evaluate(SDFState state, string name, Hashtable arguments) { System.Console.WriteLine("I am FooWithRequiredParamClassLevel {0}", arguments["argument"]); }
public void PostCreateExpression(SDFState state, string name, Hashtable arguments, ParsedExpressionList children) { this.rootExpressionChildren = children; }
public void Evaluate(SDFState state, string name, Hashtable arguments) { System.Console.WriteLine("I am FooWithRequiredState {0}", state[typeof(string)]); }
public string Evaluate(SDFState state, ArrayList arguments) { TokenResult result = new TokenResult(); state += result; try { parent.EvaluateChildExpressions(state); } finally { state -= result; } return result.Result; }
public string Evaluate(SDFState state, ArrayList arguments) { return arguments[1].ToString().ToUpper(); }
public object CreateExpression(SDFState state, string name, Hashtable arguments) { if (name == GetType().Name) { object o = new Expression(); ((ExpressionRegistry) state[typeof(ExpressionRegistry)]).AddObject(arguments["name"].ToString(), o); return o; } else { return this; } }
public object Evaluate(SDFState state, string name, Hashtable arguments) { return isTrue; }
public void Evaluate(SDFState state) { Evaluate(this, state); }
public string ToString(SDFState state) { StringBuilder returnString = new StringBuilder(); if (this.arguments.Count > 0) { MethodInfo method = this.Token.GetType().GetMethod("Evaluate"); // Call the token with the arguments returnString.Append(method.Invoke(this.Token, new Object[] { state, this.arguments }).ToString()); } else { foreach (object o in this.elements) { if (o is TokenString) { returnString.Append(((TokenString) o).ToString(state)); } else { returnString.Append(o.ToString()); } } } return returnString.ToString(); }