Retrieving an expression tree from an action

I am just starting to play with Linq Expressions, and I hit the wall. I need to create an expression tree from Action. Unfortunately, I cannot get the action as an expression, this is basically what I need to work with:

public void Something(Action action){}

I need to access the body of an action to retrieve variables and values.

+3
source share
1 answer

An is Actionnot Expression; it's just a delegate (it could have been an expression at some point, maybe there was a lambda, and maybe not either).

To make this workable, you will need to reorganize:

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

, # 3.0/.NET 3.5 Action -type. , . Func - . .NET 4.0 (CTP) , , (# 4.0) .

, , () , , Expression.

+4

Source: https://habr.com/ru/post/1699362/


All Articles