Hello Mehdi,
This is some experimental code to tweak with the ExpressionVisitor:
static void Main(string[] args)
{
int a = 5;
int b = 100;
Expression<Func<int, bool>> expr = v => v > (a + b);
WalkVisitor w = new WalkVisitor();
w.Visit(expr);
}
public class WalkVisitor : ExpressionVisitor
{
protected override Expression VisitMember(MemberExpression node)
{
var e = base.VisitMember(node);
var c = node.Expression as ConstantExpression;
if (c != null)
{
Type t = c.Value.GetType();
var x = t.InvokeMember(node.Member.Name, BindingFlags.GetField,
null, c.Value, null);
Console.WriteLine("{0} = {1}", node.ToString(), x);
}
return e;
}
}
The output is:
value(ExprVisitor.Program+<>c__DisplayClass0).a = 5
value(ExprVisitor.Program+<>c__DisplayClass0).b = 100
You might need to implement a print visitor around this snippet...
Cheers
Andi