diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs index bdd424c49..477aba5ee 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -173,6 +173,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms if (instructions[i - 1].MatchStLoc(switchValueVar, out switchValue)) { // stloc switchValueVar(switchValue) // if (call op_Equality(ldloc switchValueVar, ldstr value)) br firstBlock + + // Newer versions of Roslyn use extra variables: + if (i >= 2 && switchValue.MatchLdLoc(out var otherSwitchValueVar) && otherSwitchValueVar.IsSingleDefinition && otherSwitchValueVar.LoadCount == 1 + && instructions[i - 2].MatchStLoc(otherSwitchValueVar, out switchValue)) { + extraLoad = true; + } } else if (instructions[i - 1] is StLoc stloc) { if (stloc.Value.MatchLdLoc(switchValueVar)) { // in case of optimized legacy code there are two stlocs: