Question

I'm confused on which expression trees need to be added to a blockexpression when wanting code to be executed.

For example, if I have ConditionalExpression, that has a reference to an IsTrue and IsFalse. Do I need to include the expressions that are for IsTrue and IsFalse. or just the Conditional Expression?

Is there a guideline, i.e. how do the IEnumerable of Expressions get executed? Do they get executed in the order they appear in the IEnumerable?

Was it helpful?

Solution

Expression trees work very similarly to C# code: there all the statements inside a block (delimited by {}) are executed in order. So, that's exactly how Expression.Block() is evaluated too: all the expressions in its Expressions collection are evaluated in order. If you want to have a ConditionalExpression inside the block, then you shouldn't put them directly into the block (unless you also want them evaluated separately, outside of the ConditionalExpression).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top