From 5a317786af8968ebf2e0d868e1701e5ae8981d6d Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 10 Apr 2011 12:33:53 +0200 Subject: [PATCH] Avoid loading assemblies when figuring out whether a property is in indexer. --- ILSpy/LoadedAssembly.cs | 24 ++++++++++++++++++++++++ ILSpy/TreeNodes/PropertyTreeNode.cs | 4 +++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/ILSpy/LoadedAssembly.cs b/ILSpy/LoadedAssembly.cs index 81f46e142..d0e3f182c 100644 --- a/ILSpy/LoadedAssembly.cs +++ b/ILSpy/LoadedAssembly.cs @@ -72,6 +72,28 @@ namespace ICSharpCode.ILSpy return AssemblyDefinition.ReadAssembly(fileName, p); } + [ThreadStatic] + static int assemblyLoadDisableCount; + + public static IDisposable DisableAssemblyLoad() + { + assemblyLoadDisableCount++; + return new DecrementAssemblyLoadDisableCount(); + } + + sealed class DecrementAssemblyLoadDisableCount : IDisposable + { + bool disposed; + + public void Dispose() + { + if (!disposed) { + disposed = true; + assemblyLoadDisableCount--; + } + } + } + sealed class MyAssemblyResolver : IAssemblyResolver { readonly LoadedAssembly parent; @@ -112,6 +134,8 @@ namespace ICSharpCode.ILSpy if (asm.AssemblyDefinition != null && fullName.Equals(asm.AssemblyDefinition.FullName, StringComparison.OrdinalIgnoreCase)) return asm; } + if (assemblyLoadDisableCount > 0) + return null; if (!App.Current.Dispatcher.CheckAccess()) { // Call this method on the GUI thread. diff --git a/ILSpy/TreeNodes/PropertyTreeNode.cs b/ILSpy/TreeNodes/PropertyTreeNode.cs index 24a12f0c7..2ead5dc71 100644 --- a/ILSpy/TreeNodes/PropertyTreeNode.cs +++ b/ILSpy/TreeNodes/PropertyTreeNode.cs @@ -36,7 +36,9 @@ namespace ICSharpCode.ILSpy.TreeNodes if (property == null) throw new ArgumentNullException("property"); this.property = property; - this.isIndexer = property.IsIndexer(); + using (LoadedAssembly.DisableAssemblyLoad()) { + this.isIndexer = property.IsIndexer(); + } if (property.GetMethod != null) this.Children.Add(new MethodTreeNode(property.GetMethod));