Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ExpressionType.Add in CSharpHelper #20142

Merged
merged 1 commit into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 17 additions & 0 deletions src/EFCore.Design/Design/Internal/CSharpHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,23 @@ private bool HandleExpression(Expression expression, StringBuilder builder, bool
.Append('.')
.Append(memberExpression.Member.Name);

return true;
}
case ExpressionType.Add:
{
var binaryExpression = (BinaryExpression)expression;
if (!HandleExpression(binaryExpression.Left, builder))
{
return false;
}

builder.Append(" + ");

if (!HandleExpression(binaryExpression.Right, builder))
{
return false;
}

return true;
}
}
Expand Down
17 changes: 15 additions & 2 deletions test/EFCore.Design.Tests/Design/Internal/CSharpHelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -572,16 +572,29 @@ public void Literal_with_instance_property()
}

[ConditionalFact]
public void Literal_with_unsupported_node_throws()
public void Literal_with_add()
{
var typeMapping = CreateTypeMappingSource<SimpleTestType>(
v => Expression.Add(
Expression.Constant(10),
Expression.Constant(10)));

Assert.Equal(
"10 + 10",
new CSharpHelper(typeMapping).UnknownLiteral(new SimpleTestType()));
}

[ConditionalFact]
public void Literal_with_unsupported_node_throws()
{
var typeMapping = CreateTypeMappingSource<SimpleTestType>(
v => Expression.Multiply(
Expression.Constant(10),
Expression.Constant(10)));

Assert.Equal(
DesignStrings.LiteralExpressionNotSupported(
"(10 + 10)",
"(10 * 10)",
nameof(SimpleTestType)),
Assert.Throws<NotSupportedException>(
() => new CSharpHelper(typeMapping).UnknownLiteral(new SimpleTestType())).Message);
Expand Down