@@ -31,7 +31,7 @@ public static class ExpressionBuilder
3131 public static readonly MethodInfo OverTypeDepthMethod = typeof ( ResolutionContext ) . GetInstanceMethod ( nameof ( ResolutionContext . OverTypeDepth ) ) ;
3232 public static readonly MethodInfo CacheDestinationMethod = typeof ( ResolutionContext ) . GetInstanceMethod ( nameof ( ResolutionContext . CacheDestination ) ) ;
3333 public static readonly MethodInfo GetDestinationMethod = typeof ( ResolutionContext ) . GetInstanceMethod ( nameof ( ResolutionContext . GetDestination ) ) ;
34- private static readonly MethodCallExpression CheckContextCall = Expression . Call (
34+ public static readonly MethodCallExpression CheckContextCall = Expression . Call (
3535 typeof ( ResolutionContext ) . GetStaticMethod ( nameof ( ResolutionContext . CheckContext ) ) , ContextParameter ) ;
3636 private static readonly MethodInfo ContextMapMethod = typeof ( ResolutionContext ) . GetInstanceMethod ( nameof ( ResolutionContext . MapInternal ) ) ;
3737 private static readonly MethodInfo ArrayEmptyMethod = typeof ( Array ) . GetStaticMethod ( nameof ( Array . Empty ) ) ;
@@ -81,9 +81,7 @@ public static Expression NullCheckSource(ProfileMap profileMap, Expression sourc
8181 var destinationType = destinationParameter . Type ;
8282 var isCollection = destinationType . IsCollection ( ) ;
8383 var mustUseDestination = memberMap is { MustUseDestination : true } ;
84- var ifSourceNull = memberMap == null ?
85- destinationParameter . IfNullElse ( DefaultDestination ( ) , ClearDestinationCollection ( ) ) :
86- mustUseDestination ? ClearDestinationCollection ( ) : DefaultDestination ( ) ;
84+ var ifSourceNull = mustUseDestination ? ClearDestinationCollection ( ) : DefaultDestination ( ) ;
8785 return sourceParameter . IfNullElse ( ifSourceNull , mapExpression ) ;
8886 Expression ClearDestinationCollection ( )
8987 {
@@ -109,13 +107,13 @@ Expression ClearDestinationCollection()
109107 }
110108 var destinationElementType = GetEnumerableElementType ( destinationType ) ;
111109 destinationCollectionType = typeof ( ICollection < > ) . MakeGenericType ( destinationElementType ) ;
112- collection = Convert ( collection , destinationCollectionType ) ;
110+ collection = TypeAs ( collection , destinationCollectionType ) ;
113111 }
114112 clearMethod = destinationCollectionType . GetMethod ( "Clear" ) ;
115113 }
116114 return Block ( new [ ] { destinationVariable } ,
117115 Assign ( destinationVariable , destinationParameter ) ,
118- Condition ( ReferenceEqual ( destinationVariable , Null ) , Empty , Expression . Call ( collection , clearMethod ) ) ,
116+ Condition ( ReferenceEqual ( collection , Null ) , Empty , Expression . Call ( collection , clearMethod ) ) ,
119117 destinationVariable ) ;
120118 }
121119 Expression DefaultDestination ( )
@@ -141,14 +139,6 @@ public static Expression ContextMap(TypePair typePair, Expression sourceParamete
141139 var mapMethod = ContextMapMethod . MakeGenericMethod ( typePair . SourceType , typePair . DestinationType ) ;
142140 return Expression . Call ( ContextParameter , mapMethod , sourceParameter , destinationParameter , Constant ( memberMap , typeof ( MemberMap ) ) ) ;
143141 }
144- public static Expression CheckContext ( TypeMap typeMap )
145- {
146- if ( typeMap . MaxDepth > 0 || typeMap . PreserveReferences )
147- {
148- return CheckContextCall ;
149- }
150- return null ;
151- }
152142 public static Expression OverMaxDepth ( TypeMap typeMap ) => typeMap ? . MaxDepth > 0 ? Expression . Call ( ContextParameter , OverTypeDepthMethod , Constant ( typeMap ) ) : null ;
153143 public static Expression NullSubstitute ( this MemberMap memberMap , Expression sourceExpression ) =>
154144 Coalesce ( sourceExpression , ToType ( Constant ( memberMap . NullSubstitute ) , sourceExpression . Type ) ) ;
0 commit comments