开发者

Creating dynamic Lambda from Existing Lambda Expression

开发者 https://www.devze.com 2023-04-05 05:33 出处:网络
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 e.g

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 e.g

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号