From cafda5f692ef2fb2ac2b369f9f82767e467352c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Sun, 6 Mar 2011 13:26:53 +0000 Subject: [PATCH] Generate switch default case. Closes #26 --- .../CSharp/OutputVisitor/OutputVisitor.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs index 5f9d0f1c79..da02c47d5f 100644 --- a/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory/CSharp/OutputVisitor/OutputVisitor.cs @@ -1529,8 +1529,13 @@ namespace ICSharpCode.NRefactory.CSharp public object VisitSwitchSection(SwitchSection switchSection, object data) { StartNode(switchSection); - foreach (var label in switchSection.CaseLabels) + bool first = true; + foreach (var label in switchSection.CaseLabels) { + if (!first) + NewLine(); label.AcceptVisitor(this, data); + first = false; + } foreach (var statement in switchSection.Statements) statement.AcceptVisitor(this, data); return EndNode(switchSection); @@ -1539,11 +1544,14 @@ namespace ICSharpCode.NRefactory.CSharp public object VisitCaseLabel(CaseLabel caseLabel, object data) { StartNode(caseLabel); - WriteKeyword("case"); - Space(); - caseLabel.Expression.AcceptVisitor(this, data); + if (caseLabel.Expression.IsNull) { + WriteKeyword("default"); + } else { + WriteKeyword("case"); + Space(); + caseLabel.Expression.AcceptVisitor(this, data); + } WriteToken(":", CaseLabel.Roles.Colon); - NewLine(); return EndNode(caseLabel); }