Skip to content

Commit

Permalink
Reproducing issue AutoMapper#257
Browse files Browse the repository at this point in the history
Updating the project

Using nullable types in type check, closes AutoMapper#257
  • Loading branch information
jbogard committed Sep 30, 2012
1 parent 38b8601 commit 755fe92
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/AutoMapper/MappingEngine.cs
Expand Up @@ -416,7 +416,7 @@ object IMappingEngineRunner.CreateObject(ResolutionContext context)

bool IMappingEngineRunner.ShouldMapSourceValueAsNull(ResolutionContext context)
{
if (context.DestinationType.IsValueType)
if (context.DestinationType.IsValueType && !context.DestinationType.IsNullableType())
return false;

var typeMap = context.GetContextTypeMap();
Expand Down
22 changes: 22 additions & 0 deletions src/UnitTests/Bug/NullablePropertiesBug.cs
@@ -0,0 +1,22 @@
using NUnit.Framework;
using Should;

namespace AutoMapper.UnitTests.Bug
{
[TestFixture]
public class NullablePropertiesBug
{
public class Source { public int? A { get; set; } }
public class Target { public int? A { get; set; } }

[Test]
public void Example()
{
Mapper.CreateMap<Source, Target>();

var d = Mapper.Map(new Source { A = null }, new Target { A = 10 });

d.A.ShouldBeNull();
}
}
}
1 change: 1 addition & 0 deletions src/UnitTests/UnitTests.csproj
Expand Up @@ -127,6 +127,7 @@
<Compile Include="Bug\NamingConventions.cs" />
<Compile Include="Bug\NullableBytesAndEnums.cs" />
<Compile Include="Bug\NullableConverterBug.cs" />
<Compile Include="Bug\NullablePropertiesBug.cs" />
<Compile Include="Bug\ObjectTypeMapFailure.cs" />
<Compile Include="Bug\RecognizeIxesBug.cs" />
<Compile Include="Bug\RepeatedMappingConfigurationTest.cs" />
Expand Down

0 comments on commit 755fe92

Please sign in to comment.