@@ -80,16 +80,7 @@ public override Expression Visit(Expression expression)
80
80
if ( expression . NodeType == ExpressionType . Lambda || ! _partialEvaluationInfo . IsEvaluatableExpression ( expression ) ||
81
81
#region NH additions
82
82
// Variables should be evaluated only when they are part of an evaluatable expression (e.g. o => string.Format("...", variable))
83
- expression is UnaryExpression unaryExpression &&
84
- (
85
- ExpressionsHelper . IsVariable ( unaryExpression . Operand , out _ , out _ ) ||
86
- // Check whether the variable is casted due to comparison with a nullable expression
87
- // (e.g. o.NullableShort == shortVariable)
88
- unaryExpression . Operand is UnaryExpression subUnaryExpression &&
89
- unaryExpression . Type . UnwrapIfNullable ( ) == subUnaryExpression . Type &&
90
- ExpressionsHelper . IsVariable ( subUnaryExpression . Operand , out _ , out _ )
91
- )
92
- )
83
+ ContainsVariable ( expression ) )
93
84
#endregion
94
85
return base . Visit ( expression ) ;
95
86
@@ -162,8 +153,27 @@ private Expression EvaluateSubtree(Expression subtree)
162
153
}
163
154
}
164
155
156
+ #region NH additions
157
+
158
+ private bool ContainsVariable ( Expression expression )
159
+ {
160
+ if ( ! ( expression is UnaryExpression unaryExpression ) )
161
+ {
162
+ return false ;
163
+ }
164
+
165
+ return ExpressionsHelper . IsVariable ( unaryExpression . Operand , out _ , out _ ) ||
166
+ // Check whether the variable is casted due to comparison with a nullable expression
167
+ // (e.g. o.NullableShort == shortVariable)
168
+ unaryExpression . Operand is UnaryExpression subUnaryExpression &&
169
+ unaryExpression . Type . UnwrapIfNullable ( ) == subUnaryExpression . Type &&
170
+ ExpressionsHelper . IsVariable ( subUnaryExpression . Operand , out _ , out _ ) ;
171
+ }
172
+
165
173
#endregion
166
-
174
+
175
+ #endregion
176
+
167
177
protected override Expression VisitConstant ( ConstantExpression expression )
168
178
{
169
179
if ( expression . Value is Expression value )
0 commit comments