@@ -12,19 +12,18 @@ public static Result<Expression> Evaluate(QueryExpression expression, ParameterE
1212 switch ( expression )
1313 {
1414 case InfixExpression exp :
15- if ( exp . Left . GetType ( ) == typeof ( Identifier ) )
15+ if ( exp . Left is Identifier identifier )
1616 {
17- if ( ! propertyMapping . TryGetValue ( exp . Left . TokenLiteral ( ) , out var propertyName ) )
17+ if ( ! propertyMapping . TryGetValue ( identifier . TokenLiteral ( ) , out var propertyName ) )
1818 {
19- return Result . Fail ( $ "Invalid property '{ exp . Left . TokenLiteral ( ) } ' within filter") ;
19+ return Result . Fail ( $ "Invalid property '{ identifier . TokenLiteral ( ) } ' within filter") ;
2020 }
2121
2222 var property = Expression . Property ( parameterExpression , propertyName ) ;
2323 return EvaluateComparison ( property , exp . Right , exp . Operator , exp . Left ) ;
2424 }
25- else if ( exp . Left . GetType ( ) == typeof ( PropertyPath ) )
25+ else if ( exp . Left is PropertyPath propertyPath )
2626 {
27- var propertyPath = ( PropertyPath ) exp . Left ;
2827 var fullPath = propertyPath . GetFullPath ( ) ;
2928
3029 if ( ! propertyMapping . TryGetValue ( fullPath , out var propertyName ) )
@@ -346,16 +345,30 @@ private static Expression CreateNullableDateComparison(MemberExpression property
346345 var valueProperty = Expression . Property ( property , "Value" ) ;
347346 var dateProperty = Expression . Property ( valueProperty , "Date" ) ;
348347
349- Expression dateComparison = operatorKeyword switch
348+ Expression dateComparison ;
349+ switch ( operatorKeyword )
350350 {
351- Keywords . Eq => Expression . Equal ( dateProperty , value ) ,
352- Keywords . Ne => Expression . NotEqual ( dateProperty , value ) ,
353- Keywords . Lt => Expression . LessThan ( dateProperty , value ) ,
354- Keywords . Lte => Expression . LessThanOrEqual ( dateProperty , value ) ,
355- Keywords . Gt => Expression . GreaterThan ( dateProperty , value ) ,
356- Keywords . Gte => Expression . GreaterThanOrEqual ( dateProperty , value ) ,
357- _ => throw new ArgumentException ( $ "Unsupported operator for nullable date comparison: { operatorKeyword } ")
358- } ;
351+ case Keywords . Eq :
352+ dateComparison = Expression . Equal ( dateProperty , value ) ;
353+ break ;
354+ case Keywords . Ne :
355+ dateComparison = Expression . NotEqual ( dateProperty , value ) ;
356+ break ;
357+ case Keywords . Lt :
358+ dateComparison = Expression . LessThan ( dateProperty , value ) ;
359+ break ;
360+ case Keywords . Lte :
361+ dateComparison = Expression . LessThanOrEqual ( dateProperty , value ) ;
362+ break ;
363+ case Keywords . Gt :
364+ dateComparison = Expression . GreaterThan ( dateProperty , value ) ;
365+ break ;
366+ case Keywords . Gte :
367+ dateComparison = Expression . GreaterThanOrEqual ( dateProperty , value ) ;
368+ break ;
369+ default :
370+ throw new ArgumentException ( $ "Unsupported operator for nullable date comparison: { operatorKeyword } ") ;
371+ }
359372
360373 return operatorKeyword == Keywords . Ne
361374 ? Expression . OrElse ( Expression . Not ( hasValueProperty ) , dateComparison )
@@ -370,18 +383,36 @@ private static Result<ConstantExpression> GetIntegerExpressionConstant(int value
370383 var underlyingType = Nullable . GetUnderlyingType ( targetType ) ;
371384 var type = underlyingType ?? targetType ;
372385
373- object convertedValue = type switch
386+ object convertedValue ;
387+ switch ( type )
374388 {
375- Type t when t == typeof ( int ) => value ,
376- Type t when t == typeof ( long ) => Convert . ToInt64 ( value ) ,
377- Type t when t == typeof ( short ) => Convert . ToInt16 ( value ) ,
378- Type t when t == typeof ( byte ) => Convert . ToByte ( value ) ,
379- Type t when t == typeof ( uint ) => Convert . ToUInt32 ( value ) ,
380- Type t when t == typeof ( ulong ) => Convert . ToUInt64 ( value ) ,
381- Type t when t == typeof ( ushort ) => Convert . ToUInt16 ( value ) ,
382- Type t when t == typeof ( sbyte ) => Convert . ToSByte ( value ) ,
383- _ => throw new NotSupportedException ( $ "Unsupported numeric type: { targetType . Name } ")
384- } ;
389+ case Type t when t == typeof ( int ) :
390+ convertedValue = value ;
391+ break ;
392+ case Type t when t == typeof ( long ) :
393+ convertedValue = Convert . ToInt64 ( value ) ;
394+ break ;
395+ case Type t when t == typeof ( short ) :
396+ convertedValue = Convert . ToInt16 ( value ) ;
397+ break ;
398+ case Type t when t == typeof ( byte ) :
399+ convertedValue = Convert . ToByte ( value ) ;
400+ break ;
401+ case Type t when t == typeof ( uint ) :
402+ convertedValue = Convert . ToUInt32 ( value ) ;
403+ break ;
404+ case Type t when t == typeof ( ulong ) :
405+ convertedValue = Convert . ToUInt64 ( value ) ;
406+ break ;
407+ case Type t when t == typeof ( ushort ) :
408+ convertedValue = Convert . ToUInt16 ( value ) ;
409+ break ;
410+ case Type t when t == typeof ( sbyte ) :
411+ convertedValue = Convert . ToSByte ( value ) ;
412+ break ;
413+ default :
414+ throw new NotSupportedException ( $ "Unsupported numeric type: { targetType . Name } ") ;
415+ }
385416
386417 return Expression . Constant ( convertedValue , targetType ) ;
387418 }
0 commit comments