Skip to content

Commit

Permalink
Break anonymous object creation the same as object initializer (#755)
Browse files Browse the repository at this point in the history
closes #753
  • Loading branch information
belav authored Nov 11, 2022
1 parent 02d9c8a commit a504c10
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ class ClassName

var query2 = from Customer c in customers select c;

var selectBreak =
from Customer c in customers
select new
{
One = c.One,
Two = c.Two,
Three = C.Three
};

var whereQuery = from c in customers where c.Value == "true" select d;

var orderByQuery =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ internal static class AnonymousObjectCreationExpression
{
public static Doc Print(AnonymousObjectCreationExpressionSyntax node, FormattingContext context)
{
var alwaysBreak = node.Initializers.Count >= 3;

return Doc.Group(
Token.PrintWithSuffix(node.NewKeyword, Doc.Line, context),
Token.Print(node.OpenBraceToken, context),
node.Initializers.Any()
? Doc.Indent(
Doc.Line,
alwaysBreak ? Doc.HardLine : Doc.Line,
SeparatedSyntaxList.Print(
node.Initializers,
AnonymousObjectMemberDeclarator.Print,
Expand Down

0 comments on commit a504c10

Please sign in to comment.