@@ -102,7 +102,7 @@ Expression GetMappedMemberExpression(Expression parentExpression, List<PropertyM
102102 }
103103 }
104104
105- protected MemberExpression GetMemberExpressionFromMemberMaps ( string fullName , Expression visitedParentExpr )
105+ protected MemberExpression GetMemberExpressionFromMemberMaps ( string fullName , Expression visitedParentExpr )
106106 => ExpressionHelpers . MemberAccesses ( fullName , visitedParentExpr ) ;
107107
108108 private Expression GetMemberExpressionFromCustomExpression ( PropertyMapInfo lastWithCustExpression ,
@@ -130,7 +130,7 @@ Expression PrependParentMemberExpression(PrependParentNameVisitor visitor)
130130 ) ;
131131 }
132132
133- protected Expression GetMemberExpressionFromCustomExpression ( List < PropertyMapInfo > propertyMapInfoList , PropertyMapInfo lastWithCustExpression , Expression mappedParentExpr )
133+ protected Expression GetMemberExpressionFromCustomExpression ( List < PropertyMapInfo > propertyMapInfoList , PropertyMapInfo lastWithCustExpression , Expression mappedParentExpr )
134134 => GetMemberExpressionFromCustomExpression
135135 (
136136 lastWithCustExpression ,
@@ -306,7 +306,9 @@ Expression DoVisitUnary(Expression updated)
306306 protected override Expression VisitConstant ( ConstantExpression node )
307307 {
308308 if ( this . TypeMappings . TryGetValue ( node . Type , out Type newType )
309- && ConfigurationProvider . ResolveTypeMap ( node . Type , newType ) != null )
309+ && ConfigurationProvider . ResolveTypeMap ( newType , node . Type ) != null )
310+ //The destination becomes the source because to map a source expression to a destination expression,
311+ //we need the expressions used to create the source from the destination
310312 return base . VisitConstant ( Expression . Constant ( Mapper . MapObject ( node . Value , node . Type , newType ) , newType ) ) ;
311313 //Issue 3455 (Non-Generic Mapper.Map failing for structs in v10)
312314 //return base.VisitConstant(Expression.Constant(Mapper.Map(node.Value, node.Type, newType), newType));
@@ -410,13 +412,13 @@ private static void AddPropertyMapInfo(Type parentType, string name, List<Proper
410412 }
411413 }
412414
413- private bool GenericTypeDefinitionsAreEquivalent ( Type typeSource , Type typeDestination )
415+ private bool GenericTypeDefinitionsAreEquivalent ( Type typeSource , Type typeDestination )
414416 => typeSource . IsGenericType ( ) && typeDestination . IsGenericType ( ) && typeSource . GetGenericTypeDefinition ( ) == typeDestination . GetGenericTypeDefinition ( ) ;
415417
416418 protected void FindDestinationFullName ( Type typeSource , Type typeDestination , string sourceFullName , List < PropertyMapInfo > propertyMapInfoList )
417419 {
418420 const string period = "." ;
419-
421+
420422 if ( typeSource == typeDestination )
421423 {
422424 var sourceFullNameArray = sourceFullName . Split ( new [ ] { period [ 0 ] } , StringSplitOptions . RemoveEmptyEntries ) ;
@@ -459,7 +461,7 @@ protected void FindDestinationFullName(Type typeSource, Type typeDestination, st
459461
460462 var sourceType = typeSource . GetFieldOrProperty ( propertyName ) . GetMemberType ( ) ;
461463 var destType = typeDestination . GetFieldOrProperty ( propertyName ) . GetMemberType ( ) ;
462-
464+
463465 TypeMappings . AddTypeMapping ( ConfigurationProvider , sourceType , destType ) ;
464466
465467 var childFullName = sourceFullName . Substring ( sourceFullName . IndexOf ( period , StringComparison . OrdinalIgnoreCase ) + 1 ) ;
0 commit comments