Browse Source

* Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs: Improved

collection initializer output.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4407 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Mike Krüger 16 years ago
parent
commit
80b46b6b8d
  1. 33
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs

33
src/Libraries/NRefactory/Project/Src/PrettyPrinter/CSharp/CSharpOutputVisitor.cs

@ -2793,10 +2793,22 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public override object TrackedVisitCollectionInitializerExpression(CollectionInitializerExpression arrayInitializerExpression, object data) public override object TrackedVisitCollectionInitializerExpression(CollectionInitializerExpression arrayInitializerExpression, object data)
{ {
outputFormatter.PrintToken(Tokens.OpenCurlyBrace); outputFormatter.PrintToken (Tokens.OpenCurlyBrace);
outputFormatter.Space(); if (arrayInitializerExpression.CreateExpressions.Count == 1) {
this.AppendCommaSeparatedList(arrayInitializerExpression.CreateExpressions); outputFormatter.Space ();
outputFormatter.Space(); } else {
outputFormatter.IndentationLevel++;
outputFormatter.NewLine ();
outputFormatter.Indent ();
}
this.AppendCommaSeparatedList (arrayInitializerExpression.CreateExpressions, true);
if (arrayInitializerExpression.CreateExpressions.Count == 1) {
outputFormatter.Space ();
} else {
outputFormatter.IndentationLevel--;
outputFormatter.NewLine();
outputFormatter.Indent();
}
outputFormatter.PrintToken(Tokens.CloseCurlyBrace); outputFormatter.PrintToken(Tokens.CloseCurlyBrace);
return null; return null;
} }
@ -2916,6 +2928,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
} }
public void AppendCommaSeparatedList<T>(ICollection<T> list) where T : class, INode public void AppendCommaSeparatedList<T>(ICollection<T> list) where T : class, INode
{
AppendCommaSeparatedList(list, false);
}
public void AppendCommaSeparatedList<T>(ICollection<T> list, bool alwaysBreakLine) where T : class, INode
{ {
if (list != null) { if (list != null) {
int i = 0; int i = 0;
@ -2923,10 +2940,10 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
node.AcceptVisitor(this, null); node.AcceptVisitor(this, null);
if (i + 1 < list.Count) { if (i + 1 < list.Count) {
PrintFormattedComma(); PrintFormattedComma();
} if (alwaysBreakLine || (i + 1) % 10 == 0) {
if ((i + 1) % 10 == 0) { outputFormatter.NewLine();
outputFormatter.NewLine(); outputFormatter.Indent();
outputFormatter.Indent(); }
} }
i++; i++;
} }

Loading…
Cancel
Save