Skip to content

Commit d43137b

Browse files
authored
Merge pull request #2641 from lbargaoanu/nullable_untyped_mapfrom
Nullable untyped MapFrom
2 parents 58b6db5 + ebf0214 commit d43137b

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/AutoMapper/Mappers/NullableDestinationMapper.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ public Expression MapExpression(IConfigurationProvider configurationProvider, Pr
1616
new TypePair(sourceExpression.Type, Nullable.GetUnderlyingType(destExpression.Type)),
1717
sourceExpression,
1818
contextExpression,
19-
propertyMap,
20-
Expression.Property(destExpression, destExpression.Type.GetDeclaredProperty("Value"))
19+
propertyMap
2120
);
2221

2322
public TypePair GetAssociatedTypes(TypePair initialTypes)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Xunit;
2+
using Shouldly;
3+
4+
namespace AutoMapper.UnitTests.Bug
5+
{
6+
public class NullableUntypedMapFrom : AutoMapperSpecBase
7+
{
8+
private Destination _destination;
9+
10+
class Source
11+
{
12+
public decimal? Number { get; set; }
13+
}
14+
class Destination
15+
{
16+
public decimal? OddNumber { get; set; }
17+
}
18+
19+
protected override MapperConfiguration Configuration { get; } = new MapperConfiguration(cfg =>
20+
{
21+
cfg.CreateMap<Source, Destination>().ForMember(d => d.OddNumber, o => o.MapFrom(s => (object)s.Number));
22+
});
23+
24+
protected override void Because_of()
25+
{
26+
_destination = Mapper.Map<Destination>(new Source { Number = 12 });
27+
}
28+
29+
[Fact]
30+
public void Should_map_nullable_decimal()
31+
{
32+
_destination.OddNumber.ShouldBe(12);
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)