@@ -51,9 +51,15 @@ public static Expression Normalize(Expression node)
51
51
return normalizer . Visit ( node ) ;
52
52
}
53
53
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>
54
60
protected override Expression VisitBinary ( BinaryExpression node )
55
61
{
56
- node = FlipBinaryExpression ( node ) ;
62
+ node = EnsureConstantIsOnRight ( node ) ;
57
63
58
64
Expression result = null ;
59
65
if ( node . Left . NodeType == ExpressionType . Call && node . Right . NodeType == ExpressionType . Constant )
@@ -62,13 +68,13 @@ protected override Expression VisitBinary(BinaryExpression node)
62
68
var constant = ( ConstantExpression ) node . Right ;
63
69
if ( mex . Method . DeclaringType . FullName == "Microsoft.VisualBasic.CompilerServices.Operators" )
64
70
{
65
- //VB creates expression trees with "special" operators
71
+ // VB creates expression trees with "special" operators
66
72
result = VisitVBCompilerServicesOperators ( mex , node . NodeType , constant ) ;
67
73
}
68
74
else if ( mex . Method . DeclaringType == typeof ( string ) && mex . Method . Name == "get_Chars" && constant . Type == typeof ( char ) )
69
75
{
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#
72
78
result = Expression . MakeBinary (
73
79
node . NodeType ,
74
80
Expression . Convert ( mex , typeof ( int ) ) ,
@@ -84,27 +90,33 @@ protected override Expression VisitBinary(BinaryExpression node)
84
90
return base . VisitBinary ( node ) ;
85
91
}
86
92
93
+ /// <summary>
94
+ /// Visits a UnaryExpression.
95
+ /// </summary>
96
+ /// <param name="node">The UnaryExpression.</param>
97
+ /// <returns>The UnaryExpression (possibly modified).</returns>
87
98
protected override Expression VisitUnary ( UnaryExpression node )
88
99
{
89
100
if ( node . NodeType == ExpressionType . Convert )
90
101
{
91
102
if ( node . Type . IsAssignableFrom ( node . Operand . Type ) )
92
103
{
104
+ // ignore the unnecessary conversion added by VB
93
105
return Visit ( node . Operand ) ;
94
106
}
95
107
}
96
108
97
109
return base . VisitUnary ( node ) ;
98
110
}
99
111
100
- private BinaryExpression FlipBinaryExpression ( BinaryExpression node )
112
+ private BinaryExpression EnsureConstantIsOnRight ( BinaryExpression node )
101
113
{
102
114
var left = node . Left ;
103
115
var right = node . Right ;
104
116
var operatorType = node . NodeType ;
105
117
if ( left . NodeType == ExpressionType . Constant )
106
118
{
107
- right = node . Left as ConstantExpression ;
119
+ right = node . Left ;
108
120
left = node . Right ;
109
121
// if the constant was on the left some operators need to be flipped
110
122
switch ( operatorType )
0 commit comments