@@ -80,16 +80,7 @@ public override Expression Visit(Expression expression)
8080 if ( expression . NodeType == ExpressionType . Lambda || ! _partialEvaluationInfo . IsEvaluatableExpression ( expression ) ||
8181 #region NH additions
8282 // 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 ) )
9384 #endregion
9485 return base . Visit ( expression ) ;
9586
@@ -162,8 +153,27 @@ private Expression EvaluateSubtree(Expression subtree)
162153 }
163154 }
164155
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+
165173 #endregion
166-
174+
175+ #endregion
176+
167177 protected override Expression VisitConstant ( ConstantExpression expression )
168178 {
169179 if ( expression . Value is Expression value )
0 commit comments