Hi,
In the below code, what are the Body, Left and Right parts in the expression tree about?
BinaryExpression operation = (BinaryExpression)expression.Body;
ParameterExpression left = (ParameterExpression)operation.Left;
ConstantExpression right = (ConstantExpression)operation.Right;
Loading
Blocked AccountPosted Apr 4, 2011, 5:18 AM
The expression has subparts that has shown in the image below
VulpesPosted Apr 4, 2011, 6:35 AM
Would you mind moving the 'Accepted Answer' back to Manish's great post, as I wouldn't want to take any credit for my own post which was just to give you some code to play about with :)
Posted Apr 4, 2011, 6:08 AM
VulpesPosted Apr 4, 2011, 5:56 AM
Here's Manish's explanation expressed much more clumsily in code:
using System;
using System.Linq.Expressions;
class Test
{
static void Main()
{
Expression
Console.WriteLine(expression.Body.NodeType); // GreaterThan
BinaryExpression operation = (BinaryExpression)expression.Body;
ParameterExpression left = (ParameterExpression)operation.Left; // s
Console.WriteLine(left);
ConstantExpression right = (ConstantExpression)operation.Right; // 5
Console.WriteLine(right);
Console.ReadKey();
}
}
Posted Apr 4, 2011, 5:51 AM