@@ -51,9 +51,15 @@ public static Expression Normalize(Expression node)
5151 return normalizer . Visit ( node ) ;
5252 }
5353
54+ // protected methods
55+ /// <summary>
56+ /// Visits a BinaryExpression.
57+ /// </summary>
58+ /// <param name="node">The BinaryExpression.</param>
59+ /// <returns>The BinaryExpression (possibly modified).</returns>
5460 protected override Expression VisitBinary ( BinaryExpression node )
5561 {
56- node = FlipBinaryExpression ( node ) ;
62+ node = EnsureConstantIsOnRight ( node ) ;
5763
5864 Expression result = null ;
5965 if ( node . Left . NodeType == ExpressionType . Call && node . Right . NodeType == ExpressionType . Constant )
@@ -62,13 +68,13 @@ protected override Expression VisitBinary(BinaryExpression node)
6268 var constant = ( ConstantExpression ) node . Right ;
6369 if ( mex . Method . DeclaringType . FullName == "Microsoft.VisualBasic.CompilerServices.Operators" )
6470 {
65- //VB creates expression trees with "special" operators
71+ // VB creates expression trees with "special" operators
6672 result = VisitVBCompilerServicesOperators ( mex , node . NodeType , constant ) ;
6773 }
6874 else if ( mex . Method . DeclaringType == typeof ( string ) && mex . Method . Name == "get_Chars" && constant . Type == typeof ( char ) )
6975 {
70- //VB creates string index expressions using character comparison whereas C# uses ascii value comparison
71- //So , we make VB's string index comparison look like C#.
76+ // VB creates string index expressions using character comparison whereas C# uses ascii value comparison
77+ // so , we make VB's string index comparison look like C#
7278 result = Expression . MakeBinary (
7379 node . NodeType ,
7480 Expression . Convert ( mex , typeof ( int ) ) ,
@@ -84,27 +90,33 @@ protected override Expression VisitBinary(BinaryExpression node)
8490 return base . VisitBinary ( node ) ;
8591 }
8692
93+ /// <summary>
94+ /// Visits a UnaryExpression.
95+ /// </summary>
96+ /// <param name="node">The UnaryExpression.</param>
97+ /// <returns>The UnaryExpression (possibly modified).</returns>
8798 protected override Expression VisitUnary ( UnaryExpression node )
8899 {
89100 if ( node . NodeType == ExpressionType . Convert )
90101 {
91102 if ( node . Type . IsAssignableFrom ( node . Operand . Type ) )
92103 {
104+ // ignore the unnecessary conversion added by VB
93105 return Visit ( node . Operand ) ;
94106 }
95107 }
96108
97109 return base . VisitUnary ( node ) ;
98110 }
99111
100- private BinaryExpression FlipBinaryExpression ( BinaryExpression node )
112+ private BinaryExpression EnsureConstantIsOnRight ( BinaryExpression node )
101113 {
102114 var left = node . Left ;
103115 var right = node . Right ;
104116 var operatorType = node . NodeType ;
105117 if ( left . NodeType == ExpressionType . Constant )
106118 {
107- right = node . Left as ConstantExpression ;
119+ right = node . Left ;
108120 left = node . Right ;
109121 // if the constant was on the left some operators need to be flipped
110122 switch ( operatorType )
0 commit comments