tags:

views:

299

answers:

1

I'm just starting out playing around with Linq Expressions and I've hit a wall. I need to create an Expression Tree from an Action. Unfortunetly I can't get the Action as an Expression, this is basically what I've got to work with:

public void Something(Action action){}

I need access to the body of the Action to extract variables and values.

+2  A: 

An Action is not an Expression; it is simply a delegate (that might have been an expression at some point, might have been a lambda, and might not have been either).

To make this workable, you would need to refactor to:

public void Something(Expression<Action> action) {...}

Also, C# 3.0 / .NET 3.5 lambda expressions don't work very well for Action-type expressions. You are very limited in what you can express. Func-type expressions work better. In .NET 4.0 (CTP) there is much more flexibility here, although it still isn't clear what the language (C# 4.0) will offer by way of lambdas.

Basically, I'm not sure that you can (conveniently) do what you hope using Expression.

Marc Gravell
That's what I thought. This is an Action coming from a Boo file, so luckly I can get access to the Boo expressions and get what I need :)
Chris Canal