Skip to content

Commit 9388b2f

Browse files
authored
Merge pull request #94 from Erythnul/issue93
Resolve Issue 93
2 parents af69b1e + b4c7748 commit 9388b2f

File tree

5 files changed

+33
-8
lines changed

5 files changed

+33
-8
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
- name: Set Variables
1818
run: |
19-
echo '::set-env name=VERSION_NUMBER::4.0.2-preview-1'
19+
echo '::set-env name=VERSION_NUMBER::4.0.2-preview-2'
2020
echo '::set-env name=DEPLOY_PACKAGE_URL::https://www.myget.org/F/automapperdev/api/v3/index.json'
2121
echo '::set-env name=DEPLOY_PACKAGE_API_KEY::${{ secrets.MYGET_CI_API_KEY }}'
2222
echo '::set-env name=REPO::${{ github.repository }}'

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
- name: Set Variables
1616
run: |
17-
echo '::set-env name=VERSION_NUMBER::4.0.2-preview-1'
17+
echo '::set-env name=VERSION_NUMBER::4.0.2-preview-2'
1818
echo '::set-env name=DEPLOY_PACKAGE_URL::https://api.nuget.org/v3/index.json'
1919
echo '::set-env name=DEPLOY_PACKAGE_API_KEY::${{ secrets.NUGET_API_KEY }}'
2020
echo '::set-env name=REPO::${{ github.repository }}'

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<Authors>Jimmy Bogard</Authors>
44
<LangVersion>latest</LangVersion>
5-
<VersionPrefix>4.0.2-preview-1</VersionPrefix>
5+
<VersionPrefix>4.0.2-preview-2</VersionPrefix>
66
<WarningsAsErrors>true</WarningsAsErrors>
77
<NoWarn>$(NoWarn);1701;1702;1591</NoWarn>
88
</PropertyGroup>

src/AutoMapper.Extensions.ExpressionMapping/XpressionMapperVisitor.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,16 @@ Expression DoVisitUnary(Expression updated)
305305

306306
protected override Expression VisitConstant(ConstantExpression node)
307307
{
308-
if (this.TypeMappings.TryGetValue(node.Type, out Type newType)
309-
&& ConfigurationProvider.ResolveTypeMap(node.Type, newType) != null)
310-
return base.VisitConstant(Expression.Constant(Mapper.MapObject(node.Value, node.Type, newType), newType));
311-
//Issue 3455 (Non-Generic Mapper.Map failing for structs in v10)
312-
//return base.VisitConstant(Expression.Constant(Mapper.Map(node.Value, node.Type, newType), newType));
308+
if (this.TypeMappings.TryGetValue(node.Type, out Type newType))
309+
{
310+
if (node.Value == null)
311+
return base.VisitConstant(Expression.Constant(null, newType));
313312

313+
if (ConfigurationProvider.ResolveTypeMap(node.Type, newType) != null)
314+
return base.VisitConstant(Expression.Constant(Mapper.MapObject(node.Value, node.Type, newType), newType));
315+
//Issue 3455 (Non-Generic Mapper.Map failing for structs in v10)
316+
//return base.VisitConstant(Expression.Constant(Mapper.Map(node.Value, node.Type, newType), newType));
317+
}
314318
return base.VisitConstant(node);
315319
}
316320

tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/ShouldOnlyMapExistingTypeMaps.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,27 @@ public void Issue85()
3434
Assert.NotNull(mapped2);
3535
}
3636

37+
[Fact]
38+
public void Issue93()
39+
{
40+
var config = new MapperConfiguration(cfg =>
41+
{
42+
cfg.AddExpressionMapping();
43+
44+
cfg.CreateMap<Source, SourceDto>()
45+
.ForMember(o => o.Items, config => config.MapFrom(p => p.Items.Select(s => s.Name)));
46+
});
47+
48+
var mapper = config.CreateMapper();
49+
50+
Expression<Func<SourceDto, bool>> expression1 =
51+
src => ((src != null ? src : null) != null) && src.Items.Any(x => x == "item1");
52+
53+
var mapped1 = mapper.MapExpression<Expression<Func<Source, bool>>>(expression1);
54+
55+
Assert.NotNull(mapped1);
56+
}
57+
3758
public class Source { public ICollection<SubSource> Items { get; set; } }
3859

3960
public class SubSource { public int ID { get; set; } public string Name { get; set; } }

0 commit comments

Comments
 (0)