Skip to content

Commit 770a989

Browse files
committed
fix: map to target from null value should return null
1 parent d26be04 commit 770a989

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

src/Mapster.Tests/Mapster.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
1010
</PropertyGroup>
1111
<ItemGroup>
12+
<PackageReference Include="ExpressionDebugger" Version="2.0.0" />
1213
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
1314
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
1415
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />

src/Mapster.Tests/WhenMappingArrays.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.VisualStudio.TestTools.UnitTesting;
33
using Shouldly;
44
using System.Collections.Generic;
5+
using System.Linq.Expressions;
56

67
namespace Mapster.Tests
78
{
@@ -22,6 +23,16 @@ public void Single_Dimensional_Array_Is_Mapped()
2223
target.Ints.ShouldBe(source.Ints);
2324
}
2425

26+
[TestMethod]
27+
public void MapToTarget_With_Null_Value()
28+
{
29+
var source = new FooArray { Ints = null };
30+
var target = new BarArray { Ints = new int[] { 1, 2, 3, 4, 5 } };
31+
32+
TypeAdapter.Adapt(source, target);
33+
target.Ints.ShouldBeNull();
34+
}
35+
2536
[TestMethod]
2637
public void Multi_Dimensional_Array_Is_Mapped()
2738
{

src/Mapster/Adapters/BaseAdapter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ protected Expression CreateBlockExpressionBody(Expression source, Expression des
185185
var compareNull = Expression.Equal(source, Expression.Constant(null, source.Type));
186186
set = Expression.IfThenElse(
187187
compareNull,
188-
Expression.Assign(result, destination ?? arg.DestinationType.CreateDefault()),
188+
Expression.Assign(result, arg.DestinationType.CreateDefault()),
189189
set);
190190
}
191191
}

src/Mapster/Mapster.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
<PackageLicenseUrl>https://github.com/MapsterMapper/Mapster/blob/master/LICENSE</PackageLicenseUrl>
1717
<NetStandardImplicitPackageVersion Condition=" '$(TargetFramework)' == 'netstandard1.3' ">1.6.1</NetStandardImplicitPackageVersion>
1818
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
19-
<Version>3.3.0</Version>
19+
<Version>3.3.1</Version>
2020
<RootNamespace>Mapster</RootNamespace>
21-
<AssemblyVersion>3.3.0.0</AssemblyVersion>
21+
<AssemblyVersion>3.3.1.0</AssemblyVersion>
2222
</PropertyGroup>
2323
<ItemGroup Condition="'$(TargetFramework)' == 'net40'">
2424
<Reference Include="Microsoft.CSharp" />

0 commit comments

Comments
 (0)