Browse Source

Tuning MainWindow_Loaded: Show IU as early as possible

pull/992/head
Siegfried Pammer 8 years ago
parent
commit
12dc70e05a
  1. 2
      ILSpy.BamlDecompiler/BamlResourceEntryNode.cs
  2. 2
      ILSpy.BamlDecompiler/BamlResourceNodeFactory.cs
  3. 11
      ILSpy/Languages/CSharpLanguage.cs
  4. 11
      ILSpy/Languages/ILLanguage.cs
  5. 6
      ILSpy/Languages/Language.cs
  6. 49
      ILSpy/LoadedAssembly.cs
  7. 11
      ILSpy/MainWindow.xaml.cs
  8. 2
      ILSpy/SearchPane.cs
  9. 12
      ILSpy/TreeNodes/Analyzer/AnalyzedAttributeAppliedToTreeNode.cs
  10. 2
      ILSpy/TreeNodes/Analyzer/AnalyzerEntityTreeNode.cs
  11. 12
      ILSpy/TreeNodes/Analyzer/ScopedWhereUsedAnalyzer.cs
  12. 4
      ILSpy/TreeNodes/AssemblyListTreeNode.cs
  13. 2
      ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs
  14. 16
      ILSpy/TreeNodes/AssemblyTreeNode.cs
  15. 2
      ILSpy/TreeNodes/DerivedTypesTreeNode.cs
  16. 4
      ILSpy/TreeNodes/ILSpyTreeNode.cs
  17. 2
      ILSpy/TreeNodes/ReferenceFolderTreeNode.cs
  18. 2
      TestPlugin/ContextMenuCommand.cs

2
ILSpy.BamlDecompiler/BamlResourceEntryNode.cs

@ -50,7 +50,7 @@ namespace ILSpy.BamlDecompiler @@ -50,7 +50,7 @@ namespace ILSpy.BamlDecompiler
{
var asm = this.Ancestors().OfType<AssemblyTreeNode>().FirstOrDefault().LoadedAssembly;
Data.Position = 0;
XDocument xamlDocument = LoadIntoDocument(asm.GetAssemblyResolver(), asm.AssemblyDefinition, Data, cancellationToken);
XDocument xamlDocument = LoadIntoDocument(asm.GetAssemblyResolver(), asm.GetAssemblyDefinitionAsync().Result, Data, cancellationToken);
output.Write(xamlDocument.ToString());
return true;
}

2
ILSpy.BamlDecompiler/BamlResourceNodeFactory.cs

