Skip to content

Commit 85fcd02

Browse files
committed
Merge branch 'develop'
2 parents f0b7fe2 + 14fec95 commit 85fcd02

File tree

9 files changed

+71
-13
lines changed

9 files changed

+71
-13
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ TestResult.xml
1414
AppPackages/
1515
*.bak
1616
packages
17-
*.orig
17+
*.orig
18+
*.DotSettings

src/AutoMapper/AutoMapper.WinRT.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
<PropertyGroup>
132132
<AssemblyOriginatorKeyFile>..\AutoMapper.snk</AssemblyOriginatorKeyFile>
133133
</PropertyGroup>
134-
<Import Project="..\..\tools\MSBuild\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
134+
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
135135
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
136136
Other similar extension points exist, see Microsoft.Common.targets.
137137
<Target Name="BeforeBuild">

src/AutoMapper/AutoMapper.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
<Compile Include="Internal\PlatformAdapter.cs" />
7777
<Compile Include="Internal\ProbingAdapterResolver.cs" />
7878
<Compile Include="Mapper.cs" />
79+
<Compile Include="Mappers\AssignableArrayMapper.cs" />
7980
<Compile Include="Mappers\ExplicitConversionOperatorMapper.cs" />
8081
<Compile Include="Mappers\ImplicitConversionOperatorMapper.cs" />
8182
<Compile Include="Mappers\IPlatformSpecificMapperRegistry.cs" />
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace AutoMapper.Mappers
2+
{
3+
public class AssignableArrayMapper : IObjectMapper
4+
{
5+
public object Map(ResolutionContext context, IMappingEngineRunner mapper)
6+
{
7+
if (context.SourceValue == null && !mapper.ShouldMapSourceValueAsNull(context))
8+
{
9+
return mapper.CreateObject(context);
10+
}
11+
12+
return context.SourceValue;
13+
}
14+
15+
public bool IsMatch(ResolutionContext context)
16+
{
17+
return context.DestinationType.IsAssignableFrom(context.SourceType)
18+
&& context.DestinationType.IsArray
19+
&& context.SourceType.IsArray;
20+
}
21+
}
22+
}

src/AutoMapper/Mappers/AssignableMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace AutoMapper.Mappers
22
{
3-
public class AssignableMapper : IObjectMapper
3+
public class AssignableMapper : IObjectMapper
44
{
55
public object Map(ResolutionContext context, IMappingEngineRunner mapper)
66
{

src/AutoMapper/Mappers/MapperRegistry.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public static class MapperRegistry
88
{
99
new TypeMapMapper(TypeMapObjectMapperRegistry.Mappers),
1010
new StringMapper(),
11-
new AssignableMapper(),
11+
new AssignableArrayMapper(),
1212
new FlagsEnumMapper(),
1313
new EnumMapper(),
1414
new PrimitiveArrayMapper(),
@@ -18,6 +18,7 @@ public static class MapperRegistry
1818
new ReadOnlyCollectionMapper(),
1919
new CollectionMapper(),
2020
new EnumerableMapper(),
21+
new AssignableMapper(),
2122
new NullableSourceMapper(),
2223
new NullableMapper(),
2324
new ImplicitConversionOperatorMapper(),

src/Install.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ param($installPath, $toolsPath, $package, $project)
1111

1212
if ($platformSpecificRef)
1313
{
14-
$refPath = $platformSpecificRef.Metadata.Where({ $_.Name -eq "HintPath" }).Value
14+
$refPath = ($platformSpecificRef.Metadata | Where-Object { $_.Name -eq "HintPath" } | Select-Object -First 1).Value
1515

1616
$item = $msbuild.Xml.AddItem("Content", $refPath)
1717
$item.AddMetadata("Link", [System.IO.Path]::GetFileName($refPath))

src/UnitTests/Bug/AssignableCollectionBug.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ protected override void Establish_context()
109109

110110
protected override void Because_of()
111111
{
112-
_source = new Picture {ImageData = new byte[1000000]};
112+
_source = new Picture {ImageData = new byte[100]};
113113
_dest = Mapper.Map<Picture, PictureDto>(_source);
114114
}
115115

@@ -120,4 +120,37 @@ public void Should_copy_array()
120120
}
121121
}
122122
}
123+
124+
namespace AssignableLists
125+
{
126+
public class AutoMapperTests
127+
{
128+
[Fact]
129+
public void ListShouldNotMapAsReference()
130+
{
131+
// arrange
132+
Mapper.Reset();
133+
Mapper.CreateMap<A, B>();
134+
var source = new A { Images = new List<string>() };
135+
136+
// act
137+
var destination = Mapper.Map<B>(source);
138+
destination.Images.Add("test");
139+
140+
// assert
141+
destination.Images.Count.ShouldEqual(1);
142+
source.Images.Count.ShouldEqual(0); // in 3.1.0 source.Images.Count is 1
143+
}
144+
}
145+
146+
public class A
147+
{
148+
public IList<string> Images { get; set; }
149+
}
150+
151+
public class B
152+
{
153+
public IList<string> Images { get; set; }
154+
}
155+
}
123156
}

src/UnitTests/UnitTests.WinRT.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,15 +296,15 @@
296296
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '11.0' ">
297297
<VisualStudioVersion>11.0</VisualStudioVersion>
298298
</PropertyGroup>
299-
<Import Project="..\..\tools\MSBuild\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
299+
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
300300
<PropertyGroup>
301301
<SDKReferenceDirectoryRoot>$(ProjectDir)\libs;$(SDKReferenceDirectoryRoot)</SDKReferenceDirectoryRoot>
302302
</PropertyGroup>
303-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
304-
Other similar extension points exist, see Microsoft.Common.targets.
305-
<Target Name="BeforeBuild">
306-
</Target>
307-
<Target Name="AfterBuild">
308-
</Target>
303+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
304+
Other similar extension points exist, see Microsoft.Common.targets.
305+
<Target Name="BeforeBuild">
306+
</Target>
307+
<Target Name="AfterBuild">
308+
</Target>
309309
-->
310310
</Project>

0 commit comments

Comments
 (0)