-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Labels
Description
The fallowing is the expression view using Readable Expressions from a code block expression.
var result = 1;
while (true)
{
if (value > 1)
{
result= result * value;
value--;
}
else
{
break;
}
}This is the same block used in the loop expression chapter from Microsoft Expression Tree learning
// Creating a parameter expression.
ParameterExpression value = Expression.Parameter(typeof(int), "value");
// Creating an expression to hold a local variable.
ParameterExpression result = Expression.Parameter(typeof(int), "result");
// Creating a label to jump to from a loop.
LabelTarget label = Expression.Label(typeof(int));
// Creating a method body.
BlockExpression block = Expression.Block(
new[] { result },
Expression.Assign(result, Expression.Constant(1)),
Expression.Loop(
Expression.IfThenElse(
Expression.GreaterThan(value, Expression.Constant(1)),
Expression.MultiplyAssign(result,
Expression.PostDecrementAssign(value)),
Expression.Break(label, result)
),
label
)
);Basically the interpreted code lacks the return statement, which should be like => return result;