Lambda to Expression tree conversion

前端 未结 3 458
死守一世寂寞
死守一世寂寞 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条回答
  •  猫巷女王i
    2020-12-29 01:59

    Konrad's reply is exact. You need to assign the lambda expression to Expression> in order for the compiler to generate the expression tree. If you get a lambda as a Func<...>, Action<...> or other delegate type, all you have is a bunch of IL instructions.

    If you really need to be able to convert an IL-compiled lambda back into an expression tree, you'd have to decompile it (e.g. do what Lutz Roeder's Reflector tool does). I'd suggest having a look at the Cecil library, which provides advanced IL manipulation support and could save you quite some time.

提交回复
热议问题