Search code examples
c#dynamicexpression-trees

Compiling statement collection to an action


So lets say I want to return an action like so ...

public Action<T1, T2> BuildActionFrom(object[] stuff)
{
     BinaryExpression[] expressions = BuildExpressions(stuff);
     return (x,y) => {
          foreach(var ex in expressions) ex(x,y);
     };
}

... how might I go about building this as I can't find anyhting in the expression building api that seems to allow me to build that return value?

Each of my expressions are pretty simple (basic property assignments and what not), I just can't figure out how to put them together.


Solution

  • Found it ...

    Expression.Block(expressions);
    

    ... was what i was looking for!