Lambda to Expression tree conversion

前端 未结 3 449
死守一世寂寞
死守一世寂寞 2020-12-29 01:36

I will keep it really simple,

How do I get expression tree out of lambda??

or from query expression ?

3条回答
  •  情话喂你
    2020-12-29 02:11

    You must assign the lambda to a different type:

    // Gives you a delegate:
    Func f = x => x * 2;
    // Gives you an expression tree:
    Expression> g = x => x * 2;
    

    The same goes for method arguments. However, once you've assigned such a lambda expression to a Func<> type, you can't get the expression tree back.

提交回复
热议问题