/ICSharpCode.Decompiler/Ast/Transforms/FlattenSwitchBlocks.cs

http://github.com/icsharpcode/ILSpy · C# · 27 lines · 24 code · 3 blank · 0 comment · 5 complexity · 4d99459ade0abaaee29ad40bccf97b95 MD5 · raw file

  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. }