D
D
divinerat2014-08-03 23:12:58
C++ / C#
divinerat, 2014-08-03 23:12:58

How to recursively decompose an expression tree?

// Creating an expression tree.
Expression<Func<int, int>> expr = num => (num * 5)+ (num * 4);

// Compiling the expression tree into a delegate.
Func<int, int> result = expr.Compile();

var r = result(4);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Antonenko, 2014-09-10
@dabrahabra

The right way is to use the Expression Tree Visitor: an example from MSDN . This class allows you to traverse the entire tree and even modify it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question