diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs index 07019bc10..28fe3d0c0 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs @@ -20,6 +20,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; +using System.Text; namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { @@ -614,6 +615,18 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } } + private static void AppendNamePart(string part, StringBuilder name) + { + foreach (char c in part) + { + if (c == '\\') + { + name.Append('\\'); + } + name.Append(c); + } + } + public void NoForeachOverArray(string[] array) { for (int i = 0; i < array.Length; i++) diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs b/ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs index 718c983b2..02978e5e4 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs @@ -348,10 +348,9 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms var itemVariable = m.Get("itemVariable").Single().GetILVariable(); var indexVariable = m.Get("indexVariable").Single().GetILVariable(); var arrayVariable = m.Get("arrayVariable").Single().GetILVariable(); - var loopContainer = forStatement.Annotation(); if (itemVariable == null || indexVariable == null || arrayVariable == null) return null; - if (arrayVariable.Type.Kind != TypeKind.Array) + if (arrayVariable.Type.Kind != TypeKind.Array && !arrayVariable.Type.IsKnownType(KnownTypeCode.String)) return null; if (!VariableCanBeUsedAsForeachLocal(itemVariable, forStatement)) return null;