1
1
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
2
- //
2
+ //
3
3
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4
4
// software and associated documentation files (the "Software"), to deal in the Software
5
5
// without restriction, including without limitation the rights to use, copy, modify, merge,
6
6
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7
7
// to whom the Software is furnished to do so, subject to the following conditions:
8
- //
8
+ //
9
9
// The above copyright notice and this permission notice shall be included in all copies or
10
10
// substantial portions of the Software.
11
- //
11
+ //
12
12
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13
13
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14
14
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
@@ -30,9 +30,18 @@ namespace ICSharpCode.ILSpy.TreeNodes
30
30
/// </summary>
31
31
public sealed class AssemblyReferenceTreeNode : ILSpyTreeNode
32
32
{
33
+ private enum LoadState
34
+ {
35
+ Unloaded ,
36
+ Loading ,
37
+ Loadded ,
38
+ Failed
39
+ }
33
40
readonly MetadataModule module ;
34
41
readonly AssemblyReference r ;
35
42
readonly AssemblyTreeNode parentAssembly ;
43
+ MetadataFile referencedModule ;
44
+ private LoadState state ;
36
45
37
46
public AssemblyReferenceTreeNode ( MetadataModule module , AssemblyReference r , AssemblyTreeNode parentAssembly )
38
47
{
@@ -48,7 +57,27 @@ public override object Text {
48
57
get { return Language . EscapeName ( r . Name ) + GetSuffixString ( r . Handle ) ; }
49
58
}
50
59
51
- public override object Icon => Images . Assembly ;
60
+ public override object Icon {
61
+ get {
62
+ if ( state == LoadState . Unloaded )
63
+ {
64
+ state = LoadState . Loading ;
65
+ Dispatcher . CurrentDispatcher . BeginInvoke ( ( ) => {
66
+ var resolver = parentAssembly . LoadedAssembly . GetAssemblyResolver ( MainWindow . Instance . CurrentDecompilerSettings . AutoLoadAssemblyReferences ) ;
67
+ referencedModule = resolver . Resolve ( r ) ;
68
+ state = referencedModule is null
69
+ ? LoadState . Failed
70
+ : LoadState . Loadded ;
71
+ RaisePropertyChanged ( nameof ( Icon ) ) ;
72
+ } , DispatcherPriority . Background ) ;
73
+ }
74
+ return state switch {
75
+ LoadState . Loadded => Images . Assembly ,
76
+ LoadState . Failed => Images . AssemblyWarning ,
77
+ _ => Images . AssemblyLoading ,
78
+ } ;
79
+ }
80
+ }
52
81
53
82
public override bool ShowExpander {
54
83
get {
@@ -60,7 +89,7 @@ public override bool ShowExpander {
60
89
// while the list of references is updated causes problems with WPF's ListView rendering.
61
90
// Moving the assembly resolving out of the "add assembly reference"-loop by using the
62
91
// dispatcher fixes the issue.
63
- Dispatcher . CurrentDispatcher . BeginInvoke ( ( Action ) EnsureLazyChildren , DispatcherPriority . Normal ) ;
92
+ Dispatcher . CurrentDispatcher . BeginInvoke ( EnsureLazyChildren , DispatcherPriority . Normal ) ;
64
93
}
65
94
return base . ShowExpander ;
66
95
}
@@ -79,10 +108,7 @@ public override void ActivateItem(System.Windows.RoutedEventArgs e)
79
108
protected override void LoadChildren ( )
80
109
{
81
110
this . Children . Add ( new AssemblyReferenceReferencedTypesTreeNode ( module , r ) ) ;
82
-
83
- var resolver = parentAssembly . LoadedAssembly . GetAssemblyResolver ( MainWindow . Instance . CurrentDecompilerSettings . AutoLoadAssemblyReferences ) ;
84
- var referencedModule = resolver . Resolve ( r ) ;
85
- if ( referencedModule != null )
111
+ if ( referencedModule is not null )
86
112
{
87
113
var module = ( MetadataModule ) referencedModule . GetTypeSystemWithCurrentOptionsOrNull ( ) . MainModule ;
88
114
foreach ( var childRef in referencedModule . AssemblyReferences )
@@ -106,7 +132,10 @@ public override void Decompile(Language language, ITextOutput output, Decompilat
106
132
output . Indent ( ) ;
107
133
language . WriteCommentLine ( output , "Assembly reference loading information:" ) ;
108
134
if ( info . HasErrors )
135
+ {
109
136
language . WriteCommentLine ( output , "There were some problems during assembly reference load, see below for more information!" ) ;
137
+ state = LoadState . Failed ;
138
+ }
110
139
foreach ( var item in info . Messages )
111
140
{
112
141
language . WriteCommentLine ( output , $ "{ item . Item1 } : { item . Item2 } ") ;
0 commit comments