Why can't I create the same Expression Tree manually that my straight lambda produces?

Check the documentation: the '+' operator is actually not defined in the String class. I guess the compiler just knows it means "concatenate the strings", and it transforms it into a call to Concat So when you call Expression. Add you need to specify the method that implements the operation (in that case the String.

Concat method) I decompiled the expression with Reflector, it gives the following result (reformatted): ParameterExpression expression2; Expression> expression = Expression. Lambda>( Expression. Add( Expression.

Add( Expression. Constant("This ", typeof(string)), Expression. Condition( Expression.

Equal( expression2 = Expression. Parameter(typeof(string), "Insert"), Expression. Constant("", typeof(string)), false, (MethodInfo) methodof(string.

Op_Equality)), Expression. Constant("", typeof(string)), Expression. Add( expression2, Expression.

Constant(" ", typeof(string)), (MethodInfo) methodof(string. Concat))), (MethodInfo) methodof(string. Concat)), Expression.

Constant("That", typeof(string)), (MethodInfo) methodof(string. Concat)), new ParameterExpression { expression2 }) (Note that methodof is not an actual operator, its just what Reflector shows for the ldtoken IL instruction. In C# you have to retrieve the method using reflection.).

Check the documentation: the '+' operator is actually not defined in the String class. I guess the compiler just knows it means "concatenate the strings", and it transforms it into a call to Concat. So when you call Expression.

Add, you need to specify the method that implements the operation (in that case the String. Concat method). I decompiled the expression with Reflector, it gives the following result (reformatted): ParameterExpression expression2; Expression> expression = Expression.

Lambda>( Expression. Add( Expression. Add( Expression.

Constant("This ", typeof(string)), Expression. Condition( Expression. Equal( expression2 = Expression.

Parameter(typeof(string), "Insert"), Expression. Constant("", typeof(string)), false, (MethodInfo) methodof(string. Op_Equality)), Expression.

Constant("", typeof(string)), Expression. Add( expression2, Expression. Constant(" ", typeof(string)), (MethodInfo) methodof(string.

Concat))), (MethodInfo) methodof(string. Concat)), Expression. Constant("That", typeof(string)), (MethodInfo) methodof(string.

Concat)), new ParameterExpression { expression2 }); (Note that methodof is not an actual operator, its just what Reflector shows for the ldtoken IL instruction. In C# you have to retrieve the method using reflection. ).

1, but for clarity, a concise example: Expression. Add(Expression. Constant("a"), Expression.

Constant("b"), typeof(string). GetMethod("Concat", new { typeof(string), typeof(string) })); – Kirk Woll Oct 4 '10 at 19:33 You know chalk this up to just plain debug blindness. I ran it through again.

Never even thought to look at the Method Property 8-O Yet there it is System.String.Concat.... Thanks for the quick response clearing me up :-) – TofuBug Oct 4 '10 at 19:45.

ParameterExpression Insert = Expression. ConstantExpression This = Expression. ConstantExpression That = Expression.

ConstantExpression Space = Expression. ConstantExpression NoCharacter = Expression. BinaryExpression InsertPlusSpace = Expression.

BinaryExpression InsertEqualsNoCharacter = Expression. ConditionalExpression InsertPlusSpaceOrNothing = Expression. BinaryExpression ThisPlusInsertPlusSpaceOrNothing = Expression.

BinaryExpression ThisPlusInsertPlusSpaceOrNothingPlusThat = Expression. Lambda Lambda = Expression. BinaryExpression InsertPlusSpace = Expression.

BinaryExpression InsertPlusSpace = Expression.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions