PageRenderTime 15ms CodeModel.GetById 12ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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