From e953379916881c2465d484151b3c3025ef234746 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 26 Jun 2016 12:42:17 +0200 Subject: [PATCH] Add NRefactory to RoundtripAssembly. Add support for 'ref multiDimArray[1, 2]'. --- ICSharpCode.Decompiler/IL/ILReader.cs | 5 +++++ ICSharpCode.Decompiler/Tests/RoundtripAssembly.cs | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/ICSharpCode.Decompiler/IL/ILReader.cs b/ICSharpCode.Decompiler/IL/ILReader.cs index ab1a8592d..a2d4ca448 100644 --- a/ICSharpCode.Decompiler/IL/ILReader.cs +++ b/ICSharpCode.Decompiler/IL/ILReader.cs @@ -998,6 +998,11 @@ namespace ICSharpCode.Decompiler.IL var indices = arguments.Skip(1).ToArray(); return Push(new LdObj(new LdElema(elementType, target, indices), elementType)); } + if (method.Name == "Address") { + var target = arguments[0]; + var indices = arguments.Skip(1).ToArray(); + return Push(new LdElema(elementType, target, indices)); + } Warn("Unknown method called on array type: " + method.Name); goto default; default: diff --git a/ICSharpCode.Decompiler/Tests/RoundtripAssembly.cs b/ICSharpCode.Decompiler/Tests/RoundtripAssembly.cs index 718facca4..7b36732b3 100644 --- a/ICSharpCode.Decompiler/Tests/RoundtripAssembly.cs +++ b/ICSharpCode.Decompiler/Tests/RoundtripAssembly.cs @@ -40,6 +40,16 @@ namespace ICSharpCode.Decompiler.Tests RunWithTest("Mono.Cecil-net45", "Mono.Cecil.dll", "Mono.Cecil.Tests.dll"); } + [Test] + public void NRefactory_CSharp() + { + try { + RunWithTest("NRefactory", "ICSharpCode.NRefactory.CSharp.dll", "ICSharpCode.NRefactory.Tests.dll"); + } catch (CompilationFailedException ex) { + Assert.Ignore(ex.Message); + } + } + [Test] public void Random_Tests_TestCases() { @@ -88,6 +98,8 @@ namespace ICSharpCode.Decompiler.Tests resolver.AddSearchDirectory(inputDir); var module = ModuleDefinition.ReadModule(file, new ReaderParameters { AssemblyResolver = resolver }); var decompiler = new WholeProjectDecompiler(); + // use a fixed GUID so that we can diff the output between different ILSpy runs without spurious changes + decompiler.ProjectGuid = Guid.Parse("{127C83E4-4587-4CF9-ADCA-799875F3DFE6}"); decompiler.DecompileProject(module, decompiledDir); Console.WriteLine($"Decompiled {fileToRoundtrip} in {w.Elapsed.TotalSeconds:f2}"); projectFile = Path.Combine(decompiledDir, module.Assembly.Name.Name + ".csproj");