Skip to content

Commit 22dacd6

Browse files
committed
cast the type map expression to the property type
1 parent 64b79b1 commit 22dacd6

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/AutoMapper/Execution/ExpressionBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static Expression MapExpression(this IGlobalConfiguration configuration,
7676
typeMap.Seal(configuration);
7777
if (typeMap.MapExpression != null)
7878
{
79-
mapExpression = typeMap.Invoke(source, destination);
79+
mapExpression = ToType(typeMap.Invoke(source, destination), typePair.DestinationType);
8080
}
8181
}
8282
}

src/UnitTests/TypeConverters.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
namespace AutoMapper.UnitTests.CustomMapping;
2-
2+
public class StringToEnumConverter : AutoMapperSpecBase
3+
{
4+
class Source
5+
{
6+
public string Enum { get; set; }
7+
}
8+
class Destination
9+
{
10+
public ConsoleColor Enum { get; set; }
11+
}
12+
protected override MapperConfiguration CreateConfiguration() => new(c =>
13+
{
14+
c.CreateMap<string, Enum>().ConvertUsing(s => ConsoleColor.DarkCyan);
15+
c.CreateMap<Source, Destination>();
16+
});
17+
[Fact]
18+
public void Should_work()
19+
{
20+
Map<ConsoleColor>("").ShouldBe(ConsoleColor.DarkCyan);
21+
Map<Destination>(new Source()).Enum.ShouldBe(ConsoleColor.DarkCyan);
22+
}
23+
}
324
public class NullableConverter : AutoMapperSpecBase
425
{
526
public enum GreekLetters

0 commit comments

Comments
 (0)