Skip to content

Commit 4ed697f

Browse files
committed
Removing dictionary entries from index access checks
1 parent c6192d2 commit 4ed697f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

AgileMapper.UnitTests/WhenFlatteningToDictionaries.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using System;
44
using System.Collections.Generic;
5+
using System.Linq;
56
using TestClasses;
67
using Xunit;
78

@@ -48,14 +49,24 @@ public void ShouldFlattenAComplexTypeMember()
4849
}
4950

5051
[Fact]
51-
public void ShouldFlattenANullableComplexTypeMember()
52+
public void ShouldFlattenANullNullableDateTimeOffsetMember()
5253
{
5354
var source = new PublicProperty<DateTimeOffset?> { Value = null };
5455
var result = Mapper.Flatten(source).ToDictionary<string>();
5556

5657
result.ShouldNotContainKey("Value");
5758
}
5859

60+
[Fact]
61+
public void ShouldFlattenANullNullableIntToAStringDictionary()
62+
{
63+
var source = new PublicTwoFields<int?, int?> { Value1 = 123, Value2 = null };
64+
var result = Mapper.Flatten(source).ToDictionary<string>();
65+
66+
result["Value1"].ShouldBe("123");
67+
result.ShouldNotContainKey("Value2");
68+
}
69+
5970
[Fact]
6071
public void ShouldHandleANullComplexTypeMember()
6172
{

AgileMapper/Members/ExpressionInfoFinder.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ private static bool IsNullableHasValueAccess(MemberExpression memberAccess)
212212
protected override Expression VisitIndex(IndexExpression indexAccess)
213213
{
214214
if ((indexAccess.Object.Type != typeof(string)) &&
215+
!indexAccess.Object.Type.IsDictionary() &&
215216
IndexDoesNotUseParameter(indexAccess.Arguments[0]))
216217
{
217218
AddMemberAccess(indexAccess);

0 commit comments

Comments
 (0)