Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Changed isNullConstant func to local method
  • Loading branch information
gentledepp committed Jan 30, 2018
commit cf9af9c64edef5b76d15976bf9c6cae1ecdc91a7
9 changes: 6 additions & 3 deletions src/AutoMapper/Mappers/ExpressionMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,14 @@ protected override Expression VisitBinary(BinaryExpression node)

// check if the non-string expression is a null constent
// as this would lead to a "null.ToString()" and thus an error when executing the expression
var isNullConstant = new Func<Expression, bool>(xpr => xpr is ConstantExpression c && c.Value == null);
bool IsNullConstant(Expression xpr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it looks much better after the function body, like in the docs. Easier on the eyes :)

{
return xpr is ConstantExpression c && c.Value == null;
}

if (newLeft.Type != newRight.Type && newRight.Type == typeof(string) && !isNullConstant(newLeft))
if (newLeft.Type != newRight.Type && newRight.Type == typeof(string) && !IsNullConstant(newLeft))
newLeft = Call(newLeft, typeof(object).GetDeclaredMethod("ToString"));
if (newRight.Type != newLeft.Type && newLeft.Type == typeof(string) && !isNullConstant(newRight))
if (newRight.Type != newLeft.Type && newLeft.Type == typeof(string) && !IsNullConstant(newRight))
newRight = Call(newRight, typeof(object).GetDeclaredMethod("ToString"));
CheckNullableToNonNullableChanges(node.Left, node.Right, ref newLeft, ref newRight);
CheckNullableToNonNullableChanges(node.Right, node.Left, ref newRight, ref newLeft);
Expand Down