@ -35,7 +35,7 @@ namespace ILSpy.BamlDecompiler @@ -35,7 +35,7 @@ namespace ILSpy.BamlDecompiler
public string WriteResourceToFile(LoadedAssembly assembly, string fileName, Stream stream, DecompilationOptions options)
{
var document = BamlResourceEntryNode.LoadIntoDocument(assembly.GetAssemblyResolver(), assembly.AssemblyDefinition, stream, options.CancellationToken);
var document = BamlResourceEntryNode.LoadIntoDocument(assembly.GetAssemblyResolver(), assembly.GetAssemblyDefinitionAsync().Result, stream, options.CancellationToken);
fileName = Path.ChangeExtension(fileName, ".xaml");
document.Save(Path.Combine(options.SaveAsProjectDirectory, fileName));
return fileName;

11
ILSpy/Languages/CSharpLanguage.cs

@ -288,7 +288,7 @@ namespace ICSharpCode.ILSpy @@ -288,7 +288,7 @@ namespace ICSharpCode.ILSpy
void AddReferenceWarningMessage(AssemblyDefinition assembly, ITextOutput output)
{
var loadedAssembly = MainWindow.Instance.CurrentAssemblyList.GetAssemblies().FirstOrDefault(la => la.AssemblyDefinition == assembly);
var loadedAssembly = MainWindow.Instance.CurrentAssemblyList.GetAssemblies().FirstOrDefault(la => la.GetAssemblyDefinitionAsync().Result == assembly);
if (loadedAssembly == null || !loadedAssembly.LoadedAssemblyReferencesInfo.Any(i => i.Value.HasErrors))
return;
const string line1 = "Warning: Some assembly references could not be loaded. This might lead to incorrect decompilation of some parts,";
@ -322,15 +322,16 @@ namespace ICSharpCode.ILSpy @@ -322,15 +322,16 @@ namespace ICSharpCode.ILSpy
public override void DecompileAssembly(LoadedAssembly assembly, ITextOutput output, DecompilationOptions options)
{
var module = assembly.GetModuleDefinitionAsync().Result;
if (options.FullDecompilation && options.SaveAsProjectDirectory != null) {
var decompiler = new ILSpyWholeProjectDecompiler(assembly, options);
decompiler.ProjectGuid = App.CommandLineArguments.FixedGuid;
decompiler.DecompileProject(assembly.ModuleDefinition, options.SaveAsProjectDirectory, new TextOutputWriter(output), options.CancellationToken);
decompiler.DecompileProject(module, options.SaveAsProjectDirectory, new TextOutputWriter(output), options.CancellationToken);
} else {
AddReferenceWarningMessage(assembly.AssemblyDefinition, output);
AddReferenceWarningMessage(module.Assembly, output);
output.WriteLine();
base.DecompileAssembly(assembly, output, options);
ModuleDefinition mainModule = assembly.ModuleDefinition;
ModuleDefinition mainModule = module;
if (mainModule.Types.Count > 0) {
output.Write("// Global type: ");
output.WriteReference(mainModule.Types[0].FullName, mainModule.Types[0]);
@ -353,7 +354,7 @@ namespace ICSharpCode.ILSpy @@ -353,7 +354,7 @@ namespace ICSharpCode.ILSpy
// don't automatically load additional assemblies when an assembly node is selected in the tree view
using (options.FullDecompilation ? null : LoadedAssembly.DisableAssemblyLoad()) {
CSharpDecompiler decompiler = new CSharpDecompiler(assembly.ModuleDefinition, options.DecompilerSettings);
CSharpDecompiler decompiler = new CSharpDecompiler(module, options.DecompilerSettings);
decompiler.CancellationToken = options.CancellationToken;
SyntaxTree st;
if (options.FullDecompilation) {

11
ILSpy/Languages/ILLanguage.cs

@ -118,16 +118,17 @@ namespace ICSharpCode.ILSpy @@ -118,16 +118,17 @@ namespace ICSharpCode.ILSpy
output.WriteLine();
var dis = CreateDisassembler(output, options);
var module = assembly.GetModuleDefinitionAsync().Result;
if (options.FullDecompilation)
dis.WriteAssemblyReferences(assembly.ModuleDefinition);
if (assembly.AssemblyDefinition != null)
dis.WriteAssemblyHeader(assembly.AssemblyDefinition);
dis.WriteAssemblyReferences(module);
if (module.Assembly != null)
dis.WriteAssemblyHeader(module.Assembly);
output.WriteLine();
dis.WriteModuleHeader(assembly.ModuleDefinition);
dis.WriteModuleHeader(module);
if (options.FullDecompilation) {
output.WriteLine();
output.WriteLine();
dis.WriteModuleContents(assembly.ModuleDefinition);
dis.WriteModuleContents(module);
}
}

6
ILSpy/Languages/Language.cs

@ -87,15 +87,15 @@ namespace ICSharpCode.ILSpy @@ -87,15 +87,15 @@ namespace ICSharpCode.ILSpy
public virtual void DecompileAssembly(LoadedAssembly assembly, ITextOutput output, DecompilationOptions options)
{
WriteCommentLine(output, assembly.FileName);
if (assembly.AssemblyDefinition != null) {
var name = assembly.AssemblyDefinition.Name;
if (assembly.GetAssemblyDefinitionAsync().Result != null) {
var name = assembly.GetAssemblyDefinitionAsync().Result.Name;
if (name.IsWindowsRuntime) {
WriteCommentLine(output, name.Name + " [WinRT]");
} else {
WriteCommentLine(output, name.FullName);
}
} else {
WriteCommentLine(output, assembly.ModuleDefinition.Name);
WriteCommentLine(output, assembly.GetModuleDefinitionAsync().Result.Name);
}
}

49
ILSpy/LoadedAssembly.cs

@ -20,6 +20,7 @@ using System; @@ -20,6 +20,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Threading;
using ICSharpCode.Decompiler;
@ -37,7 +38,6 @@ namespace ICSharpCode.ILSpy @@ -37,7 +38,6 @@ namespace ICSharpCode.ILSpy
readonly AssemblyList assemblyList;
readonly string fileName;
readonly string shortName;
readonly Lazy<string> targetFrameworkId;
readonly Dictionary<string, UnresolvedAssemblyNameReference> loadedAssemblyReferences = new Dictionary<string, UnresolvedAssemblyNameReference>();
public LoadedAssembly(AssemblyList assemblyList, string fileName, Stream stream = null)
@ -51,14 +51,17 @@ namespace ICSharpCode.ILSpy @@ -51,14 +51,17 @@ namespace ICSharpCode.ILSpy
this.assemblyTask = Task.Factory.StartNew<ModuleDefinition>(LoadAssembly, stream); // requires that this.fileName is set
this.shortName = Path.GetFileNameWithoutExtension(fileName);
this.targetFrameworkId = new Lazy<string>(() => AssemblyDefinition?.DetectTargetFrameworkId(), false);
}
/// <summary>
/// Returns a target framework identifier in the form '&lt;framework&gt;Version=v&lt;version&gt;'.
/// Returns an empty string if no TargetFrameworkAttribute was found or the file doesn't contain an assembly header, i.e., is only a module.
/// </summary>
public string TargetFrameworkId => targetFrameworkId.Value ?? string.Empty;
public async Task<string> GetTargetFrameworkIdAsync()
{
var assembly = await GetAssemblyDefinitionAsync();
return assembly?.DetectTargetFrameworkId() ?? string.Empty;
}
public Dictionary<string, UnresolvedAssemblyNameReference> LoadedAssemblyReferencesInfo => loadedAssemblyReferences;
@ -66,26 +69,20 @@ namespace ICSharpCode.ILSpy @@ -66,26 +69,20 @@ namespace ICSharpCode.ILSpy
/// Gets the Cecil ModuleDefinition.
/// Can be null when there was a load error.
/// </summary>
public ModuleDefinition ModuleDefinition {
get {
try {
return assemblyTask.Result;
} catch (AggregateException) {
return null;
}
}
public Task<ModuleDefinition> GetModuleDefinitionAsync()
{
return assemblyTask;
}
/// <summary>
/// Gets the Cecil AssemblyDefinition.
/// Is null when there was a load error; or when opening a netmodule.
/// </summary>
public AssemblyDefinition AssemblyDefinition {
get {
var module = this.ModuleDefinition;
public async Task<AssemblyDefinition> GetAssemblyDefinitionAsync()
{
var module = await assemblyTask;
return module != null ? module.Assembly : null;
}
}
public AssemblyList AssemblyList => assemblyList;
@ -95,8 +92,8 @@ namespace ICSharpCode.ILSpy @@ -95,8 +92,8 @@ namespace ICSharpCode.ILSpy
public string Text {
get {
if (AssemblyDefinition != null) {
return String.Format("{0} ({1})", ShortName, AssemblyDefinition.Name.Version);
if (IsLoaded && !HasLoadError) {
return String.Format("{0} ({1})", ShortName, GetAssemblyDefinitionAsync().Result.Name.Version);
} else {
return ShortName;
}
@ -196,25 +193,25 @@ namespace ICSharpCode.ILSpy @@ -196,25 +193,25 @@ namespace ICSharpCode.ILSpy
public AssemblyDefinition Resolve(AssemblyNameReference name)
{
var node = parent.LookupReferencedAssembly(name);
return node != null ? node.AssemblyDefinition : null;
return node != null ? node.GetAssemblyDefinitionAsync().Result : null;
}
public AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters)
{
var node = parent.LookupReferencedAssembly(name);
return node != null ? node.AssemblyDefinition : null;
return node != null ? node.GetAssemblyDefinitionAsync().Result : null;
}
public AssemblyDefinition Resolve(string fullName)
{
var node = parent.LookupReferencedAssembly(fullName);
return node != null ? node.AssemblyDefinition : null;
return node != null ? node.GetAssemblyDefinitionAsync().Result : null;
}
public AssemblyDefinition Resolve(string fullName, ReaderParameters parameters)
{
var node = parent.LookupReferencedAssembly(fullName);
return node != null ? node.AssemblyDefinition : null;
return node != null ? node.GetAssemblyDefinitionAsync().Result : null;
}
public void Dispose()
@ -254,7 +251,8 @@ namespace ICSharpCode.ILSpy @@ -254,7 +251,8 @@ namespace ICSharpCode.ILSpy
LoadedAssembly LookupReferencedAssemblyInternal(string fullName)
{
foreach (LoadedAssembly asm in assemblyList.GetAssemblies()) {
if (asm.AssemblyDefinition != null && fullName.Equals(asm.AssemblyDefinition.FullName, StringComparison.OrdinalIgnoreCase)) {
var asmDef = asm.GetAssemblyDefinitionAsync().Result;
if (asmDef != null && fullName.Equals(asmDef.FullName, StringComparison.OrdinalIgnoreCase)) {
return asm;
}
}
@ -266,7 +264,7 @@ namespace ICSharpCode.ILSpy @@ -266,7 +264,7 @@ namespace ICSharpCode.ILSpy
return (LoadedAssembly)App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Func<string, LoadedAssembly>(LookupReferencedAssembly), fullName);
}
var resolver = new MyUniversalResolver(this) { TargetFramework = TargetFrameworkId };
var resolver = new MyUniversalResolver(this) { TargetFramework = GetTargetFrameworkIdAsync().Result };
var name = AssemblyNameReference.Parse(fullName);
var file = resolver.Resolve(name);
@ -282,7 +280,8 @@ namespace ICSharpCode.ILSpy @@ -282,7 +280,8 @@ namespace ICSharpCode.ILSpy
LoadedAssembly LookupWinRTMetadata(string name)
{
foreach (LoadedAssembly asm in assemblyList.GetAssemblies()) {
if (asm.AssemblyDefinition != null && name.Equals(asm.AssemblyDefinition.Name.Name, StringComparison.OrdinalIgnoreCase))
var asmDef = asm.GetAssemblyDefinitionAsync().Result;
if (asmDef!= null && name.Equals(asmDef.Name.Name, StringComparison.OrdinalIgnoreCase))
return asm;
}
if (assemblyLoadDisableCount > 0)
@ -302,7 +301,7 @@ namespace ICSharpCode.ILSpy @@ -302,7 +301,7 @@ namespace ICSharpCode.ILSpy
public Task ContinueWhenLoaded(Action<Task<ModuleDefinition>> onAssemblyLoaded, TaskScheduler taskScheduler)
{
return this.assemblyTask.ContinueWith(onAssemblyLoaded, taskScheduler);
return this.assemblyTask.ContinueWith(onAssemblyLoaded, default(CancellationToken), TaskContinuationOptions.RunContinuationsAsynchronously, taskScheduler);
}
/// <summary>

11
ILSpy/MainWindow.xaml.cs

@ -31,6 +31,7 @@ using System.Windows.Input; @@ -31,6 +31,7 @@ using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.Documentation;
using ICSharpCode.ILSpy.TextView;
@ -280,7 +281,7 @@ namespace ICSharpCode.ILSpy @@ -280,7 +281,7 @@ namespace ICSharpCode.ILSpy
}
} else {
foreach (LoadedAssembly asm in commandLineLoadedAssemblies) {
ModuleDefinition def = asm.ModuleDefinition;
ModuleDefinition def = asm.GetModuleDefinitionAsync().Result;
if (def != null) {
MemberReference mr = XmlDocKeyProvider.FindMemberByKey(def, args.NavigateTo);
if (mr != null) {
@ -299,7 +300,7 @@ namespace ICSharpCode.ILSpy @@ -299,7 +300,7 @@ namespace ICSharpCode.ILSpy
} else if (commandLineLoadedAssemblies.Count == 1) {
// NavigateTo == null and an assembly was given on the command-line:
// Select the newly loaded assembly
JumpToReference(commandLineLoadedAssemblies[0].ModuleDefinition);
JumpToReference(commandLineLoadedAssemblies[0].GetModuleDefinitionAsync().Result);
}
if (args.Search != null)
{
@ -327,6 +328,12 @@ namespace ICSharpCode.ILSpy @@ -327,6 +328,12 @@ namespace ICSharpCode.ILSpy
}
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(InitializeAssemblyListAndOpenAssemblies));
}
void InitializeAssemblyListAndOpenAssemblies()
{
ILSpySettings spySettings = this.spySettings;
this.spySettings = null;

2
ILSpy/SearchPane.cs

@ -216,7 +216,7 @@ namespace ICSharpCode.ILSpy @@ -216,7 +216,7 @@ namespace ICSharpCode.ILSpy
try {
var searcher = GetSearchStrategy(searchMode, searchTerm);
foreach (var loadedAssembly in assemblies) {
ModuleDefinition module = loadedAssembly.ModuleDefinition;
ModuleDefinition module = loadedAssembly.GetModuleDefinitionAsync().Result;
if (module == null)
continue;
CancellationToken cancellationToken = cts.Token;

12
ILSpy/TreeNodes/Analyzer/AnalyzedAttributeAppliedToTreeNode.cs

@ -295,21 +295,21 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -295,21 +295,21 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
string requiredAssemblyFullName = asm.FullName;
IEnumerable<LoadedAssembly> assemblies = MainWindow.Instance.CurrentAssemblyList.GetAssemblies().Where(assy => assy.AssemblyDefinition != null);
IEnumerable<LoadedAssembly> assemblies = MainWindow.Instance.CurrentAssemblyList.GetAssemblies().Where(assy => assy.GetAssemblyDefinitionAsync().Result != null);
foreach (var assembly in assemblies) {
ct.ThrowIfCancellationRequested();
bool found = false;
foreach (var reference in assembly.AssemblyDefinition.MainModule.AssemblyReferences) {
foreach (var reference in assembly.GetAssemblyDefinitionAsync().Result.MainModule.AssemblyReferences) {
if (requiredAssemblyFullName == reference.FullName) {
found = true;
break;
}
}
if (found) {
var typeref = GetScopeTypeReferenceInAssembly(assembly.AssemblyDefinition);
var typeref = GetScopeTypeReferenceInAssembly(assembly.GetAssemblyDefinitionAsync().Result);
if (typeref != null)
yield return new Tuple<AssemblyDefinition, TypeReference>(assembly.AssemblyDefinition, typeref);
yield return new Tuple<AssemblyDefinition, TypeReference>(assembly.GetAssemblyDefinitionAsync().Result, typeref);
}
}
}
@ -334,9 +334,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -334,9 +334,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
foreach (var assembly in assemblies) {
ct.ThrowIfCancellationRequested();
if (friendAssemblies.Contains(assembly.ShortName)) {
var typeref = GetScopeTypeReferenceInAssembly(assembly.AssemblyDefinition);
var typeref = GetScopeTypeReferenceInAssembly(assembly.GetAssemblyDefinitionAsync().Result);
if (typeref != null) {
yield return new Tuple<AssemblyDefinition, TypeReference>(assembly.AssemblyDefinition, typeref);
yield return new Tuple<AssemblyDefinition, TypeReference>(assembly.GetAssemblyDefinitionAsync().Result, typeref);
}
}
}

2
ILSpy/TreeNodes/Analyzer/AnalyzerEntityTreeNode.cs

@ -38,7 +38,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -38,7 +38,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
public override bool HandleAssemblyListChanged(ICollection<LoadedAssembly> removedAssemblies, ICollection<LoadedAssembly> addedAssemblies)
{
foreach (LoadedAssembly asm in removedAssemblies) {
if (this.Member.Module == asm.ModuleDefinition)
if (this.Member.Module == asm.GetModuleDefinitionAsync().Result)
return false; // remove this node
}
this.Children.RemoveAll(

12
ILSpy/TreeNodes/Analyzer/ScopedWhereUsedAnalyzer.cs

@ -254,19 +254,19 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -254,19 +254,19 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
string requiredAssemblyFullName = asm.FullName;
IEnumerable<LoadedAssembly> assemblies = MainWindow.Instance.CurrentAssemblyList.GetAssemblies().Where(assy => assy.AssemblyDefinition != null);
IEnumerable<LoadedAssembly> assemblies = MainWindow.Instance.CurrentAssemblyList.GetAssemblies().Where(assy => assy.GetAssemblyDefinitionAsync().Result != null);
foreach (var assembly in assemblies) {
ct.ThrowIfCancellationRequested();
bool found = false;
foreach (var reference in assembly.AssemblyDefinition.MainModule.AssemblyReferences) {
foreach (var reference in assembly.GetAssemblyDefinitionAsync().Result.MainModule.AssemblyReferences) {
if (requiredAssemblyFullName == reference.FullName) {
found = true;
break;
}
}
if (found && AssemblyReferencesScopeType(assembly.AssemblyDefinition))
yield return assembly.AssemblyDefinition;
if (found && AssemblyReferencesScopeType(assembly.GetAssemblyDefinitionAsync().Result))
yield return assembly.GetAssemblyDefinitionAsync().Result;
}
}
@ -289,8 +289,8 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -289,8 +289,8 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
foreach (var assembly in assemblies) {
ct.ThrowIfCancellationRequested();
if (friendAssemblies.Contains(assembly.ShortName) && AssemblyReferencesScopeType(assembly.AssemblyDefinition)) {
yield return assembly.AssemblyDefinition;
if (friendAssemblies.Contains(assembly.ShortName) && AssemblyReferencesScopeType(assembly.GetAssemblyDefinitionAsync().Result)) {
yield return assembly.GetAssemblyDefinitionAsync().Result;
}
}
}

4
ILSpy/TreeNodes/AssemblyListTreeNode.cs

@ -185,7 +185,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -185,7 +185,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
return null;
App.Current.Dispatcher.VerifyAccess();
foreach (AssemblyTreeNode node in this.Children) {
if (node.LoadedAssembly.IsLoaded && node.LoadedAssembly.ModuleDefinition == module)
if (node.LoadedAssembly.IsLoaded && node.LoadedAssembly.GetModuleDefinitionAsync().Result == module)
return node;
}
return null;
@ -197,7 +197,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -197,7 +197,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
return null;
App.Current.Dispatcher.VerifyAccess();
foreach (AssemblyTreeNode node in this.Children) {
if (node.LoadedAssembly.IsLoaded && node.LoadedAssembly.AssemblyDefinition == asm)
if (node.LoadedAssembly.IsLoaded && node.LoadedAssembly.GetAssemblyDefinitionAsync().Result == asm)
return node;
}
return null;

2
ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs

@ -77,7 +77,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -77,7 +77,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
if (assemblyListNode != null) {
var refNode = assemblyListNode.FindAssemblyNode(parentAssembly.LoadedAssembly.LookupReferencedAssembly(r));
if (refNode != null) {
ModuleDefinition module = refNode.LoadedAssembly.ModuleDefinition;
ModuleDefinition module = refNode.LoadedAssembly.GetModuleDefinitionAsync().Result;
if (module != null) {
foreach (var childRef in module.AssemblyReferences)
this.Children.Add(new AssemblyReferenceTreeNode(childRef, refNode));

16
ILSpy/TreeNodes/AssemblyTreeNode.cs

@ -95,19 +95,20 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -95,19 +95,20 @@ namespace ICSharpCode.ILSpy.TreeNodes
if (assembly.HasLoadError)
return "Assembly could not be loaded. Click here for details.";
if (tooltip == null) {
if (tooltip == null && assembly.IsLoaded) {
tooltip = new TextBlock();
if (assembly.AssemblyDefinition != null) {
var module = assembly.GetModuleDefinitionAsync().Result;
if (assembly.GetAssemblyDefinitionAsync().Result != null) {
tooltip.Inlines.Add(new Bold(new Run("Name: ")));
tooltip.Inlines.Add(new Run(assembly.AssemblyDefinition.FullName));
tooltip.Inlines.Add(new Run(module.Assembly.FullName));
tooltip.Inlines.Add(new LineBreak());
}
tooltip.Inlines.Add(new Bold(new Run("Location: ")));
tooltip.Inlines.Add(new Run(assembly.FileName));
tooltip.Inlines.Add(new LineBreak());
tooltip.Inlines.Add(new Bold(new Run("Architecture: ")));
tooltip.Inlines.Add(new Run(CSharpLanguage.GetPlatformDisplayName(assembly.ModuleDefinition)));
string runtimeName = CSharpLanguage.GetRuntimeDisplayName(assembly.ModuleDefinition);
tooltip.Inlines.Add(new Run(CSharpLanguage.GetPlatformDisplayName(module)));
string runtimeName = CSharpLanguage.GetRuntimeDisplayName(module);
if (runtimeName != null) {
tooltip.Inlines.Add(new LineBreak());
tooltip.Inlines.Add(new Bold(new Run("Runtime: ")));
@ -129,6 +130,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -129,6 +130,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
// change from "Loading" icon to final icon
RaisePropertyChanged("Icon");
RaisePropertyChanged("ExpandedIcon");
RaisePropertyChanged("Tooltip");
if (moduleTask.IsFaulted) {
RaisePropertyChanged("ShowExpander"); // cannot expand assemblies with load error
// observe the exception so that the Task's finalizer doesn't re-throw it
@ -143,7 +145,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -143,7 +145,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
protected override void LoadChildren()
{
ModuleDefinition moduleDefinition = assembly.ModuleDefinition;
ModuleDefinition moduleDefinition = assembly.GetModuleDefinitionAsync().Result;
if (moduleDefinition == null) {
// if we crashed on loading, then we don't have any children
return;
@ -381,7 +383,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -381,7 +383,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
foreach (var node in context.SelectedTreeNodes) {
var la = ((AssemblyTreeNode)node).LoadedAssembly;
if (!la.HasLoadError) {
foreach (var assyRef in la.ModuleDefinition.AssemblyReferences) {
foreach (var assyRef in la.GetModuleDefinitionAsync().Result.AssemblyReferences) {
la.LookupReferencedAssembly(assyRef.FullName);
}
}

2
ILSpy/TreeNodes/DerivedTypesTreeNode.cs

@ -60,7 +60,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -60,7 +60,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
IEnumerable<ILSpyTreeNode> FetchChildren(CancellationToken cancellationToken)
{
// FetchChildren() runs on the main thread; but the enumerator will be consumed on a background thread
var assemblies = list.GetAssemblies().Select(node => node.ModuleDefinition).Where(asm => asm != null).ToArray();
var assemblies = list.GetAssemblies().Select(node => node.GetModuleDefinitionAsync().Result).Where(asm => asm != null).ToArray();
return FindDerivedTypes(type, assemblies, cancellationToken);
}

4
ILSpy/TreeNodes/ILSpyTreeNode.cs

@ -150,11 +150,11 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -150,11 +150,11 @@ namespace ICSharpCode.ILSpy.TreeNodes
}
}
protected override void OnIsVisibleChanged()
/*protected override void OnIsVisibleChanged()
{
base.OnIsVisibleChanged();
EnsureChildrenFiltered();
}
}*/
internal void EnsureChildrenFiltered()
{

2
ILSpy/TreeNodes/ReferenceFolderTreeNode.cs

@ -61,7 +61,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -61,7 +61,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
language.WriteCommentLine(output, $"Detected Target-Framework-Id: {parentAssembly.LoadedAssembly.TargetFrameworkId}");
language.WriteCommentLine(output, $"Detected Target-Framework-Id: {parentAssembly.LoadedAssembly.GetTargetFrameworkIdAsync().Result}");
App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(EnsureLazyChildren));
output.WriteLine();
language.WriteCommentLine(output, "Referenced assemblies (in metadata order):");

2
TestPlugin/ContextMenuCommand.cs

@ -27,7 +27,7 @@ namespace TestPlugin @@ -27,7 +27,7 @@ namespace TestPlugin
if (context.SelectedTreeNodes == null)
return;
AssemblyTreeNode node = (AssemblyTreeNode)context.SelectedTreeNodes[0];
AssemblyDefinition asm = node.LoadedAssembly.AssemblyDefinition;
AssemblyDefinition asm = node.LoadedAssembly.GetAssemblyDefinitionAsync().Result;
if (asm != null) {
SaveFileDialog dlg = new SaveFileDialog();
dlg.FileName = node.LoadedAssembly.FileName;

Loading…
Cancel
Save