Skip to content

Commit 91b51cb

Browse files
committed
More minor.
1 parent 9ecc25f commit 91b51cb

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/AutoMapper.Extensions.ExpressionMapping/XpressionMapperVisitor.cs

+8-6
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ private MemberInitExpression GetAnonymousTypeMemberInitExpression(Dictionary<str
273273
(
274274
Expression.New(newAnonymousType),
275275
bindingExpressions
276-
.ToDictionary(be => be.Key, be => newAnonymousType.GetMember(be.Key)[0])
276+
.ToDictionary(be => be.Key, be => newAnonymousType.GetProperty(be.Key))
277277
.Select(member => Expression.Bind(member.Value, bindingExpressions[member.Key]))
278278
);
279279
}
@@ -620,6 +620,12 @@ protected void FindDestinationFullName(Type typeSource, Type typeDestination, st
620620
bool BothTypesAreAnonymous()
621621
=> IsAnonymousType(typeSource) && IsAnonymousType(typeDestination);
622622

623+
TypeMap GetTypeMap() => BothTypesAreAnonymous()
624+
? anonymousTypesConfigurationProvider.CheckIfTypeMapExists(sourceType: typeDestination, destinationType: typeSource)
625+
: ConfigurationProvider.CheckIfTypeMapExists(sourceType: typeDestination, destinationType: typeSource);
626+
//The destination becomes the source because to map a source expression to a destination expression,
627+
//we need the expressions used to create the source from the destination
628+
623629
if (typeSource == typeDestination)
624630
{
625631
var sourceFullNameArray = sourceFullName.Split(new[] { period[0] }, StringSplitOptions.RemoveEmptyEntries);
@@ -671,11 +677,7 @@ bool BothTypesAreAnonymous()
671677
}
672678
}
673679

674-
var typeMap = BothTypesAreAnonymous()
675-
? anonymousTypesConfigurationProvider.CheckIfTypeMapExists(sourceType: typeDestination, destinationType: typeSource)
676-
: ConfigurationProvider.CheckIfTypeMapExists(sourceType: typeDestination, destinationType: typeSource);
677-
//The destination becomes the source because to map a source expression to a destination expression,
678-
//we need the expressions used to create the source from the destination
680+
var typeMap = GetTypeMap();
679681

680682
PathMap pathMap = typeMap.FindPathMapByDestinationPath(destinationFullPath: sourceFullName);
681683
if (pathMap != null)

0 commit comments

Comments
 (0)