views:

43

answers:

1

lets say i have :

anything.where(x=>x.age == int.parse(txtage.text));

now i know that int.parse(txtage.text) is an expression of type ExpressionType.Convert

now i wanna know how to create an expression of type ExpressionType.Convert manually (programatically)

why ?

because im passing expressions between layers and changing the type of it , i managed make a visit to every expression and rebuild it except for

case ExpressionType.Convert:

any idea ? thanks in advance.

+1  A: 

No, int.Parse(txtage.text) is a method call, not a conversion expression. You'd build it using Expression.Call.

However, if you do want to build a conversion expression, use Expression.Convert.

Jon Skeet
actually that lambda expression gets converted to x => (Convert(x.age) == Convert(Convert(Parse(value(type).ddlage.text))))
Stacker
so i get it catched in case ExpressionType.Convert:
Stacker
@Stacker: Well you haven't told us any of the types involved... is `x.age` not an int?
Jon Skeet
its int but still it needs to convert it for some reason
Stacker
any way i managed to make Convert expression System.Linq.Expressions.Expression.MakeUnary(ExpressionType.Convert, newoperand,type) now im trying to make call expression
Stacker
@Stacker: If it's already an int, I wouldn't *expect* to see a convert call. Could you show a short but complete program demonstrating this? What type is it converting to?
Jon Skeet