Skip to content

Commit

Permalink
Don't print trailing comma for enumerable constants (#22925)
Browse files Browse the repository at this point in the history
* Don't print trailing comma for enumerable constants

* Flip condition

* Update src/EFCore/Query/ExpressionPrinter.cs

Co-authored-by: Smit Patel <smitpatel@users.noreply.github.com>
  • Loading branch information
roji and smitpatel authored Oct 9, 2020
1 parent 7122369 commit ec3df8f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/EFCore/Query/ExpressionPrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,13 +459,22 @@ private void Print(object value)
&& !(value is string))
{
_stringBuilder.Append(value.GetType().ShortDisplayName() + " { ");

var first = true;
foreach (var item in enumerable)
{
if (first)
{
first = false;
}
else
{
_stringBuilder.Append(", ");
}
Print(item);
_stringBuilder.Append(", ");
}

_stringBuilder.Append("}");
_stringBuilder.Append(" }");
return;
}

Expand Down
10 changes: 10 additions & 0 deletions test/EFCore.Tests/Query/ExpressionPrinterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,15 @@ public void Linq_methods_printed_as_extensions()
_expressionPrinter.Print(expr.Body),
ignoreLineEndingDifferences: true);
}

[ConditionalFact]
public void Enumerable_Constant_printed_correctly()
{
Assert.Equal(
@"int[] { 1, 2, 3 }",
_expressionPrinter.Print(
Expression.Constant(
new[] { 1, 2, 3 })));
}
}
}

0 comments on commit ec3df8f

Please sign in to comment.