diff --git a/src/AutoMapper/Mappers/NullableDestinationMapper.cs b/src/AutoMapper/Mappers/NullableDestinationMapper.cs index 63e504d424..bb487cd18b 100644 --- a/src/AutoMapper/Mappers/NullableDestinationMapper.cs +++ b/src/AutoMapper/Mappers/NullableDestinationMapper.cs @@ -16,8 +16,7 @@ public Expression MapExpression(IConfigurationProvider configurationProvider, Pr new TypePair(sourceExpression.Type, Nullable.GetUnderlyingType(destExpression.Type)), sourceExpression, contextExpression, - propertyMap, - Expression.Property(destExpression, destExpression.Type.GetDeclaredProperty("Value")) + propertyMap ); public TypePair GetAssociatedTypes(TypePair initialTypes) diff --git a/src/UnitTests/Bug/NullableUntypedMapFrom.cs b/src/UnitTests/Bug/NullableUntypedMapFrom.cs new file mode 100644 index 0000000000..635f10a3ee --- /dev/null +++ b/src/UnitTests/Bug/NullableUntypedMapFrom.cs @@ -0,0 +1,35 @@ +using Xunit; +using Shouldly; + +namespace AutoMapper.UnitTests.Bug +{ + public class NullableUntypedMapFrom : AutoMapperSpecBase + { + private Destination _destination; + + class Source + { + public decimal? Number { get; set; } + } + class Destination + { + public decimal? OddNumber { get; set; } + } + + protected override MapperConfiguration Configuration { get; } = new MapperConfiguration(cfg => + { + cfg.CreateMap().ForMember(d => d.OddNumber, o => o.MapFrom(s => (object)s.Number)); + }); + + protected override void Because_of() + { + _destination = Mapper.Map(new Source { Number = 12 }); + } + + [Fact] + public void Should_map_nullable_decimal() + { + _destination.OddNumber.ShouldBe(12); + } + } +} \ No newline at end of file