Browse Source

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

pull/1612/head
Siegfried Pammer 6 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 @@ -16,12 +16,25 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
continue;
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;
blockStatement.Remove();
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