diff --git a/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyAddIn.csproj b/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyAddIn.csproj
index d41f81ac34..e4e3e1d0d7 100644
--- a/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyAddIn.csproj
+++ b/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyAddIn.csproj
@@ -67,7 +67,6 @@
-
diff --git a/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyAssemblyResolver.cs b/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyAssemblyResolver.cs
deleted file mode 100644
index b5e5e663d3..0000000000
--- a/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyAssemblyResolver.cs
+++ /dev/null
@@ -1,107 +0,0 @@
-// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
-// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
-
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-using ICSharpCode.Core;
-using ICSharpCode.SharpDevelop;
-using ICSharpCode.SharpDevelop.Parser;
-using Mono.Cecil;
-
-namespace ICSharpCode.ILSpyAddIn
-{
- class ILSpyAssemblyResolver : IAssemblyResolver
- {
- readonly DirectoryInfo directoryInfo;
- readonly IDictionary cache;
- readonly IDictionary localAssembliesCache;
-
- public ILSpyAssemblyResolver(string decompiledAssemblyFolder)
- {
- if (string.IsNullOrEmpty(decompiledAssemblyFolder))
- throw new ArgumentException("Invalid working folder");
-
- FolderPath = decompiledAssemblyFolder;
- this.directoryInfo = new DirectoryInfo(decompiledAssemblyFolder);
- this.cache = new Dictionary ();
- this.localAssembliesCache = new Dictionary();
-
- ReadLocalAssemblies();
- }
-
- public string FolderPath {
- get; private set;
- }
-
- public AssemblyDefinition Resolve(AssemblyNameReference name)
- {
- return this.Resolve(name, new ReaderParameters());
- }
-
- public AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters)
- {
- if (name == null)
- throw new ArgumentNullException("name");
-
- if (parameters == null)
- throw new ArgumentNullException("parameters");
-
- try {
- AssemblyDefinition assembly = null;
- if (cache.TryGetValue(name.FullName, out assembly))
- return assembly;
-
- // search into assemblyDecompiledFolder
- if (localAssembliesCache.ContainsKey(name.FullName)) {
- assembly = localAssembliesCache[name.FullName];
- }
-
- if (assembly == null) {
- // search using ILSpy's GacInterop.FindAssemblyInNetGac()
- string fileInGac = SD.GlobalAssemblyCache.FindAssemblyInNetGac(new DomAssemblyName(name.FullName));
- if (!string.IsNullOrEmpty(fileInGac)) {
- assembly = AssemblyDefinition.ReadAssembly(fileInGac, parameters);
- }
- }
-
- // update caches
- if (assembly != null) {
- this.cache.Add(assembly.FullName, assembly);
- }
- return assembly;
- } catch (Exception ex) {
- LoggingService.Error("Exception (ILSpyAssemblyResolver): " + ex.Message);
- return null;
- }
- }
-
- public AssemblyDefinition Resolve(string fullName)
- {
- return this.Resolve(fullName, new ReaderParameters());
- }
-
- public AssemblyDefinition Resolve(string fullName, ReaderParameters parameters)
- {
- if (string.IsNullOrEmpty(fullName))
- throw new ArgumentException("fullName is null or empty");
-
- return Resolve(AssemblyNameReference.Parse(fullName), parameters);
- }
-
- void ReadLocalAssemblies()
- {
- // read local assemblies
- foreach (var file in this.directoryInfo.GetFiles()) {
- try {
- var localAssembly = AssemblyDefinition.ReadAssembly(file.FullName);
- localAssembliesCache.Add(localAssembly.FullName, localAssembly);
- } catch {
- // unable to read assembly file
- }
- }
- }
- }
-}
diff --git a/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyDecompilerService.cs b/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyDecompilerService.cs
index ea29fac22d..c5852bece5 100644
--- a/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyDecompilerService.cs
+++ b/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyDecompilerService.cs
@@ -14,6 +14,7 @@ using ICSharpCode.Decompiler.Ast;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom.ClassBrowser;
+using ICSharpCode.SharpDevelop.Parser;
using Mono.Cecil;
namespace ICSharpCode.ILSpyAddIn
@@ -23,6 +24,38 @@ namespace ICSharpCode.ILSpyAddIn
///
public static class ILSpyDecompilerService
{
+ class ILSpyAssemblyResolver : DefaultAssemblySearcher, IAssemblyResolver
+ {
+ public ILSpyAssemblyResolver(FileName fileName)
+ : base(fileName)
+ {
+ }
+
+ public AssemblyDefinition Resolve(AssemblyNameReference name)
+ {
+ return Resolve(name, new ReaderParameters());
+ }
+
+ public AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters)
+ {
+ var file = FindAssembly(new DomAssemblyName(name.FullName));
+ if (file == null) return null;
+ return AssemblyDefinition.ReadAssembly(file, parameters);
+ }
+
+ public AssemblyDefinition Resolve(string fullName)
+ {
+ return Resolve(fullName, new ReaderParameters());
+ }
+
+ public AssemblyDefinition Resolve(string fullName, ReaderParameters parameters)
+ {
+ var file = FindAssembly(new DomAssemblyName(fullName));
+ if (file == null) return null;
+ return AssemblyDefinition.ReadAssembly(file, parameters);
+ }
+ }
+
public static ILSpyUnresolvedFile DecompileType(DecompiledTypeReference name)
{
if (name == null)
@@ -32,9 +65,9 @@ namespace ICSharpCode.ILSpyAddIn
public static async Task DecompileTypeAsync(DecompiledTypeReference name, CancellationToken cancellationToken)
{
- return Task.Run(
+ return await Task.Run(
delegate() { return DoDecompile(name, cancellationToken); },
- cancellationToken).Result;
+ cancellationToken);
}
static AstBuilder CreateAstBuilder(DecompiledTypeReference name, CancellationToken cancellationToken = default(CancellationToken))
@@ -42,7 +75,7 @@ namespace ICSharpCode.ILSpyAddIn
ReaderParameters readerParameters = new ReaderParameters();
// Use new assembly resolver instance so that the AssemblyDefinitions
// can be garbage-collected once the code is decompiled.
- readerParameters.AssemblyResolver = new ILSpyAssemblyResolver(Path.GetDirectoryName(name.AssemblyFile));
+ readerParameters.AssemblyResolver = new ILSpyAssemblyResolver(name.AssemblyFile);
ModuleDefinition module = ModuleDefinition.ReadModule(name.AssemblyFile, readerParameters);
TypeDefinition typeDefinition = module.GetType(name.Type.ReflectionName);
diff --git a/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyParser.cs b/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyParser.cs
index b4ec755972..de6f80e841 100644
--- a/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyParser.cs
+++ b/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyParser.cs
@@ -69,8 +69,9 @@ namespace ICSharpCode.ILSpyAddIn
{
DecompiledTypeReference reference = DecompiledTypeReference.FromFileName(fileName);
if (reference != null) {
-// var model = SD.GetService().FindAssemblyModel(reference.AssemblyFile);
-// return SD.AssemblyParserService.CreateCompilationForAssembly(model);
+ var model = SD.GetService().FindAssemblyModel(reference.AssemblyFile);
+ if (model != null)
+ return SD.AssemblyParserService.CreateCompilationForAssembly(model, true);
}
return new CSharpProjectContent()
.AddAssemblyReferences(defaultReferences.Value)
diff --git a/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyUnresolvedFile.cs b/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyUnresolvedFile.cs
index 61601faf23..f0268b9cee 100644
--- a/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyUnresolvedFile.cs
+++ b/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyUnresolvedFile.cs
@@ -34,9 +34,9 @@ namespace ICSharpCode.ILSpyAddIn
syntaxTree.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true });
var outputFormatter = TokenWriter.WrapInWriterThatSetsLocationsInAST(output);
syntaxTree.AcceptVisitor(new CSharpOutputVisitor(outputFormatter, FormattingOptionsFactory.CreateSharpDevelop()));
- ILSpyUnresolvedFile file = new ILSpyUnresolvedFile(name, builder.SyntaxTree.Errors);
+ ILSpyUnresolvedFile file = new ILSpyUnresolvedFile(name, syntaxTree.Errors);
builder.SyntaxTree.FileName = name.ToFileName();
- var ts = builder.SyntaxTree.ToTypeSystem();
+ var ts = syntaxTree.ToTypeSystem();
file.topLevel = ts.TopLevelTypeDefinitions;
file.MemberLocations = output.MemberLocations;
file.DebugSymbols = output.DebugSymbols;
@@ -67,10 +67,12 @@ namespace ICSharpCode.ILSpyAddIn
{
throw new NotImplementedException();
}
+
public IUnresolvedTypeDefinition GetInnermostTypeDefinition(TextLocation location)
{
throw new NotImplementedException();
}
+
public IUnresolvedMember GetMember(TextLocation location)
{
throw new NotImplementedException();
@@ -100,6 +102,7 @@ namespace ICSharpCode.ILSpyAddIn
throw new NotImplementedException();
}
}
+
public IList ModuleAttributes {
get {
throw new NotImplementedException();