@@ -47,29 +47,31 @@ public static void BuildFilter(IndexInfo index)
4747 protected override Expression VisitBinary ( BinaryExpression b )
4848 {
4949 if ( EnumRewritableOperations ( b ) ) {
50- var bareLeft = b . Left . StripCasts ( ) ;
51- var bareLeftType = bareLeft . Type . StripNullable ( ) ;
52- var bareRight = b . Right . StripCasts ( ) ;
53- var bareRightType = bareRight . Type . StripNullable ( ) ;
54-
55- if ( bareLeftType . IsEnum && bareRight . NodeType == ExpressionType . Constant ) {
56- var typeToCast = bareLeft . Type . IsNullable ( )
50+ var leftNoCasts = b . Left . StripCasts ( ) ;
51+ var leftNoCastsType = leftNoCasts . Type ;
52+ var bareLeftType = leftNoCastsType . StripNullable ( ) ;
53+ var rightNoCasts = b . Right . StripCasts ( ) ;
54+ var rightNoCastsType = rightNoCasts . Type ;
55+ var bareRightType = rightNoCastsType . StripNullable ( ) ;
56+
57+ if ( bareLeftType . IsEnum && rightNoCasts . NodeType == ExpressionType . Constant ) {
58+ var typeToCast = leftNoCastsType . IsNullable ( )
5759 ? bareLeftType . GetEnumUnderlyingType ( ) . ToNullable ( )
58- : bareLeft . Type . GetEnumUnderlyingType ( ) ;
60+ : leftNoCastsType . GetEnumUnderlyingType ( ) ;
5961
6062 return base . VisitBinary ( Expression . MakeBinary (
6163 b . NodeType ,
62- Expression . Convert ( bareLeft , typeToCast ) ,
64+ Expression . Convert ( leftNoCasts , typeToCast ) ,
6365 Expression . Convert ( b . Right , typeToCast ) ) ) ;
6466 }
65- else if ( bareRightType . IsEnum && bareLeft . NodeType == ExpressionType . Constant ) {
66- var typeToCast = bareRight . Type . IsNullable ( )
67+ else if ( bareRightType . IsEnum && leftNoCasts . NodeType == ExpressionType . Constant ) {
68+ var typeToCast = rightNoCastsType . IsNullable ( )
6769 ? bareRightType . GetEnumUnderlyingType ( ) . ToNullable ( )
68- : bareRight . Type . GetEnumUnderlyingType ( ) ;
70+ : rightNoCastsType . GetEnumUnderlyingType ( ) ;
6971
7072 return base . VisitBinary ( Expression . MakeBinary (
7173 b . NodeType ,
72- Expression . Convert ( bareRight , typeToCast ) ,
74+ Expression . Convert ( rightNoCasts , typeToCast ) ,
7375 Expression . Convert ( b . Left , typeToCast ) ) ) ;
7476 }
7577 }
0 commit comments