@@ -88,8 +88,17 @@ Expression CompileBinary(ParameterExpression dataItemExpr, IList criteriaJson) {
8888 if ( _stringToLower && clientValue is String )
8989 clientValue = ( ( string ) clientValue ) . ToLower ( ) ;
9090
91- if ( ( accessorExpr . Type == typeof ( Guid ) || accessorExpr . Type == typeof ( Guid ? ) ) && IsInequality ( expressionType ) )
92- return CompileGuidComparison ( accessorExpr , expressionType , clientValue ) ;
91+ if ( IsInequality ( expressionType ) ) {
92+ if ( accessorExpr . Type == typeof ( Guid ) || accessorExpr . Type == typeof ( Guid ? ) ) {
93+ var method = typeof ( Guid ) . GetMethod ( nameof ( Guid . CompareTo ) , new [ ] { typeof ( Guid ) } ) ;
94+ return CompileCompareToCall ( accessorExpr , expressionType , clientValue , method ) ;
95+ }
96+
97+ if ( Utils . StripNullableType ( accessorExpr . Type ) . IsEnum ) {
98+ var method = typeof ( Enum ) . GetMethod ( nameof ( Enum . CompareTo ) , new [ ] { typeof ( object ) } ) ;
99+ return CompileCompareToCall ( accessorExpr , expressionType , clientValue , method ) ;
100+ }
101+ }
93102
94103 Expression valueExpr = Expression . Constant ( clientValue , accessorExpr . Type ) ;
95104
@@ -120,16 +129,16 @@ bool IsInequality(ExpressionType type) {
120129 return type == ExpressionType . LessThan || type == ExpressionType . LessThanOrEqual || type == ExpressionType . GreaterThanOrEqual || type == ExpressionType . GreaterThan ;
121130 }
122131
123- Expression CompileGuidComparison ( Expression accessorExpr , ExpressionType expressionType , object clientValue ) {
132+ Expression CompileCompareToCall ( Expression accessorExpr , ExpressionType expressionType , object clientValue , MethodInfo compareToMethod ) {
124133 if ( clientValue == null )
125134 return Expression . Constant ( false ) ;
126135
127136 var result = Expression . MakeBinary (
128137 expressionType ,
129138 Expression . Call (
130139 Utils . IsNullable ( accessorExpr . Type ) ? Expression . Property ( accessorExpr , "Value" ) : accessorExpr ,
131- typeof ( Guid ) . GetMethod ( nameof ( Guid . CompareTo ) , new [ ] { typeof ( Guid ) } ) ,
132- Expression . Constant ( clientValue , typeof ( Guid ) )
140+ compareToMethod ,
141+ Expression . Constant ( clientValue , compareToMethod . GetParameters ( ) [ 0 ] . ParameterType )
133142 ) ,
134143 Expression . Constant ( 0 )
135144 ) ;
0 commit comments