You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
729 B

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using ICSharpCode.NRefactory.CSharp;
  6. namespace ICSharpCode.Decompiler.Ast.Transforms
  7. {
  8. class FlattenSwitchBlocks : IAstTransform
  9. {
  10. public void Run(AstNode compilationUnit)
  11. {
  12. foreach (var switchSection in compilationUnit.Descendants.OfType<SwitchSection>())
  13. {
  14. if (switchSection.Statements.Count != 1)
  15. continue;
  16. var blockStatement = switchSection.Statements.First() as BlockStatement;
  17. if (blockStatement == null || blockStatement.Statements.Any(st => st is VariableDeclarationStatement))
  18. continue;
  19. blockStatement.Remove();
  20. blockStatement.Statements.MoveTo(switchSection.Statements);
  21. }
  22. }
  23. }
  24. }