Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fixed a nasty bug related to flipping binary comparison operations wh…

…en the left side was a constant.
  • Loading branch information...
commit 112651a282ccccb6054528dd88e667f1b9bff145 1 parent 63581ce
Craig Wilson authored June 27, 2010
32  source/MongoDB/Linq/Translators/QueryBinder.cs
@@ -36,9 +36,37 @@ public Expression Bind(Expression expression)
36 36
 
37 37
         protected override Expression VisitBinary(BinaryExpression b)
38 38
         {
  39
+            ExpressionType nodeType = b.NodeType;
  40
+            bool shouldFlip = false;
  41
+            switch (nodeType)
  42
+            {
  43
+                case ExpressionType.LessThan:
  44
+                    nodeType = ExpressionType.GreaterThanOrEqual;
  45
+                    shouldFlip = true;
  46
+                    break;
  47
+                case ExpressionType.LessThanOrEqual:
  48
+                    nodeType = ExpressionType.GreaterThan;
  49
+                    shouldFlip = true;
  50
+                    break;
  51
+                case ExpressionType.GreaterThan:
  52
+                    nodeType = ExpressionType.LessThanOrEqual;
  53
+                    shouldFlip = true;
  54
+                    break;
  55
+                case ExpressionType.GreaterThanOrEqual:
  56
+                    nodeType = ExpressionType.LessThan;
  57
+                    shouldFlip = true;
  58
+                    break;
  59
+                case ExpressionType.NotEqual:
  60
+                    shouldFlip = true;
  61
+                    break;
  62
+                case ExpressionType.Equal:
  63
+                    shouldFlip = true;
  64
+                    break;
  65
+            }
  66
+
39 67
             //reverse the conditionals if the left one is a constant to make things easier in the formatter...
40  
-            if (b.Left.NodeType == ExpressionType.Constant)
41  
-                b = Expression.MakeBinary(b.NodeType, b.Right, b.Left, b.IsLiftedToNull, b.Method, b.Conversion);
  68
+            if (shouldFlip && b.Left.NodeType == ExpressionType.Constant)
  69
+                b = Expression.MakeBinary(nodeType, b.Right, b.Left, b.IsLiftedToNull, b.Method, b.Conversion);
42 70
 
43 71
             return base.VisitBinary(b);
44 72
         }

0 notes on commit 112651a

Please sign in to comment.
Something went wrong with that request. Please try again.