@@ -342,19 +342,19 @@ private static Expression CreateRightExprFromType(Type leftExprType, string righ
342342 targetType = typeof ( string ) ;
343343 }
344344 var values = right . Trim ( '[' , ']' ) . Split ( ',' ) . Select ( x => x . Trim ( ) ) . ToList ( ) ;
345- var elementType = targetType . IsArray ? targetType . GetElementType ( ) : targetType ;
346-
345+ var elementType = targetType . IsArray ? targetType . GetElementType ( ) ! : targetType ;
346+
347347 var expressions = values . Select ( x =>
348348 {
349349 if ( elementType == typeof ( string ) && x . StartsWith ( "\" " ) && x . EndsWith ( "\" " ) )
350350 {
351351 x = x . Trim ( '"' ) ;
352352 }
353-
353+
354354 var convertedValue = TypeConversionFunctions [ elementType ] ( x ) ;
355355 return Expression . Constant ( convertedValue , elementType ) ;
356356 } ) . ToArray ( ) ;
357-
357+
358358 var newArrayExpression = Expression . NewArrayInit ( elementType , expressions ) ;
359359 return newArrayExpression ;
360360 }
@@ -373,13 +373,13 @@ private static Expression CreateRightExprFromType(Type leftExprType, string righ
373373 dt = DateTime . SpecifyKind ( dt , DateTimeKind . Utc ) ;
374374 }
375375
376- var dtCtor = typeof ( DateTime ) . GetConstructor ( new [ ] { typeof ( long ) , typeof ( DateTimeKind ) } ) ;
376+ var dtCtor = typeof ( DateTime ) . GetConstructor ( new [ ] { typeof ( long ) , typeof ( DateTimeKind ) } ) ! ;
377377 var newExpr = Expression . New ( dtCtor , Expression . Constant ( dt . Ticks ) , Expression . Constant ( dt . Kind ) ) ;
378378
379379 var isNullable = rawType == typeof ( DateTime ? ) ;
380380 if ( ! isNullable ) return newExpr ;
381-
382- var nullableDtCtor = typeof ( DateTime ? ) . GetConstructor ( new [ ] { typeof ( DateTime ) } ) ;
381+
382+ var nullableDtCtor = typeof ( DateTime ? ) . GetConstructor ( new [ ] { typeof ( DateTime ) } ) ! ;
383383 newExpr = Expression . New ( nullableDtCtor , newExpr ) ;
384384 return newExpr ;
385385 }
@@ -388,32 +388,32 @@ private static Expression CreateRightExprFromType(Type leftExprType, string righ
388388 {
389389 var dtStyle = right . EndsWith ( "Z" ) ? DateTimeStyles . AdjustToUniversal : DateTimeStyles . AssumeLocal ;
390390 var dto = DateTimeOffset . Parse ( right , CultureInfo . InvariantCulture , dtStyle ) ;
391-
392- var dtoCtor = typeof ( DateTimeOffset ) . GetConstructor ( new [ ] { typeof ( long ) , typeof ( TimeSpan ) } ) ;
391+
392+ var dtoCtor = typeof ( DateTimeOffset ) . GetConstructor ( new [ ] { typeof ( long ) , typeof ( TimeSpan ) } ) ! ;
393393 var newExpr = Expression . New ( dtoCtor , Expression . Constant ( dto . Ticks ) , Expression . Constant ( dto . Offset ) ) ;
394394
395395 var isNullable = rawType == typeof ( DateTimeOffset ? ) ;
396396 if ( ! isNullable ) return newExpr ;
397-
398- var nullableDtoCtor = typeof ( DateTimeOffset ? ) . GetConstructor ( new [ ] { typeof ( DateTimeOffset ) } ) ;
397+
398+ var nullableDtoCtor = typeof ( DateTimeOffset ? ) . GetConstructor ( new [ ] { typeof ( DateTimeOffset ) } ) ! ;
399399 newExpr = Expression . New ( nullableDtoCtor , newExpr ) ;
400400 return newExpr ;
401401 }
402402
403403 if ( targetType == typeof ( DateOnly ) )
404404 {
405405 var date = DateOnly . Parse ( right , CultureInfo . InvariantCulture ) ;
406- var dateCtor = typeof ( DateOnly ) . GetConstructor ( new [ ] { typeof ( int ) , typeof ( int ) , typeof ( int ) } ) ;
406+ var dateCtor = typeof ( DateOnly ) . GetConstructor ( new [ ] { typeof ( int ) , typeof ( int ) , typeof ( int ) } ) ! ;
407407 var newExpr = Expression . New ( dateCtor , Expression . Constant ( date . Year ) , Expression . Constant ( date . Month ) , Expression . Constant ( date . Day ) ) ;
408408
409409 var isNullable = rawType == typeof ( DateOnly ? ) ;
410410 if ( ! isNullable ) return newExpr ;
411-
412- var nullableDateCtor = typeof ( DateOnly ? ) . GetConstructor ( new [ ] { typeof ( DateOnly ) } ) ;
411+
412+ var nullableDateCtor = typeof ( DateOnly ? ) . GetConstructor ( new [ ] { typeof ( DateOnly ) } ) ! ;
413413 newExpr = Expression . New ( nullableDateCtor , newExpr ) ;
414414 return newExpr ;
415415 }
416-
416+
417417 if ( targetType == typeof ( TimeOnly ) )
418418 {
419419 var time = TimeOnly . Parse ( right , CultureInfo . InvariantCulture ) ;
@@ -432,13 +432,13 @@ private static Expression CreateRightExprFromType(Type leftExprType, string righ
432432 }
433433 }
434434
435- var timeCtor = typeof ( TimeOnly ) . GetConstructor ( new [ ] { typeof ( int ) , typeof ( int ) , typeof ( int ) , typeof ( int ) , typeof ( int ) } ) ;
435+ var timeCtor = typeof ( TimeOnly ) . GetConstructor ( new [ ] { typeof ( int ) , typeof ( int ) , typeof ( int ) , typeof ( int ) , typeof ( int ) } ) ! ;
436436 var newExpr = Expression . New ( timeCtor , Expression . Constant ( time . Hour ) , Expression . Constant ( time . Minute ) , Expression . Constant ( time . Second ) , Expression . Constant ( millisecond ) , Expression . Constant ( microsecond ) ) ;
437437
438438 var isNullable = rawType == typeof ( TimeOnly ? ) ;
439439 if ( ! isNullable ) return newExpr ;
440-
441- var nullableTimeCtor = typeof ( TimeOnly ? ) . GetConstructor ( new [ ] { typeof ( TimeOnly ) } ) ;
440+
441+ var nullableTimeCtor = typeof ( TimeOnly ? ) . GetConstructor ( new [ ] { typeof ( TimeOnly ) } ) ! ;
442442 newExpr = Expression . New ( nullableTimeCtor , newExpr ) ;
443443 return newExpr ;
444444 }
@@ -500,8 +500,8 @@ private static Expression CreateRightExprFromType(Type leftExprType, string righ
500500 var constant = Expression . Constant ( enumValue , enumType ) ;
501501
502502 if ( rawType == enumType ) return constant ;
503-
504- var nullableCtor = rawType . GetConstructor ( new [ ] { enumType } ) ;
503+
504+ var nullableCtor = rawType . GetConstructor ( new [ ] { enumType } ) ! ;
505505 return Expression . New ( nullableCtor , constant ) ;
506506 }
507507
@@ -526,7 +526,7 @@ private static Type TransformTargetTypeIfNullable(Type targetType)
526526 {
527527 if ( targetType . IsNullable ( ) )
528528 {
529- targetType = Nullable . GetUnderlyingType ( targetType ) ;
529+ targetType = Nullable . GetUnderlyingType ( targetType ) ?? targetType ;
530530 }
531531
532532 return targetType ;
@@ -623,14 +623,19 @@ private static Parser<Expression> ComparisonExprParser<T>(ParameterExpression pa
623623 . SelectMany ( temp => rightSideValueParser , ( temp , right ) => new { temp . leftExpr , temp . op , right } )
624624 . Select ( temp =>
625625 {
626- if ( temp . leftExpr . NodeType == ExpressionType . Constant && ( ( ConstantExpression ) temp . leftExpr ) . Value ! . Equals ( true ) )
626+ if ( temp . leftExpr == null )
627+ {
628+ throw new InvalidOperationException ( "Left expression cannot be null" ) ;
629+ }
630+
631+ if ( temp . leftExpr . NodeType == ExpressionType . Constant && true . Equals ( ( ( ConstantExpression ) temp . leftExpr ) . Value ) )
627632 {
628633 return Expression . Equal ( Expression . Constant ( true ) , Expression . Constant ( true ) ) ;
629634 }
630635
631636 // Check if this is a custom operation placeholder
632- if ( temp . leftExpr . NodeType == ExpressionType . Constant &&
633- ( ( ConstantExpression ) temp . leftExpr ) . Value is string constantValue &&
637+ if ( temp . leftExpr . NodeType == ExpressionType . Constant &&
638+ ( ( ConstantExpression ) temp . leftExpr ) . Value is string constantValue &&
634639 constantValue . StartsWith ( "CustomOperation:" ) )
635640 {
636641 var operationName = constantValue . Substring ( "CustomOperation:" . Length ) ;
@@ -801,7 +806,7 @@ private static Parser<Expression> ComparisonExprParser<T>(ParameterExpression pa
801806 if ( IsEnumerable ( member . Type ) )
802807 {
803808 var genericArgType = member . Type . GetGenericArguments ( ) [ 0 ] ;
804- var propertyType = genericArgType . GetProperty ( propName ) . PropertyType ;
809+ var propertyType = genericArgType . GetProperty ( propName ) ! . PropertyType ;
805810
806811 if ( IsEnumerable ( propertyType ) )
807812 {
@@ -814,7 +819,7 @@ private static Parser<Expression> ComparisonExprParser<T>(ParameterExpression pa
814819
815820 var innerParameter = Expression . Parameter ( genericArgType , "y" ) ;
816821 var propertyInfoForMethod = GetPropertyInfo ( genericArgType , propName ) ;
817- Expression lambdaBody = Expression . PropertyOrField ( innerParameter , propertyInfoForMethod . Name ) ;
822+ Expression lambdaBody = Expression . PropertyOrField ( innerParameter , propertyInfoForMethod ! . Name ) ;
818823
819824 // Ensure the lambda body returns IEnumerable<T> for SelectMany
820825 var expectedType = typeof ( IEnumerable < > ) . MakeGenericType ( propertyType ) ;
@@ -834,11 +839,11 @@ private static Parser<Expression> ComparisonExprParser<T>(ParameterExpression pa
834839 {
835840 var selectMethod = typeof ( Enumerable ) . GetMethods ( )
836841 . First ( m => m . Name == "Select" && m . GetParameters ( ) . Length == 2 )
837- . MakeGenericMethod ( genericArgType , genericArgType . GetProperty ( propName ) . PropertyType ) ;
842+ . MakeGenericMethod ( genericArgType , genericArgType . GetProperty ( propName ) ! . PropertyType ) ;
838843
839844 var innerParameter = Expression . Parameter ( genericArgType , "y" ) ;
840845 var propertyInfoForMethod = GetPropertyInfo ( genericArgType , propName ) ;
841- var lambdaBody = Expression . PropertyOrField ( innerParameter , propertyInfoForMethod . Name ) ;
846+ var lambdaBody = Expression . PropertyOrField ( innerParameter , propertyInfoForMethod ! . Name ) ;
842847 var selectLambda = Expression . Lambda ( lambdaBody , innerParameter ) ;
843848 var selectResult = Expression . Call ( null , selectMethod , member , selectLambda ) ;
844849
@@ -850,17 +855,17 @@ private static Parser<Expression> ComparisonExprParser<T>(ParameterExpression pa
850855 if ( expr is MethodCallExpression call )
851856 {
852857 var innerGenericType = GetInnerGenericType ( call . Method . ReturnType ) ;
853- var propertyInfoForMethod = GetPropertyInfo ( innerGenericType , propName ) ;
858+ var propertyInfoForMethod = GetPropertyInfo ( innerGenericType ! , propName ) ;
854859
855- var propertyType = propertyInfoForMethod . PropertyType ;
860+ var propertyType = propertyInfoForMethod ! . PropertyType ;
856861 var linqMethod = IsEnumerable ( propertyType ) ? "SelectMany" : "Select" ;
857862 var resultType = IsEnumerable ( propertyType ) ? propertyType . GetGenericArguments ( ) [ 0 ] : propertyType ;
858-
863+
859864 var selectMethod = typeof ( Enumerable ) . GetMethods ( )
860865 . First ( m => m . Name == linqMethod && m . GetParameters ( ) . Length == 2 )
861- . MakeGenericMethod ( innerGenericType , resultType ) ;
866+ . MakeGenericMethod ( innerGenericType ! , resultType ) ;
862867
863- var innerParameter = Expression . Parameter ( innerGenericType , "y" ) ;
868+ var innerParameter = Expression . Parameter ( innerGenericType ! , "y" ) ;
864869 var lambdaBody = Expression . PropertyOrField ( innerParameter , propertyInfoForMethod . Name ) ;
865870 var selectLambda = Expression . Lambda ( lambdaBody , innerParameter ) ;
866871
@@ -967,7 +972,7 @@ private static Expression CreatePropertyExpressionFromPath<T>(
967972 if ( IsEnumerable ( member . Type ) )
968973 {
969974 var genericArgType = member . Type . GetGenericArguments ( ) [ 0 ] ;
970- var propertyType = genericArgType . GetProperty ( propName ) . PropertyType ;
975+ var propertyType = genericArgType . GetProperty ( propName ) ! . PropertyType ;
971976
972977 if ( IsEnumerable ( propertyType ) )
973978 {
@@ -980,7 +985,7 @@ private static Expression CreatePropertyExpressionFromPath<T>(
980985
981986 var innerParameter = Expression . Parameter ( genericArgType , "y" ) ;
982987 var propertyInfoForMethod = GetPropertyInfo ( genericArgType , propName ) ;
983- Expression lambdaBody = Expression . PropertyOrField ( innerParameter , propertyInfoForMethod . Name ) ;
988+ Expression lambdaBody = Expression . PropertyOrField ( innerParameter , propertyInfoForMethod ! . Name ) ;
984989
985990 var expectedType = typeof ( IEnumerable < > ) . MakeGenericType ( propertyType ) ;
986991 if ( lambdaBody . Type != expectedType && ! expectedType . IsAssignableFrom ( lambdaBody . Type ) )
@@ -997,11 +1002,11 @@ private static Expression CreatePropertyExpressionFromPath<T>(
9971002 {
9981003 var selectMethod = typeof ( Enumerable ) . GetMethods ( )
9991004 . First ( m => m . Name == "Select" && m . GetParameters ( ) . Length == 2 )
1000- . MakeGenericMethod ( genericArgType , genericArgType . GetProperty ( propName ) . PropertyType ) ;
1005+ . MakeGenericMethod ( genericArgType , genericArgType . GetProperty ( propName ) ! . PropertyType ) ;
10011006
10021007 var innerParameter = Expression . Parameter ( genericArgType , "y" ) ;
10031008 var propertyInfoForMethod = GetPropertyInfo ( genericArgType , propName ) ;
1004- var lambdaBody = Expression . PropertyOrField ( innerParameter , propertyInfoForMethod . Name ) ;
1009+ var lambdaBody = Expression . PropertyOrField ( innerParameter , propertyInfoForMethod ! . Name ) ;
10051010 var selectLambda = Expression . Lambda ( lambdaBody , innerParameter ) ;
10061011 var selectResult = Expression . Call ( null , selectMethod , member , selectLambda ) ;
10071012
@@ -1013,17 +1018,17 @@ private static Expression CreatePropertyExpressionFromPath<T>(
10131018 if ( expr is MethodCallExpression call )
10141019 {
10151020 var innerGenericType = GetInnerGenericType ( call . Method . ReturnType ) ;
1016- var propertyInfoForMethod = GetPropertyInfo ( innerGenericType , propName ) ;
1021+ var propertyInfoForMethod = GetPropertyInfo ( innerGenericType ! , propName ) ;
10171022
1018- var propertyType = propertyInfoForMethod . PropertyType ;
1023+ var propertyType = propertyInfoForMethod ! . PropertyType ;
10191024 var linqMethod = IsEnumerable ( propertyType ) ? "SelectMany" : "Select" ;
10201025 var resultType = IsEnumerable ( propertyType ) ? propertyType . GetGenericArguments ( ) [ 0 ] : propertyType ;
10211026
10221027 var selectMethod = typeof ( Enumerable ) . GetMethods ( )
10231028 . First ( m => m . Name == linqMethod && m . GetParameters ( ) . Length == 2 )
1024- . MakeGenericMethod ( innerGenericType , resultType ) ;
1029+ . MakeGenericMethod ( innerGenericType ! , resultType ) ;
10251030
1026- var innerParameter = Expression . Parameter ( innerGenericType , "y" ) ;
1031+ var innerParameter = Expression . Parameter ( innerGenericType ! , "y" ) ;
10271032 var lambdaBody = Expression . PropertyOrField ( innerParameter , propertyInfoForMethod . Name ) ;
10281033 var selectLambda = Expression . Lambda ( lambdaBody , innerParameter ) ;
10291034
@@ -1263,8 +1268,14 @@ private static Expression CreateNestedCollectionFilterExpression<T>(MethodCallEx
12631268
12641269 private class CollectionInfo
12651270 {
1266- public Type CollectionElementType { get ; set ; }
1267- public string PropertyName { get ; set ; }
1271+ public CollectionInfo ( Type collectionElementType , string propertyName )
1272+ {
1273+ CollectionElementType = collectionElementType ;
1274+ PropertyName = propertyName ;
1275+ }
1276+
1277+ public Type CollectionElementType { get ; }
1278+ public string PropertyName { get ; }
12681279 }
12691280
12701281 private static List < CollectionInfo > UnwindSelectManyChain ( MethodCallExpression methodCall )
@@ -1279,11 +1290,7 @@ private static List<CollectionInfo> UnwindSelectManyChain(MethodCallExpression m
12791290 lambda . Body is MemberExpression member )
12801291 {
12811292 var elementType = current . Method . GetGenericArguments ( ) [ 0 ] ;
1282- result . Insert ( 0 , new CollectionInfo
1283- {
1284- CollectionElementType = elementType ,
1285- PropertyName = member . Member . Name
1286- } ) ;
1293+ result . Insert ( 0 , new CollectionInfo ( elementType , member . Member . Name ) ) ;
12871294 }
12881295
12891296 // Move to the next level
@@ -1431,7 +1438,7 @@ private static Expression CreateCustomOperationExpression<T>(ParameterExpression
14311438
14321439 // For custom operations, we need to convert the string value to the appropriate basic type
14331440 // instead of trying to match it to the entity type
1434- object convertedValue = ConvertStringToBasicType ( rightValue ) ;
1441+ object ? convertedValue = ConvertStringToBasicType ( rightValue ) ;
14351442
14361443 // Create the parameter expressions for the custom operation
14371444 var entityParameter = Expression . Convert ( parameter , typeof ( object ) ) ;
@@ -1445,7 +1452,7 @@ private static Expression CreateCustomOperationExpression<T>(ParameterExpression
14451452 return invocationExpression ;
14461453 }
14471454
1448- private static object ConvertStringToBasicType ( string value )
1455+ private static object ? ConvertStringToBasicType ( string value )
14491456 {
14501457 // Handle null
14511458 if ( string . IsNullOrEmpty ( value ) || value . Equals ( "null" , StringComparison . InvariantCultureIgnoreCase ) )
0 commit comments