Skip to content

Commit ed33732

Browse files
committed
Cleaner conversions.
1 parent 442eeb5 commit ed33732

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/AutoMapper.Extensions.ExpressionMapping/Extensions/VisitorExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static string GetPropertyFullName(this Expression expression)
6767
}
6868
}
6969

70-
private static Expression GetUnconvertedMemberExpression(this Expression expression)
70+
public static Expression GetUnconvertedMemberExpression(this Expression expression)
7171
{
7272
switch (expression.NodeType)
7373
{

src/AutoMapper.Extensions.ExpressionMapping/MapperExtensions.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using AutoMapper.Internal;
1+
using AutoMapper.Extensions.ExpressionMapping.Extensions;
2+
using AutoMapper.Internal;
23
using System;
34
using System.Collections.Generic;
45
using System.Linq;
@@ -113,9 +114,19 @@ TDestDelegate GetLambda(Dictionary<Type, Type> typeMappings, XpressionMapperVisi
113114
return (TDestDelegate)Lambda
114115
(
115116
typeDestFunc,
116-
shouldConvertMappedBodyToDestType(typeDestFunc) ? ExpressionFactory.ToType(mappedBody, typeDestFunc.GetGenericArguments().Last()) : mappedBody,
117+
ConvertBody(),
117118
expression.GetDestinationParameterExpressions(visitor.InfoDictionary, typeMappings)
118119
);
120+
121+
Expression ConvertBody()
122+
{
123+
if (!shouldConvertMappedBodyToDestType(typeDestFunc))
124+
return mappedBody;
125+
126+
mappedBody = mappedBody.GetUnconvertedMemberExpression();
127+
128+
return ExpressionFactory.ToType(mappedBody, typeDestFunc.GetGenericArguments().Last());
129+
}
119130
}
120131
}
121132

0 commit comments

Comments
 (0)