Browse Source

FlattenSwitchBlocks: include local function and out var declarations in the list of exceptions.

pull/1612/head
Siegfried Pammer 7 years ago
parent
commit
3067aa5519
  1. 15
      ICSharpCode.Decompiler/CSharp/Transforms/FlattenSwitchBlocks.cs

15
ICSharpCode.Decompiler/CSharp/Transforms/FlattenSwitchBlocks.cs

@ -16,12 +16,25 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
continue; continue;
var blockStatement = switchSection.Statements.First() as BlockStatement; var blockStatement = switchSection.Statements.First() as BlockStatement;
if (blockStatement == null || blockStatement.Statements.Any(st => st is VariableDeclarationStatement)) if (blockStatement == null || blockStatement.Statements.Any(ContainsLocalDeclaration))
continue; continue;
blockStatement.Remove(); blockStatement.Remove();
blockStatement.Statements.MoveTo(switchSection.Statements); blockStatement.Statements.MoveTo(switchSection.Statements);
} }
bool ContainsLocalDeclaration(AstNode node)
{
if (node is VariableDeclarationStatement || node is LocalFunctionDeclarationStatement || node is OutVarDeclarationExpression)
return true;
if (node is BlockStatement)
return false;
foreach (var child in node.Children) {
if (ContainsLocalDeclaration(child))
return true;
}
return false;
}
} }
} }
} }

Loading…
Cancel
Save