public Comparison (Operation op, IExpression e1, IExpression e2) : base (op, e1, e2) {}
override public object Eval (DataRow row)
+ {
+ return EvalBoolean (row);
+ }
+
+ public override bool EvalBoolean (DataRow row)
{
IComparable o1 = expr1.Eval (row) as IComparable;
IComparable o2 = expr2.Eval (row) as IComparable;
return (op == Operation.NE);
}
- switch(Compare (o1, o2, row.Table.CaseSensitive)) {
- case -1:
+ int result = Compare (o1, o2, row.Table.CaseSensitive);
+ if (result < 0) {
return (op == Operation.NE || op == Operation.LE || op == Operation.LT);
- case 0:
- default:
- return (op == Operation.EQ || op == Operation.LE || op == Operation.GE);
- case 1:
+ }
+ if (result > 0) {
return (op == Operation.NE || op == Operation.GE || op == Operation.GT);
}
+ // result == 0
+ return (op == Operation.EQ || op == Operation.LE || op == Operation.GE);
+
}
internal static int Compare (IComparable o1, IComparable o2, bool caseSensitive)
try {
if (o1 is string && Numeric.IsNumeric (o2))
- o1 = (IComparable)Convert.ChangeType (o1, o2.GetType ());
- if (o2 is string && Numeric.IsNumeric (o1))
- o2 = (IComparable)Convert.ChangeType (o2, o1.GetType ());
+ o1 = (IComparable) Convert.ChangeType (o1, o2.GetType ());
+ else if (o2 is string && Numeric.IsNumeric (o1))
+ o2 = (IComparable) Convert.ChangeType (o2, o1.GetType ());
+ else if (o1 is string && o2 is Guid)
+ o2 = o2.ToString ();
+ else if (o2 is string && o1 is Guid)
+ o1 = o1.ToString ();
} catch (FormatException) {
throw new EvaluateException (String.Format ("Cannot perform compare operation on {0} and {1}.", o1.GetType(), o2.GetType()));
}