summaryrefslogtreecommitdiff
path: root/ICSharpCode.Decompiler/Ast/Transforms/FlattenSwitchBlocks.cs
diff options
context:
space:
mode:
Diffstat (limited to 'ICSharpCode.Decompiler/Ast/Transforms/FlattenSwitchBlocks.cs')
-rw-r--r--ICSharpCode.Decompiler/Ast/Transforms/FlattenSwitchBlocks.cs27
1 files changed, 27 insertions, 0 deletions
diff --git a/ICSharpCode.Decompiler/Ast/Transforms/FlattenSwitchBlocks.cs b/ICSharpCode.Decompiler/Ast/Transforms/FlattenSwitchBlocks.cs
new file mode 100644
index 00000000..9595e81b
--- /dev/null
+++ b/ICSharpCode.Decompiler/Ast/Transforms/FlattenSwitchBlocks.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using ICSharpCode.NRefactory.CSharp;
+
+namespace ICSharpCode.Decompiler.Ast.Transforms
+{
+ internal class FlattenSwitchBlocks : IAstTransform
+ {
+ public void Run(AstNode compilationUnit)
+ {
+ foreach (var switchSection in compilationUnit.Descendants.OfType<SwitchSection>())
+ {
+ if (switchSection.Statements.Count != 1)
+ continue;
+
+ var blockStatement = switchSection.Statements.First() as BlockStatement;
+ if (blockStatement == null || blockStatement.Statements.Any(st => st is VariableDeclarationStatement))
+ continue;
+
+ blockStatement.Remove();
+ blockStatement.Statements.MoveTo(switchSection.Statements);
+ }
+ }
+ }
+}