1313
1414using JetBrains . Annotations ;
1515
16- using SuppressMessageAttribute = System . Diagnostics . CodeAnalysis . SuppressMessageAttribute ;
17-
1816namespace CodeJam . Mapping
1917{
2018 using Reflection ;
@@ -505,7 +503,7 @@ from a in dic
505503 }
506504
507505 private static ValueTuple < Expression , bool > ? GetConverter (
508- [ AllowNull ] MappingSchema ? mappingSchema ,
506+ MappingSchema mappingSchema ,
509507 Expression expr ,
510508 Type from ,
511509 Type to )
@@ -518,33 +516,33 @@ from a in dic
518516 if ( le != null )
519517 return ValueTuple . Create ( le . ReplaceParameters ( expr ) , false ) ;
520518
521- var lex = mappingSchema ! . TryGetConvertExpression ( from , to ) ;
519+ var lex = mappingSchema . TryGetConvertExpression ( from , to ) ;
522520
523521 if ( lex != null )
524522 return ValueTuple . Create ( lex . ReplaceParameters ( expr ) , true ) ;
525523
526524 var ex =
527525 GetFromEnum ( from , to , expr , mappingSchema ) ??
528- GetToEnum ( from , to , expr , mappingSchema ) ;
526+ GetToEnum ( from , to , expr , mappingSchema ) ;
529527
530528 if ( ex != null )
531529 return ValueTuple . Create ( ex , true ) ;
532530
533531 ex =
534532 GetConversion ( from , to , expr ) ??
535- GetCtor ( from , to , expr ) ??
536- GetValue ( from , to , expr ) ??
537- GetOperator ( from , to , expr ) ??
538- GetParse ( from , to , expr ) ??
539- GetToString ( from , to , expr ) ??
540- GetParseEnum ( from , to , expr ) ;
541-
542- return ex != null ? ValueTuple . Create ( ex , false ) : ( ValueTuple < Expression , bool > ? ) null ;
533+ GetCtor ( from , to , expr ) ??
534+ GetValue ( from , to , expr ) ??
535+ GetOperator ( from , to , expr ) ??
536+ GetParse ( from , to , expr ) ??
537+ GetToString ( from , to , expr ) ??
538+ GetParseEnum ( from , to , expr ) ;
539+
540+ return ex != null ? ValueTuple . Create ( ex , false ) : null ;
543541 }
544542
545543 [ return : MaybeNull ]
546544 private static ValueTuple < Expression , bool > ? ConvertUnderlying (
547- [ AllowNull ] MappingSchema mappingSchema ,
545+ MappingSchema mappingSchema ,
548546 Expression expr ,
549547 Type from ,
550548 Type ufrom ,
@@ -597,8 +595,8 @@ from a in dic
597595
598596 var ex =
599597 GetConverter ( mappingSchema , p , from , to ) ??
600- ConvertUnderlying ( mappingSchema , p , from , from . ToNullableUnderlying ( ) , to , to . ToNullableUnderlying ( ) ) ??
601- ConvertUnderlying ( mappingSchema , p , from , from . ToUnderlying ( ) , to , to . ToUnderlying ( ) ) ;
598+ ConvertUnderlying ( mappingSchema , p , from , from . ToNullableUnderlying ( ) , to , to . ToNullableUnderlying ( ) ) ??
599+ ConvertUnderlying ( mappingSchema , p , from , from . ToUnderlying ( ) , to , to . ToUnderlying ( ) ) ;
602600
603601 if ( ex != null )
604602 {
@@ -613,9 +611,7 @@ from a in dic
613611 ex . Value . Item2 ) ;
614612 else if ( from . GetIsClass ( ) )
615613 ex = ValueTuple . Create (
616- Expression . Condition (
617- Expression . NotEqual ( p , Expression . Constant ( null , from ) ) , ex . Value . Item1 ,
618- new DefaultValueExpression ( mappingSchema , to ) ) as Expression ,
614+ Expression . Condition ( Expression . NotEqual ( p , Expression . Constant ( null , from ) ) , ex . Value . Item1 , new DefaultValueExpression ( mappingSchema , to ) ) as Expression ,
619615 ex . Value . Item2 ) ;
620616 }
621617
@@ -626,8 +622,7 @@ from a in dic
626622 {
627623 var uto = to . ToNullableUnderlying ( ) ;
628624
629- var defex = Expression . Call (
630- _defaultConverter ,
625+ var defex = Expression . Call ( _defaultConverter ,
631626 Expression . Convert ( p , typeof ( object ) ) ,
632627 Expression . Constant ( uto ) ) as Expression ;
633628
@@ -636,12 +631,11 @@ from a in dic
636631
637632 defex = GetCtor ( uto , to , defex ) ;
638633
639- return ValueTuple . Create ( Expression . Lambda ( defex ! , p ) , nullLambda , false ) ;
634+ return ValueTuple . Create ( Expression . Lambda ( defex ?? p , p ) , nullLambda , false ) ;
640635 }
641636 else
642637 {
643- var defex = Expression . Call (
644- _defaultConverter ,
638+ var defex = Expression . Call ( _defaultConverter ,
645639 Expression . Convert ( p , typeof ( object ) ) ,
646640 Expression . Constant ( to ) ) as Expression ;
647641
0 commit comments