c# - How to convert a LambdaExpression to typed Expression<Func<T, T>> -


i'm dynamically building linq queries nhibernate.

due dependencies, wanted cast/retrieve typed expression @ later time, have been unsuccessfull far.

this not working (the cast supposed happen elsewhere):

var functype = typeof (func<,>).makegenerictype(entitytype, typeof (bool)); var typedexpression =  (func<t, bool>)expression.lambda(functype, itempredicate, parameter); //fails 

this working:

var typedexpression = expression.lambda<func<t, bool>>(itempredicate, parameter); 

is possible 'encapsulated' typed expression lambdaexpression?

var typedexpression =     (func<t, bool>)expression.lambda(functype, itempredicate, parameter); //fails 

this not surprising, have compile lambdaexpression in order actual delegate can invoked (which func<t, bool> is).

so work, 'm not sure if need:

// no longer expression , cannot used iqueryable var mydelegate =     (func<t, bool>)     expression.lambda(functype, itempredicate, parameter).compile(); 

if not looking compile expression instead move expression tree around, solution instead cast expression<func<t, bool>>:

var typedexpression = (expression<func<t, bool>>)                        expression.lambda(functype, itempredicate, parameter); 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -