public static string GetExpressionString(Expression node) { var exprMachine = new ExpressionMachine(); exprMachine.Visit(node); return(exprMachine.s); }
protected override Expression VisitMethodCall(MethodCallExpression node) { var functionName = node.Method.Name; var machine = new ExpressionMachine(); machine.Visit(node.Arguments[0]); var argString = machine.s; s += Indent() + functionName + " " + argString + ";\n"; return(base.VisitMethodCall(node)); }
protected override Expression VisitBinary(BinaryExpression node) { var machine = new ExpressionMachine(); var type = node.NodeType; var leftExpr = GetExpressionString(node.Left); var rightExpr = GetExpressionString(node.Right); if (IsAssigningLocation(node, out var thing)) { s += Indent() + "Now " + thing + " is in " + rightExpr + ";\n"; } else if (type == ExpressionType.Assign) { s += Indent() + "Now " + leftExpr + " is " + rightExpr + ";\n"; } return(base.VisitBinary(node)); }
string OutputRule(Rule rule) { var s = rule.type.ToString() + " " + rule.applyingTo.name; if (rule.condition != null) { s += " when "; var expr = rule.condition; if (expr is Expression <Predicate <Thing> > thingExpr) { var visitor = new ExpressionMachine(); visitor.Visit(expr); s += visitor.s + ":\n"; } } s += OutputRuleBody(rule); return(s); }