@@ -80,7 +80,12 @@ private LambdaToDbExpressionVisitor(DynamicFilterDefinition filter, DbExpression
8080
8181 #region ExpressionVisitor Overrides
8282
83- private ConstantExpression GetByteConstant ( Expression expression )
83+ /// <summary>
84+ /// Attempts to try convert the expression into a byte. The expression must be a constant and in range of a byte.
85+ /// </summary>
86+ /// <param name="expression">The expression.</param>
87+ /// <returns>A expression converted to byte or null if the expression was not a constant or in range of a byte.</returns>
88+ private ConstantExpression TryGetByteConstant ( Expression expression )
8489 {
8590 if ( expression . NodeType != ExpressionType . Constant || expression . Type != typeof ( int ) )
8691 return null ;
@@ -94,6 +99,9 @@ private ConstantExpression GetByteConstant(Expression expression)
9499 return null ;
95100 }
96101
102+ /// <summary>Gets inner operand.</summary>
103+ /// <param name="expression">The expression.</param>
104+ /// <returns>The inner operand.</returns>
97105 private Expression GetInnerOperand ( Expression expression )
98106 {
99107 switch ( expression . NodeType ) {
@@ -110,6 +118,10 @@ private Expression GetInnerOperand(Expression expression)
110118 }
111119 }
112120
121+ /// <summary>If possible, we try to cast both side to byte otherwise we return the current BinaryExpression.</summary>
122+ /// <param name="node">The node.</param>
123+ /// <remarks>Pull: https://github.com/zzzprojects/EntityFramework.DynamicFilters/pull/164 </remarks>
124+ /// <returns>The BinaryExpression we try to cast both side to byte otherwise we return the current BinaryExpression.</returns>
113125 private BinaryExpression OptimizeByteEnumComparisons ( BinaryExpression node )
114126 {
115127 if ( node . Method != null )
@@ -136,12 +148,12 @@ private BinaryExpression OptimizeByteEnumComparisons(BinaryExpression node)
136148 if ( leftIsByteEnum )
137149 leftOperand = Expression . Convert ( leftOperand , typeof ( byte ) ) ;
138150 else
139- leftOperand = GetByteConstant ( leftOperand ) ;
151+ leftOperand = TryGetByteConstant ( leftOperand ) ;
140152
141153 if ( rightIsByteEnum )
142154 rightOperand = Expression . Convert ( rightOperand , typeof ( byte ) ) ;
143155 else
144- rightOperand = GetByteConstant ( rightOperand ) ;
156+ rightOperand = TryGetByteConstant ( rightOperand ) ;
145157
146158 if ( leftOperand == null || rightOperand == null )
147159 return node ;
0 commit comments