Dec 1, 2009 at 12:11 AM
Edited Jan 25, 2010 at 11:32 PM
I had the same requirement last week and changed the Flee library to cater for this. Two issues had to be addressed:
a) The expression tree that FLEE builds up during parsing is not accessible publicly
b) The FLEE library is too strict about types for this usage pattern. In my case I don’t know the type of the expression
"MyMethod(\"ABC\")" until later.
To overcome these hurdles I modified the Flee library so that it exposes the AST (Abstract Syntax Tree) that it creates during parsing. In addition all expression elements are now public and support the visitor pattern in conjunction with an abstract ExpressionWalker
class (the visitor). The ExpressionWalker is analogous to the TreeWalker that IronPython offers. Finally a flag controls whether type checks should be performed during parsing.
Here is a sample code snippet that demonstrates the usage. The AstPrinter class derives from the new ExpressionWalker class and writes out information about the various expression elements.
ExpressionContext expressionContext = new
IDynamicExpression expression = expressionContext.CompileDynamic("Value(\"..Blah\") + Value(\"..Blah1\", 15)");
RootExpressionElement rootElement = ((Expression<object>)expression).RootElement;
AstPrinter astPrinter = new
You can download the code from here:
http://www.hessmer.org/dev/Flee/Flee-0.9.26.0_WithExpressionWalker.zip. The solution contains an additional C# project called FleeLibraryPlayground that demonstrates the usage of the ExpressionWalker class.
Thank you, Eciloci, for sharing your great library! Without your source code I would have been stuck.