简体   繁体   中英

Creating dynamic Lambda from Existing Lambda Expression

i have an extension method that configures the filtering for telerik grid. it receives lambda expressions as parameter. is it possible to make new expressions from existing ones eg

public static void ConfigureFiltering<T>(this HtmlHelper html, Configurator conf, params Expression<Func<T,object>>[] args) where T:class 
{
 }   

i want to create expressions like

Expression<Func<object,bool?>> filtere = obj=>obj == null? null: obj.ToString().StartsWith("xyz");//return type is nullable cause of string
Expression<Func<object,bool>> filtere = obj=>Convert.ToInt32(obj) < 20 //return type is non-nullable cause of int

can someone plz guide me how to target this problem

I'm not sure what the problem is that you're having, nor how the first and second parts of your question relate.

I can tell you that the ternary operator in your first expression will need to cast that null to bool? , so it will become:

Expression<Func<object,bool?>> filtere = obj=>obj == null
    ? (bool?)null 
    : obj.ToString().StartsWith("xyz");

Also, both expressions cannot share the same variable name of filtere .

Beyond that, you'll need to explain in somewhat more detail what you are trying to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM