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

share|improve this question

68% accept rate
It can be done; do you have an example of a source expression and what you'd want to convert it to? – Jacob Sep 16 '11 at 20:12
no its first time i am trying to create one and have no idea where to start with – Muhammad Adeel Zahid Sep 16 '11 at 20:14
args is array of source lambdas of type Expression<Func<T,object>> and i want to convert them as written in second code snippet – Muhammad Adeel Zahid Sep 16 '11 at 20:20
feedback

1 Answer

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.

share|improve this answer
Jay its not body of my method. its example of target expression that i want to achieve starting from Expression<Func<T,object>>. target is to create an expression of type Expression<Func<object,bool?>> if object is nullable and Expression<Func<object,bool>> otherwise. – Muhammad Adeel Zahid Sep 17 '11 at 6:38
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.