diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/VariableNamingWithoutSymbols.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/VariableNamingWithoutSymbols.cs index e724559fd..bb458845b 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/VariableNamingWithoutSymbols.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/VariableNamingWithoutSymbols.cs @@ -1,4 +1,7 @@ -namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty +using System; +using System.Collections.Generic; + +namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { internal class VariableNamingWithoutSymbols { @@ -25,5 +28,54 @@ string text2 = c.Text; #endif } + + private static IDisposable GetData() + { + return null; + } + + private static void UseData(IDisposable data) + { + + } + + private static IEnumerable GetItems() + { + throw null; + } + + private static byte[] GetMemory() + { + throw null; + } + + private static void Test(int item) + { + foreach (int item2 in GetItems()) + { + Console.WriteLine(item2); + } + } + + private static void Test(IDisposable data) + { +#if CS80 + using IDisposable data2 = GetData(); + UseData(data2); +#else + using (IDisposable data2 = GetData()) + { + UseData(data2); + } +#endif + } + + private unsafe static void Test(byte[] memory) + { + fixed (byte* memory2 = GetMemory()) + { + Console.WriteLine(*memory2); + } + } } } diff --git a/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs b/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs index 108b1aa80..4b9dcc5dd 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs @@ -233,7 +233,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms void AssignName() { - if (v.HasGeneratedName || !IsValidName(v.Name) || ConflictWithLocal(v)) + if (v.HasGeneratedName || !IsValidName(v.Name)) { // don't use the name from the debug symbols if it looks like a generated name v.Name = null; @@ -337,16 +337,6 @@ namespace ICSharpCode.Decompiler.IL.Transforms } } - bool ConflictWithLocal(ILVariable v) - { - if (v.Kind == VariableKind.UsingLocal || v.Kind == VariableKind.ForeachLocal) - { - if (reservedVariableNames.ContainsKey(v.Name)) - return true; - } - return false; - } - internal static bool IsValidName(string varName) { if (string.IsNullOrWhiteSpace(varName))