c# - How to create Expression<Func<TModel, TProperty>>; -


is possible create expression<func<tmodel, bool>>() can used in different htmlhelpers (for instance in checkboxfor()), if have model object

this htmlhelper<tmodel> htmlhelper 

and name of property (through reflection).

sure:

static expression<func<tmodel,tproperty>> createexpression<tmodel,tproperty>(     string propertyname) {     var param = expression.parameter(typeof(tmodel), "x");     return expression.lambda<func<tmodel, tproperty>>(         expression.propertyorfield(param, propertyname), param); } 

then:

var lambda = createexpression<somemodel, bool>("isalive"); 

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 -