mirror of https://github.com/icsharpcode/ILSpy.git
7 changed files with 85 additions and 13 deletions
@ -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 |
||||||
|
{ |
||||||
|
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); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue