From 596fca2b373b60a59d4fb12b638037bb3eeb490b Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 10 Oct 2017 16:35:06 +0200 Subject: [PATCH] Fix unit tests --- .../CSharp/StatementBuilder.cs | 4 ++-- .../ConnectMethodDecompiler.cs | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs index 8cf20cfb8..56fdfb6e9 100644 --- a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs @@ -153,7 +153,7 @@ namespace ICSharpCode.Decompiler.CSharp switch (section.Body) { case Branch br: // we can only inline the block, if all branches are in the switchContainer. - if (br.TargetBlock.IsDescendantOf(switchContainer)) + if (br.TargetBlock.Parent == switchContainer && switchContainer.Descendants.OfType().Where(b => b.TargetBlock == br.TargetBlock).All(b => BlockContainer.FindClosestContainer(b) == switchContainer)) caseLabelMapping.Add(br.TargetBlock, firstValueResolveResult); break; default: @@ -167,7 +167,7 @@ namespace ICSharpCode.Decompiler.CSharp switch (section.Body) { case Branch br: // we can only inline the block, if all branches are in the switchContainer. - if (br.TargetBlock.IsDescendantOf(switchContainer)) + if (br.TargetBlock.Parent == switchContainer && switchContainer.Descendants.OfType().Where(b => b.TargetBlock == br.TargetBlock).All(b => BlockContainer.FindClosestContainer(b) == switchContainer)) ConvertSwitchSectionBody(astSection, br.TargetBlock); else ConvertSwitchSectionBody(astSection, section.Body); diff --git a/ILSpy.BamlDecompiler/ConnectMethodDecompiler.cs b/ILSpy.BamlDecompiler/ConnectMethodDecompiler.cs index a28f63d7b..39ddba883 100644 --- a/ILSpy.BamlDecompiler/ConnectMethodDecompiler.cs +++ b/ILSpy.BamlDecompiler/ConnectMethodDecompiler.cs @@ -66,7 +66,7 @@ namespace ILSpy.BamlDecompiler function.RunTransforms(CSharpDecompiler.GetILTransforms(), context); var block = function.Body.Children.OfType().First(); - var ilSwitch = block.Children.OfType().FirstOrDefault(); + var ilSwitch = block.Descendants.OfType().FirstOrDefault(); if (ilSwitch != null) { foreach (var section in ilSwitch.Sections) { @@ -92,13 +92,18 @@ namespace ILSpy.BamlDecompiler { var events = new List(); - if (inst is Block) { - foreach (var node in ((Block)inst).Instructions) { - FindEvents(node, events); - } - FindEvents(((Block)inst).FinalInstruction, events); - } else { - FindEvents(inst, events); + switch (inst) { + case Block b: + foreach (var node in ((Block)inst).Instructions) { + FindEvents(node, events); + } + FindEvents(((Block)inst).FinalInstruction, events); + break; + case Branch br: + return FindEvents(br.TargetBlock); + default: + FindEvents(inst, events); + break; } return events.ToArray(); }