Skip to content

Commit d613dee

Browse files
authored
Merge pull request #54 from BlaiseD/master
Fix for Issue #53 - InvalidOperationException mapping a string with Plus (+) operator
2 parents f593fa2 + 6462472 commit d613dee

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

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>3.0.5</VersionPrefix>
5+
<VersionPrefix>3.0.6-preview01</VersionPrefix>
66
<WarningsAsErrors>true</WarningsAsErrors>
77
<NoWarn>$(NoWarn);1701;1702;1591</NoWarn>
88
</PropertyGroup>

src/AutoMapper.Extensions.ExpressionMapping/XpressionMapperVisitor.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,15 @@ Expression DoVisitBinary(Expression newLeft, Expression newRight, Expression con
146146
newLeft,
147147
newRight,
148148
node.IsLiftedToNull,
149-
Expression.MakeBinary(node.NodeType, newLeft, newRight).Method
149+
TypesChanged()
150+
? Expression.MakeBinary(node.NodeType, newLeft, newRight).Method
151+
: node.Method
150152
);
151153
}
152154

153155
return node;
156+
157+
bool TypesChanged() => newLeft.Type != node.Left.Type || newRight.Type != node.Right.Type;
154158
}
155159
}
156160

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,20 @@ public void Map_object_type_change_again()
176176
Assert.True(users.Count == 0);
177177
}
178178

179+
[Fact]
180+
public void Uses_the_correct_Add_expression_when_mapping_string_plus_operator()
181+
{
182+
//Arrange
183+
Expression<Func<UserModel, bool>> selection = s => s.FullName + "FFF" == "";
184+
185+
//Act
186+
Expression<Func<User, bool>> selectionMapped = mapper.MapExpression<Expression<Func<User, bool>>>(selection);
187+
List<User> users = Users.Where(selectionMapped).ToList();
188+
189+
//Assert
190+
Assert.True(users.Count == 0);
191+
}
192+
179193
[Fact]
180194
public void Map__object_including_child_and_grandchild()
181195
{

0 commit comments

Comments
 (0)