diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs index 874769b9b..1c99c6ed4 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Switch.cs @@ -1192,5 +1192,22 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty throw new ArgumentOutOfRangeException(); } } + + public static bool DoNotRemoveAssignmentBeforeSwitch(string x, out ConsoleKey key) + { + key = (ConsoleKey)0; + switch (x) { + case "A": + key = ConsoleKey.A; + break; + case "B": + key = ConsoleKey.B; + break; + case "C": + key = ConsoleKey.C; + break; + } + return key != (ConsoleKey)0; + } } } \ No newline at end of file diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs index 7c8575c20..c9c1cd804 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -203,6 +203,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms switchValue = new LdLoc(switchValueVar); } } else { + // Instruction before the start of the switch is not related to the switch. + keepAssignmentBefore = true; switchValue = new LdLoc(switchValueVar); } // if instruction must be followed by a branch to the next case diff --git a/ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs b/ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs index 51a1c8cfe..d7b5ae5aa 100644 --- a/ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs +++ b/ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs @@ -26,7 +26,7 @@ using System.Text; namespace ICSharpCode.Decompiler.Metadata { - // This inspired by Mono.Cecil's BaseAssemblyResolver/DefaultAssemblyResolver. + // This is inspired by Mono.Cecil's BaseAssemblyResolver/DefaultAssemblyResolver. public class UniversalAssemblyResolver : IAssemblyResolver { static UniversalAssemblyResolver()