Improvements we found usefull

Topics: New Features
Dec 11, 2012 at 8:20 AM

Hello and congratulations for this wonderful expressions engine!

We are using it a lot in our projects and we made some small improvements to it to fit more complex scenarios.

Some of them they are:

1. In "EvaluationVisitor.cs"

     case BinaryExpressionType.And:

You are doing something like this:

Result = Convert.ToBoolean(left()) && Convert.ToBoolean(right());

You should check first if left() is false and if is false, skip right() evaluation and return directly false. (false && anything else) will return false.

2. Same thing for case BinaryExpressionType.Or

If left() returns true, you can return true without evaluating right()

3. In "EvaluationVisitor.cs"

    case BinaryExpressionType.Plus

You have

if (left() is string)
{
       Result = String.Concat(left(), right());
}

We changed it to

if (left() is string || right() is string)

because sometimes left() was returning null and it wasn't recognized as a string.

4. We made some conventions about Add, Substract, Divide and Modulo.

If any of the parameters is null, we set it to the default mathematical value. (For example for Add will be 0). We also checked for division by 0 and other things like this

Enjoy programming!