Browse Source

Analyzer code clean-up.

pull/147/head
Ed Harvey 15 years ago
parent
commit
e40fe48a5b
  1. 4
      ILSpy/BamlDecompiler.cs
  2. 6
      ILSpy/ILSpy.csproj
  3. 5
      ILSpy/TreeNodes/Analyzer/AnalyzeContextMenuEntry.cs
  4. 9
      ILSpy/TreeNodes/Analyzer/AnalyzedEventAccessorsTreeNode.cs
  5. 15
      ILSpy/TreeNodes/Analyzer/AnalyzedEventOverridesTreeNode.cs
  6. 8
      ILSpy/TreeNodes/Analyzer/AnalyzedEventTreeNode.cs
  7. 20
      ILSpy/TreeNodes/Analyzer/AnalyzedFieldAccessTreeNode.cs
  8. 10
      ILSpy/TreeNodes/Analyzer/AnalyzedFieldTreeNode.cs
  9. 12
      ILSpy/TreeNodes/Analyzer/AnalyzedInterfaceEventImplementedByTreeNode.cs
  10. 10
      ILSpy/TreeNodes/Analyzer/AnalyzedInterfaceMethodImplementedByTreeNode.cs
  11. 12
      ILSpy/TreeNodes/Analyzer/AnalyzedInterfacePropertyImplementedByTreeNode.cs
  12. 25
      ILSpy/TreeNodes/Analyzer/AnalyzedMethodOverridesTreeNode.cs
  13. 8
      ILSpy/TreeNodes/Analyzer/AnalyzedMethodTreeNode.cs
  14. 16
      ILSpy/TreeNodes/Analyzer/AnalyzedMethodUsedByTreeNode.cs
  15. 12
      ILSpy/TreeNodes/Analyzer/AnalyzedMethodUsesTreeNode.cs
  16. 9
      ILSpy/TreeNodes/Analyzer/AnalyzedPropertyAccessorsTreeNode.cs
  17. 13
      ILSpy/TreeNodes/Analyzer/AnalyzedPropertyOverridesTreeNode.cs
  18. 10
      ILSpy/TreeNodes/Analyzer/AnalyzedPropertyTreeNode.cs
  19. 20
      ILSpy/TreeNodes/Analyzer/AnalyzedTypeExposedByTreeNode.cs
  20. 36
      ILSpy/TreeNodes/Analyzer/AnalyzedTypeExtensionMethodsTreeNode.cs
  21. 17
      ILSpy/TreeNodes/Analyzer/AnalyzedTypeInstantiationsTreeNode.cs
  22. 4
      ILSpy/TreeNodes/Analyzer/AnalyzedTypeTreeNode.cs
  23. 2
      ILSpy/TreeNodes/Analyzer/AnalyzerTreeNode.cs
  24. 2
      ILSpy/TreeNodes/Analyzer/Helpers.cs
  25. 18
      ILSpy/TreeNodes/Analyzer/ScopedWhereUsedAnalyzer.cs
  26. 24
      ILSpy/TreeNodes/AssemblyTreeNode.cs
  27. 26
      ILSpy/TreeNodes/ResourceEntryNode.cs
  28. 2
      ILSpy/TreeNodes/XamlResourceNode.cs

4
ILSpy/BamlDecompiler.cs

@ -400,8 +400,8 @@ namespace ICSharpCode.ILSpy.Baml
BamlDecompiler decompiler = CreateBamlDecompilerInAppDomain(ref bamlDecompilerAppDomain, asm.FileName); BamlDecompiler decompiler = CreateBamlDecompilerInAppDomain(ref bamlDecompilerAppDomain, asm.FileName);
MemoryStream bamlStream = new MemoryStream(); MemoryStream bamlStream = new MemoryStream();
data.Position = 0; Data.Position = 0;
data.CopyTo(bamlStream); Data.CopyTo(bamlStream);
output.Write(decompiler.DecompileBaml(bamlStream, asm.FileName, new ConnectMethodDecompiler(asm), new AssemblyResolver(asm))); output.Write(decompiler.DecompileBaml(bamlStream, asm.FileName, new ConnectMethodDecompiler(asm), new AssemblyResolver(asm)));
return true; return true;

6
ILSpy/ILSpy.csproj

@ -178,11 +178,11 @@
<Compile Include="TextView\ReferenceElementGenerator.cs" /> <Compile Include="TextView\ReferenceElementGenerator.cs" />
<Compile Include="TextView\AvalonEditTextOutput.cs" /> <Compile Include="TextView\AvalonEditTextOutput.cs" />
<Compile Include="TextView\UIElementGenerator.cs" /> <Compile Include="TextView\UIElementGenerator.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzedFieldAccessNode.cs" /> <Compile Include="TreeNodes\Analyzer\AnalyzedFieldAccessTreeNode.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzedFieldNode.cs" /> <Compile Include="TreeNodes\Analyzer\AnalyzedFieldTreeNode.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzedMethodTreeNode.cs" /> <Compile Include="TreeNodes\Analyzer\AnalyzedMethodTreeNode.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzedMethodUsedByTreeNode.cs" /> <Compile Include="TreeNodes\Analyzer\AnalyzedMethodUsedByTreeNode.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzedMethodUsesNode.cs" /> <Compile Include="TreeNodes\Analyzer\AnalyzedMethodUsesTreeNode.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzerTreeNode.cs" /> <Compile Include="TreeNodes\Analyzer\AnalyzerTreeNode.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzedMethodOverridesTreeNode.cs" /> <Compile Include="TreeNodes\Analyzer\AnalyzedMethodOverridesTreeNode.cs" />
<Compile Include="TreeNodes\AssemblyListTreeNode.cs" /> <Compile Include="TreeNodes\AssemblyListTreeNode.cs" />

5
ILSpy/TreeNodes/Analyzer/AnalyzeContextMenuEntry.cs

@ -24,7 +24,7 @@ using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{ {
[ExportContextMenuEntry(Header = "Analyze", Icon = "images/Search.png")] [ExportContextMenuEntry(Header = "Analyze", Icon = "images/Search.png")]
sealed class AnalyzeContextMenuEntry : IContextMenuEntry internal sealed class AnalyzeContextMenuEntry : IContextMenuEntry
{ {
public bool IsVisible(SharpTreeNode[] selectedNodes) public bool IsVisible(SharpTreeNode[] selectedNodes)
{ {
@ -41,6 +41,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
|| Analyzer.AnalyzedEventTreeNode.CanShow(node.Member))) || Analyzer.AnalyzedEventTreeNode.CanShow(node.Member)))
return false; return false;
} }
return true; return true;
} }
@ -54,7 +55,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
MainWindow.Instance.AddToAnalyzer(new AnalyzedTypeTreeNode(type)); MainWindow.Instance.AddToAnalyzer(new AnalyzedTypeTreeNode(type));
FieldDefinition field = node.Member as FieldDefinition; FieldDefinition field = node.Member as FieldDefinition;
if (field != null) if (field != null)
MainWindow.Instance.AddToAnalyzer(new AnalyzedFieldNode(field)); MainWindow.Instance.AddToAnalyzer(new AnalyzedFieldTreeNode(field));
MethodDefinition method = node.Member as MethodDefinition; MethodDefinition method = node.Member as MethodDefinition;
if (method != null) if (method != null)
MainWindow.Instance.AddToAnalyzer(new AnalyzedMethodTreeNode(method)); MainWindow.Instance.AddToAnalyzer(new AnalyzedMethodTreeNode(method));

9
ILSpy/TreeNodes/Analyzer/AnalyzedEventAccessorsTreeNode.cs

@ -21,15 +21,12 @@ using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{ {
public class AnalyzedEventAccessorsTreeNode : AnalyzerTreeNode internal sealed class AnalyzedEventAccessorsTreeNode : AnalyzerTreeNode
{ {
EventDefinition analyzedEvent;
public AnalyzedEventAccessorsTreeNode(EventDefinition analyzedEvent) public AnalyzedEventAccessorsTreeNode(EventDefinition analyzedEvent)
{ {
if (analyzedEvent == null) if (analyzedEvent == null)
throw new ArgumentNullException("analyzedEvent"); throw new ArgumentNullException("analyzedEvent");
this.analyzedEvent = analyzedEvent;
if (analyzedEvent.AddMethod != null) if (analyzedEvent.AddMethod != null)
this.Children.Add(new AnalyzedEventAccessorTreeNode(analyzedEvent.AddMethod, "add")); this.Children.Add(new AnalyzedEventAccessorTreeNode(analyzedEvent.AddMethod, "add"));
@ -54,9 +51,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
return !MainWindow.Instance.CurrentLanguage.ShowMember(property.AddMethod ?? property.RemoveMethod); return !MainWindow.Instance.CurrentLanguage.ShowMember(property.AddMethod ?? property.RemoveMethod);
} }
class AnalyzedEventAccessorTreeNode : AnalyzedMethodTreeNode internal class AnalyzedEventAccessorTreeNode : AnalyzedMethodTreeNode
{ {
string name; private string name;
public AnalyzedEventAccessorTreeNode(MethodDefinition analyzedMethod, string name) public AnalyzedEventAccessorTreeNode(MethodDefinition analyzedMethod, string name)
: base(analyzedMethod) : base(analyzedMethod)

15
ILSpy/TreeNodes/Analyzer/AnalyzedEventOverridesTreeNode.cs

@ -27,10 +27,10 @@ using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{ {
class AnalyzedEventOverridesTreeNode : AnalyzerTreeNode internal sealed class AnalyzedEventOverridesTreeNode : AnalyzerTreeNode
{ {
readonly EventDefinition analyzedEvent; private readonly EventDefinition analyzedEvent;
readonly ThreadingSupport threading; private readonly ThreadingSupport threading;
public AnalyzedEventOverridesTreeNode(EventDefinition analyzedEvent) public AnalyzedEventOverridesTreeNode(EventDefinition analyzedEvent)
{ {
@ -44,7 +44,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
public override object Text public override object Text
{ {
get { return "Overriden By"; } get { return "Overridden By"; }
} }
public override object Icon public override object Icon
@ -66,19 +66,20 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
} }
} }
IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct) private IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct)
{ {
return FindReferences(MainWindow.Instance.CurrentAssemblyList.GetAssemblies(), ct); return FindReferences(MainWindow.Instance.CurrentAssemblyList.GetAssemblies(), ct);
} }
IEnumerable<SharpTreeNode> FindReferences(IEnumerable<LoadedAssembly> assemblies, CancellationToken ct) private IEnumerable<SharpTreeNode> FindReferences(IEnumerable<LoadedAssembly> assemblies, CancellationToken ct)
{ {
assemblies = assemblies.Where(asm => asm.AssemblyDefinition != null); assemblies = assemblies.Where(asm => asm.AssemblyDefinition != null);
// use parallelism only on the assembly level (avoid locks within Cecil) // use parallelism only on the assembly level (avoid locks within Cecil)
return assemblies.AsParallel().WithCancellation(ct).SelectMany((LoadedAssembly asm) => FindReferences(asm, ct)); return assemblies.AsParallel().WithCancellation(ct).SelectMany((LoadedAssembly asm) => FindReferences(asm, ct));
} }
IEnumerable<SharpTreeNode> FindReferences(LoadedAssembly asm, CancellationToken ct) private IEnumerable<SharpTreeNode> FindReferences(LoadedAssembly asm, CancellationToken ct)
{ {
string asmName = asm.AssemblyDefinition.Name.Name; string asmName = asm.AssemblyDefinition.Name.Name;
string name = analyzedEvent.Name; string name = analyzedEvent.Name;

8
ILSpy/TreeNodes/Analyzer/AnalyzedEventTreeNode.cs

@ -21,15 +21,15 @@ using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{ {
class AnalyzedEventTreeNode : AnalyzerTreeNode internal sealed class AnalyzedEventTreeNode : AnalyzerTreeNode
{ {
EventDefinition analyzedEvent; private readonly EventDefinition analyzedEvent;
string prefix; private readonly string prefix;
public AnalyzedEventTreeNode(EventDefinition analyzedEvent, string prefix = "") public AnalyzedEventTreeNode(EventDefinition analyzedEvent, string prefix = "")
{ {
if (analyzedEvent == null) if (analyzedEvent == null)
throw new ArgumentNullException("analyzedMethod"); throw new ArgumentNullException("analyzedEvent");
this.analyzedEvent = analyzedEvent; this.analyzedEvent = analyzedEvent;
this.prefix = prefix; this.prefix = prefix;
this.LazyLoading = true; this.LazyLoading = true;

20
ILSpy/TreeNodes/Analyzer/AnalyzedFieldAccessNode.cs → ILSpy/TreeNodes/Analyzer/AnalyzedFieldAccessTreeNode.cs

@ -25,13 +25,13 @@ using Mono.Cecil.Cil;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{ {
class AnalyzedFieldAccessNode : AnalyzerTreeNode internal sealed class AnalyzedFieldAccessTreeNode : AnalyzerTreeNode
{ {
readonly bool showWrites; // true: show writes; false: show read access private readonly bool showWrites; // true: show writes; false: show read access
readonly FieldDefinition analyzedField; private readonly FieldDefinition analyzedField;
readonly ThreadingSupport threading; private readonly ThreadingSupport threading;
public AnalyzedFieldAccessNode(FieldDefinition analyzedField, bool showWrites) public AnalyzedFieldAccessTreeNode(FieldDefinition analyzedField, bool showWrites)
{ {
if (analyzedField == null) if (analyzedField == null)
throw new ArgumentNullException("analyzedField"); throw new ArgumentNullException("analyzedField");
@ -66,13 +66,13 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
} }
} }
IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct) private IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct)
{ {
var analyzer = new ScopedWhereUsedScopeAnalyzer<SharpTreeNode>(analyzedField, FindReferencesInType); var analyzer = new ScopedWhereUsedScopeAnalyzer<SharpTreeNode>(analyzedField, FindReferencesInType);
return analyzer.PerformAnalysis(ct); return analyzer.PerformAnalysis(ct);
} }
IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type) private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type)
{ {
string name = analyzedField.Name; string name = analyzedField.Name;
string declTypeName = analyzedField.DeclaringType.FullName; string declTypeName = analyzedField.DeclaringType.FullName;
@ -84,7 +84,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
foreach (Instruction instr in method.Body.Instructions) { foreach (Instruction instr in method.Body.Instructions) {
if (CanBeReference(instr.OpCode.Code)) { if (CanBeReference(instr.OpCode.Code)) {
FieldReference fr = instr.Operand as FieldReference; FieldReference fr = instr.Operand as FieldReference;
if (fr != null && fr.Name == name && Helpers.IsReferencedBy(analyzedField.DeclaringType, fr.DeclaringType) && fr.Resolve() == analyzedField) { if (fr != null && fr.Name == name &&
Helpers.IsReferencedBy(analyzedField.DeclaringType, fr.DeclaringType) &&
fr.Resolve() == analyzedField) {
found = true; found = true;
break; break;
} }
@ -98,7 +100,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
} }
} }
bool CanBeReference(Code code) private bool CanBeReference(Code code)
{ {
switch (code) { switch (code) {
case Code.Ldfld: case Code.Ldfld:

10
ILSpy/TreeNodes/Analyzer/AnalyzedFieldNode.cs → ILSpy/TreeNodes/Analyzer/AnalyzedFieldTreeNode.cs

@ -21,11 +21,11 @@ using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{ {
class AnalyzedFieldNode : AnalyzerTreeNode, IMemberTreeNode internal class AnalyzedFieldTreeNode : AnalyzerTreeNode, IMemberTreeNode
{ {
FieldDefinition analyzedField; private readonly FieldDefinition analyzedField;
public AnalyzedFieldNode(FieldDefinition analyzedField) public AnalyzedFieldTreeNode(FieldDefinition analyzedField)
{ {
if (analyzedField == null) if (analyzedField == null)
throw new ArgumentNullException("analyzedField"); throw new ArgumentNullException("analyzedField");
@ -55,9 +55,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
protected override void LoadChildren() protected override void LoadChildren()
{ {
this.Children.Add(new AnalyzedFieldAccessNode(analyzedField, false)); this.Children.Add(new AnalyzedFieldAccessTreeNode(analyzedField, false));
if (!analyzedField.IsLiteral) if (!analyzedField.IsLiteral)
this.Children.Add(new AnalyzedFieldAccessNode(analyzedField, true)); this.Children.Add(new AnalyzedFieldAccessTreeNode(analyzedField, true));
} }
MemberReference IMemberTreeNode.Member MemberReference IMemberTreeNode.Member

12
ILSpy/TreeNodes/Analyzer/AnalyzedInterfaceEventImplementedByTreeNode.cs

@ -26,11 +26,11 @@ using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{ {
class AnalyzedInterfaceEventImplementedByTreeNode : AnalyzerTreeNode internal sealed class AnalyzedInterfaceEventImplementedByTreeNode : AnalyzerTreeNode
{ {
EventDefinition analyzedEvent; private readonly EventDefinition analyzedEvent;
MethodDefinition analyzedMethod; private readonly MethodDefinition analyzedMethod;
ThreadingSupport threading; private readonly ThreadingSupport threading;
public AnalyzedInterfaceEventImplementedByTreeNode(EventDefinition analyzedEvent) public AnalyzedInterfaceEventImplementedByTreeNode(EventDefinition analyzedEvent)
{ {
@ -67,14 +67,14 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
} }
} }
IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct) private IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct)
{ {
ScopedWhereUsedScopeAnalyzer<SharpTreeNode> analyzer; ScopedWhereUsedScopeAnalyzer<SharpTreeNode> analyzer;
analyzer = new ScopedWhereUsedScopeAnalyzer<SharpTreeNode>(analyzedMethod, FindReferencesInType); analyzer = new ScopedWhereUsedScopeAnalyzer<SharpTreeNode>(analyzedMethod, FindReferencesInType);
return analyzer.PerformAnalysis(ct); return analyzer.PerformAnalysis(ct);
} }
IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type) private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type)
{ {
if (!type.HasInterfaces) if (!type.HasInterfaces)
yield break; yield break;

10
ILSpy/TreeNodes/Analyzer/AnalyzedInterfaceMethodImplementedByTreeNode.cs

@ -26,10 +26,10 @@ using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{ {
class AnalyzedInterfaceMethodImplementedByTreeNode : AnalyzerTreeNode internal sealed class AnalyzedInterfaceMethodImplementedByTreeNode : AnalyzerTreeNode
{ {
MethodDefinition analyzedMethod; private readonly MethodDefinition analyzedMethod;
ThreadingSupport threading; private readonly ThreadingSupport threading;
public AnalyzedInterfaceMethodImplementedByTreeNode(MethodDefinition analyzedMethod) public AnalyzedInterfaceMethodImplementedByTreeNode(MethodDefinition analyzedMethod)
{ {
@ -65,14 +65,14 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
} }
} }
IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct) private IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct)
{ {
ScopedWhereUsedScopeAnalyzer<SharpTreeNode> analyzer; ScopedWhereUsedScopeAnalyzer<SharpTreeNode> analyzer;
analyzer = new ScopedWhereUsedScopeAnalyzer<SharpTreeNode>(analyzedMethod, FindReferencesInType); analyzer = new ScopedWhereUsedScopeAnalyzer<SharpTreeNode>(analyzedMethod, FindReferencesInType);
return analyzer.PerformAnalysis(ct); return analyzer.PerformAnalysis(ct);
} }
IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type) private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type)
{ {
if (!type.HasInterfaces) if (!type.HasInterfaces)
yield break; yield break;

12
ILSpy/TreeNodes/Analyzer/AnalyzedInterfacePropertyImplementedByTreeNode.cs

@ -26,11 +26,11 @@ using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{ {
class AnalyzedInterfacePropertyImplementedByTreeNode : AnalyzerTreeNode internal sealed class AnalyzedInterfacePropertyImplementedByTreeNode : AnalyzerTreeNode
{ {
PropertyDefinition analyzedProperty; private readonly PropertyDefinition analyzedProperty;
MethodDefinition analyzedMethod; private readonly MethodDefinition analyzedMethod;
ThreadingSupport threading; private readonly ThreadingSupport threading;
public AnalyzedInterfacePropertyImplementedByTreeNode(PropertyDefinition analyzedProperty) public AnalyzedInterfacePropertyImplementedByTreeNode(PropertyDefinition analyzedProperty)
{ {
@ -67,14 +67,14 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
} }
} }
IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct) private IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct)
{ {
ScopedWhereUsedScopeAnalyzer<SharpTreeNode> analyzer; ScopedWhereUsedScopeAnalyzer<SharpTreeNode> analyzer;
analyzer = new ScopedWhereUsedScopeAnalyzer<SharpTreeNode>(analyzedMethod, FindReferencesInType); analyzer = new ScopedWhereUsedScopeAnalyzer<SharpTreeNode>(analyzedMethod, FindReferencesInType);
return analyzer.PerformAnalysis(ct); return analyzer.PerformAnalysis(ct);
} }
IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type) private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type)
{ {
if (!type.HasInterfaces) if (!type.HasInterfaces)
yield break; yield break;

25
ILSpy/TreeNodes/Analyzer/AnalyzedMethodOverridesTreeNode.cs

@ -14,10 +14,10 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
/// <summary> /// <summary>
/// Searches for overrides of the analyzed method. /// Searches for overrides of the analyzed method.
/// </summary> /// </summary>
class AnalyzedMethodOverridesTreeNode : AnalyzerTreeNode internal sealed class AnalyzedMethodOverridesTreeNode : AnalyzerTreeNode
{ {
readonly MethodDefinition analyzedMethod; private readonly MethodDefinition analyzedMethod;
readonly ThreadingSupport threading; private readonly ThreadingSupport threading;
public AnalyzedMethodOverridesTreeNode(MethodDefinition analyzedMethod) public AnalyzedMethodOverridesTreeNode(MethodDefinition analyzedMethod)
{ {
@ -46,33 +46,32 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
protected override void OnCollapsing() protected override void OnCollapsing()
{ {
if (threading.IsRunning) if (threading.IsRunning) {
{
this.LazyLoading = true; this.LazyLoading = true;
threading.Cancel(); threading.Cancel();
this.Children.Clear(); this.Children.Clear();
} }
} }
IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct) private IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct)
{ {
return FindReferences(MainWindow.Instance.CurrentAssemblyList.GetAssemblies(), ct); return FindReferences(MainWindow.Instance.CurrentAssemblyList.GetAssemblies(), ct);
} }
IEnumerable<SharpTreeNode> FindReferences(IEnumerable<LoadedAssembly> assemblies, CancellationToken ct) private IEnumerable<SharpTreeNode> FindReferences(IEnumerable<LoadedAssembly> assemblies, CancellationToken ct)
{ {
assemblies = assemblies.Where(asm => asm.AssemblyDefinition != null); assemblies = assemblies.Where(asm => asm.AssemblyDefinition != null);
// use parallelism only on the assembly level (avoid locks within Cecil) // use parallelism only on the assembly level (avoid locks within Cecil)
return assemblies.AsParallel().WithCancellation(ct).SelectMany((LoadedAssembly asm) => FindReferences(asm, ct)); return assemblies.AsParallel().WithCancellation(ct).SelectMany((LoadedAssembly asm) => FindReferences(asm, ct));
} }
IEnumerable<SharpTreeNode> FindReferences(LoadedAssembly asm, CancellationToken ct) private IEnumerable<SharpTreeNode> FindReferences(LoadedAssembly asm, CancellationToken ct)
{ {
string asmName = asm.AssemblyDefinition.Name.Name; string asmName = asm.AssemblyDefinition.Name.Name;
string name = analyzedMethod.Name; string name = analyzedMethod.Name;
string declTypeName = analyzedMethod.DeclaringType.FullName; string declTypeName = analyzedMethod.DeclaringType.FullName;
foreach (TypeDefinition type in TreeTraversal.PreOrder(asm.AssemblyDefinition.MainModule.Types, t => t.NestedTypes)) foreach (TypeDefinition type in TreeTraversal.PreOrder(asm.AssemblyDefinition.MainModule.Types, t => t.NestedTypes)) {
{
ct.ThrowIfCancellationRequested(); ct.ThrowIfCancellationRequested();
SharpTreeNode newNode = null; SharpTreeNode newNode = null;
try { try {
@ -91,6 +90,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
catch (ReferenceResolvingException) { catch (ReferenceResolvingException) {
// ignore this type definition. maybe add a notification about such cases. // ignore this type definition. maybe add a notification about such cases.
} }
if (newNode != null) if (newNode != null)
yield return newNode; yield return newNode;
} }
@ -98,7 +98,10 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
public static bool CanShow(MethodDefinition method) public static bool CanShow(MethodDefinition method)
{ {
return method.IsVirtual && !method.IsFinal && !method.DeclaringType.IsSealed && !method.DeclaringType.IsInterface; // interfaces are temporarly disabled return method.IsVirtual &&
!method.IsFinal &&
!method.DeclaringType.IsSealed &&
!method.DeclaringType.IsInterface; // interface methods are definitions not implementations - cannot be overridden
} }
} }
} }

8
ILSpy/TreeNodes/Analyzer/AnalyzedMethodTreeNode.cs

@ -21,10 +21,10 @@ using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{ {
class AnalyzedMethodTreeNode : AnalyzerTreeNode, IMemberTreeNode internal class AnalyzedMethodTreeNode : AnalyzerTreeNode, IMemberTreeNode
{ {
MethodDefinition analyzedMethod; private readonly MethodDefinition analyzedMethod;
string prefix; private readonly string prefix;
public AnalyzedMethodTreeNode(MethodDefinition analyzedMethod, string prefix = "") public AnalyzedMethodTreeNode(MethodDefinition analyzedMethod, string prefix = "")
{ {
@ -57,7 +57,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
protected override void LoadChildren() protected override void LoadChildren()
{ {
if (analyzedMethod.HasBody) if (analyzedMethod.HasBody)
this.Children.Add(new AnalyzedMethodUsesNode(analyzedMethod)); this.Children.Add(new AnalyzedMethodUsesTreeNode(analyzedMethod));
this.Children.Add(new AnalyzedMethodUsedByTreeNode(analyzedMethod)); this.Children.Add(new AnalyzedMethodUsedByTreeNode(analyzedMethod));
if (AnalyzedMethodOverridesTreeNode.CanShow(analyzedMethod)) if (AnalyzedMethodOverridesTreeNode.CanShow(analyzedMethod))
this.Children.Add(new AnalyzedMethodOverridesTreeNode(analyzedMethod)); this.Children.Add(new AnalyzedMethodOverridesTreeNode(analyzedMethod));

16
ILSpy/TreeNodes/Analyzer/AnalyzedMethodUsedByTreeNode.cs

@ -25,10 +25,10 @@ using Mono.Cecil.Cil;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{ {
class AnalyzedMethodUsedByTreeNode : AnalyzerTreeNode internal sealed class AnalyzedMethodUsedByTreeNode : AnalyzerTreeNode
{ {
MethodDefinition analyzedMethod; private readonly MethodDefinition analyzedMethod;
ThreadingSupport threading; private readonly ThreadingSupport threading;
public AnalyzedMethodUsedByTreeNode(MethodDefinition analyzedMethod) public AnalyzedMethodUsedByTreeNode(MethodDefinition analyzedMethod)
{ {
@ -64,7 +64,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
} }
} }
IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct) private IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct)
{ {
ScopedWhereUsedScopeAnalyzer<SharpTreeNode> analyzer; ScopedWhereUsedScopeAnalyzer<SharpTreeNode> analyzer;
@ -72,7 +72,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
return analyzer.PerformAnalysis(ct); return analyzer.PerformAnalysis(ct);
} }
IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type) private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type)
{ {
string name = analyzedMethod.Name; string name = analyzedMethod.Name;
foreach (MethodDefinition method in type.Methods) { foreach (MethodDefinition method in type.Methods) {
@ -81,13 +81,15 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
continue; continue;
foreach (Instruction instr in method.Body.Instructions) { foreach (Instruction instr in method.Body.Instructions) {
MethodReference mr = instr.Operand as MethodReference; MethodReference mr = instr.Operand as MethodReference;
if (mr != null && mr.Name == name && Helpers.IsReferencedBy(analyzedMethod.DeclaringType, mr.DeclaringType) && mr.Resolve() == analyzedMethod) { if (mr != null &&
mr.Name == name &&
Helpers.IsReferencedBy(analyzedMethod.DeclaringType, mr.DeclaringType) &&
mr.Resolve() == analyzedMethod) {
found = true; found = true;
break; break;
} }
} }
method.Body = null; method.Body = null;
if (found) if (found)

12
ILSpy/TreeNodes/Analyzer/AnalyzedMethodUsesNode.cs → ILSpy/TreeNodes/Analyzer/AnalyzedMethodUsesTreeNode.cs

@ -27,11 +27,11 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
/// <summary> /// <summary>
/// Shows the methods that are used by this method. /// Shows the methods that are used by this method.
/// </summary> /// </summary>
sealed class AnalyzedMethodUsesNode : AnalyzerTreeNode internal sealed class AnalyzedMethodUsesTreeNode : AnalyzerTreeNode
{ {
MethodDefinition analyzedMethod; private readonly MethodDefinition analyzedMethod;
public AnalyzedMethodUsesNode(MethodDefinition analyzedMethod) public AnalyzedMethodUsesTreeNode(MethodDefinition analyzedMethod)
{ {
if (analyzedMethod == null) if (analyzedMethod == null)
throw new ArgumentNullException("analyzedMethod"); throw new ArgumentNullException("analyzedMethod");
@ -53,7 +53,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
protected override void LoadChildren() protected override void LoadChildren()
{ {
foreach (var f in GetUsedFields().Distinct()) { foreach (var f in GetUsedFields().Distinct()) {
this.Children.Add(new AnalyzedFieldNode(f)); this.Children.Add(new AnalyzedFieldTreeNode(f));
} }
foreach (var m in GetUsedMethods().Distinct()) { foreach (var m in GetUsedMethods().Distinct()) {
this.Children.Add(new AnalyzedMethodTreeNode(m)); this.Children.Add(new AnalyzedMethodTreeNode(m));
@ -61,7 +61,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
analyzedMethod.Body = null; analyzedMethod.Body = null;
} }
IEnumerable<MethodDefinition> GetUsedMethods() private IEnumerable<MethodDefinition> GetUsedMethods()
{ {
foreach (Instruction instr in analyzedMethod.Body.Instructions) { foreach (Instruction instr in analyzedMethod.Body.Instructions) {
MethodReference mr = instr.Operand as MethodReference; MethodReference mr = instr.Operand as MethodReference;
@ -73,7 +73,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
} }
} }
IEnumerable<FieldDefinition> GetUsedFields() private IEnumerable<FieldDefinition> GetUsedFields()
{ {
foreach (Instruction instr in analyzedMethod.Body.Instructions) { foreach (Instruction instr in analyzedMethod.Body.Instructions) {
FieldReference fr = instr.Operand as FieldReference; FieldReference fr = instr.Operand as FieldReference;

9
ILSpy/TreeNodes/Analyzer/AnalyzedPropertyAccessorsTreeNode.cs

@ -21,15 +21,12 @@ using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{ {
public class AnalyzedPropertyAccessorsTreeNode : AnalyzerTreeNode public sealed class AnalyzedPropertyAccessorsTreeNode : AnalyzerTreeNode
{ {
PropertyDefinition analyzedProperty;
public AnalyzedPropertyAccessorsTreeNode(PropertyDefinition analyzedProperty) public AnalyzedPropertyAccessorsTreeNode(PropertyDefinition analyzedProperty)
{ {
if (analyzedProperty == null) if (analyzedProperty == null)
throw new ArgumentNullException("analyzedProperty"); throw new ArgumentNullException("analyzedProperty");
this.analyzedProperty = analyzedProperty;
if (analyzedProperty.GetMethod != null) if (analyzedProperty.GetMethod != null)
this.Children.Add(new AnalyzedPropertyAccessorTreeNode(analyzedProperty.GetMethod, "get")); this.Children.Add(new AnalyzedPropertyAccessorTreeNode(analyzedProperty.GetMethod, "get"));
@ -54,9 +51,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
return !MainWindow.Instance.CurrentLanguage.ShowMember(property.GetMethod ?? property.SetMethod); return !MainWindow.Instance.CurrentLanguage.ShowMember(property.GetMethod ?? property.SetMethod);
} }
class AnalyzedPropertyAccessorTreeNode : AnalyzedMethodTreeNode private class AnalyzedPropertyAccessorTreeNode : AnalyzedMethodTreeNode
{ {
string name; private readonly string name;
public AnalyzedPropertyAccessorTreeNode(MethodDefinition analyzedMethod, string name) public AnalyzedPropertyAccessorTreeNode(MethodDefinition analyzedMethod, string name)
: base(analyzedMethod) : base(analyzedMethod)

13
ILSpy/TreeNodes/Analyzer/AnalyzedPropertyOverridesTreeNode.cs

@ -28,10 +28,10 @@ using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{ {
class AnalyzedPropertyOverridesTreeNode : AnalyzerTreeNode internal sealed class AnalyzedPropertyOverridesTreeNode : AnalyzerTreeNode
{ {
readonly PropertyDefinition analyzedProperty; private readonly PropertyDefinition analyzedProperty;
readonly ThreadingSupport threading; private readonly ThreadingSupport threading;
public AnalyzedPropertyOverridesTreeNode(PropertyDefinition analyzedProperty) public AnalyzedPropertyOverridesTreeNode(PropertyDefinition analyzedProperty)
{ {
@ -67,19 +67,20 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
} }
} }
IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct) private IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct)
{ {
return FindReferences(MainWindow.Instance.CurrentAssemblyList.GetAssemblies(), ct); return FindReferences(MainWindow.Instance.CurrentAssemblyList.GetAssemblies(), ct);
} }
IEnumerable<SharpTreeNode> FindReferences(IEnumerable<LoadedAssembly> assemblies, CancellationToken ct) private IEnumerable<SharpTreeNode> FindReferences(IEnumerable<LoadedAssembly> assemblies, CancellationToken ct)
{ {
assemblies = assemblies.Where(asm => asm.AssemblyDefinition != null); assemblies = assemblies.Where(asm => asm.AssemblyDefinition != null);
// use parallelism only on the assembly level (avoid locks within Cecil) // use parallelism only on the assembly level (avoid locks within Cecil)
return assemblies.AsParallel().WithCancellation(ct).SelectMany((LoadedAssembly asm) => FindReferences(asm, ct)); return assemblies.AsParallel().WithCancellation(ct).SelectMany((LoadedAssembly asm) => FindReferences(asm, ct));
} }
IEnumerable<SharpTreeNode> FindReferences(LoadedAssembly asm, CancellationToken ct) private IEnumerable<SharpTreeNode> FindReferences(LoadedAssembly asm, CancellationToken ct)
{ {
string asmName = asm.AssemblyDefinition.Name.Name; string asmName = asm.AssemblyDefinition.Name.Name;
string name = analyzedProperty.Name; string name = analyzedProperty.Name;

10
ILSpy/TreeNodes/Analyzer/AnalyzedPropertyTreeNode.cs

@ -22,16 +22,16 @@ using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{ {
class AnalyzedPropertyTreeNode : AnalyzerTreeNode internal sealed class AnalyzedPropertyTreeNode : AnalyzerTreeNode
{ {
PropertyDefinition analyzedProperty; private readonly PropertyDefinition analyzedProperty;
bool isIndexer; private readonly bool isIndexer;
string prefix; private readonly string prefix;
public AnalyzedPropertyTreeNode(PropertyDefinition analyzedProperty, string prefix = "") public AnalyzedPropertyTreeNode(PropertyDefinition analyzedProperty, string prefix = "")
{ {
if (analyzedProperty == null) if (analyzedProperty == null)
throw new ArgumentNullException("analyzedMethod"); throw new ArgumentNullException("analyzedProperty");
this.isIndexer = analyzedProperty.IsIndexer(); this.isIndexer = analyzedProperty.IsIndexer();
this.analyzedProperty = analyzedProperty; this.analyzedProperty = analyzedProperty;
this.prefix = prefix; this.prefix = prefix;

20
ILSpy/TreeNodes/Analyzer/AnalyzedTypeExposedByTreeNode.cs

@ -24,11 +24,10 @@ using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{ {
class AnalyzedTypeExposedByTreeNode : AnalyzerTreeNode internal sealed class AnalyzedTypeExposedByTreeNode : AnalyzerTreeNode
{ {
TypeDefinition analyzedType; private readonly TypeDefinition analyzedType;
ThreadingSupport threading; private readonly ThreadingSupport threading;
bool IsSystemObject;
public AnalyzedTypeExposedByTreeNode(TypeDefinition analyzedType) public AnalyzedTypeExposedByTreeNode(TypeDefinition analyzedType)
{ {
@ -38,8 +37,6 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
this.analyzedType = analyzedType; this.analyzedType = analyzedType;
this.threading = new ThreadingSupport(); this.threading = new ThreadingSupport();
this.LazyLoading = true; this.LazyLoading = true;
this.IsSystemObject = (analyzedType.FullName == "System.Object");
} }
public override object Text public override object Text
@ -66,7 +63,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
} }
} }
IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct) private IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct)
{ {
ScopedWhereUsedScopeAnalyzer<SharpTreeNode> analyzer; ScopedWhereUsedScopeAnalyzer<SharpTreeNode> analyzer;
@ -74,7 +71,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
return analyzer.PerformAnalysis(ct); return analyzer.PerformAnalysis(ct);
} }
IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type) private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type)
{ {
if (analyzedType.IsEnum && type == analyzedType) if (analyzedType.IsEnum && type == analyzedType)
yield break; yield break;
@ -84,7 +81,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
foreach (FieldDefinition field in type.Fields) { foreach (FieldDefinition field in type.Fields) {
if (TypeIsExposedBy(field)) if (TypeIsExposedBy(field))
yield return new AnalyzedFieldNode(field); yield return new AnalyzedFieldTreeNode(field);
} }
foreach (PropertyDefinition property in type.Properties) { foreach (PropertyDefinition property in type.Properties) {
@ -165,14 +162,14 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
return false; return false;
} }
private bool IsPrivate(PropertyDefinition property) private static bool IsPrivate(PropertyDefinition property)
{ {
bool isGetterPublic = (property.GetMethod != null && !property.GetMethod.IsPrivate); bool isGetterPublic = (property.GetMethod != null && !property.GetMethod.IsPrivate);
bool isSetterPublic = (property.SetMethod != null && !property.SetMethod.IsPrivate); bool isSetterPublic = (property.SetMethod != null && !property.SetMethod.IsPrivate);
return !(isGetterPublic || isSetterPublic); return !(isGetterPublic || isSetterPublic);
} }
private bool IsPrivate(EventDefinition eventDef) private static bool IsPrivate(EventDefinition eventDef)
{ {
bool isAdderPublic = (eventDef.AddMethod != null && !eventDef.AddMethod.IsPrivate); bool isAdderPublic = (eventDef.AddMethod != null && !eventDef.AddMethod.IsPrivate);
bool isRemoverPublic = (eventDef.RemoveMethod != null && !eventDef.RemoveMethod.IsPrivate); bool isRemoverPublic = (eventDef.RemoveMethod != null && !eventDef.RemoveMethod.IsPrivate);
@ -183,6 +180,5 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{ {
return true; return true;
} }
} }
} }

36
ILSpy/TreeNodes/Analyzer/AnalyzedTypeExtensionMethodsTreeNode.cs

@ -25,11 +25,10 @@ using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{ {
class AnalyzedTypeExtensionMethodsTreeNode : AnalyzerTreeNode internal class AnalyzedTypeExtensionMethodsTreeNode : AnalyzerTreeNode
{ {
TypeDefinition analyzedType; private readonly TypeDefinition analyzedType;
ThreadingSupport threading; private readonly ThreadingSupport threading;
bool IsSystemObject;
public AnalyzedTypeExtensionMethodsTreeNode(TypeDefinition analyzedType) public AnalyzedTypeExtensionMethodsTreeNode(TypeDefinition analyzedType)
{ {
@ -39,8 +38,6 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
this.analyzedType = analyzedType; this.analyzedType = analyzedType;
this.threading = new ThreadingSupport(); this.threading = new ThreadingSupport();
this.LazyLoading = true; this.LazyLoading = true;
this.IsSystemObject = (analyzedType.FullName == "System.Object");
} }
public override object Text public override object Text
@ -67,7 +64,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
} }
} }
IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct) private IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct)
{ {
ScopedWhereUsedScopeAnalyzer<SharpTreeNode> analyzer; ScopedWhereUsedScopeAnalyzer<SharpTreeNode> analyzer;
@ -75,7 +72,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
return analyzer.PerformAnalysis(ct); return analyzer.PerformAnalysis(ct);
} }
IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type) private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type)
{ {
foreach (MethodDefinition method in type.Methods) { foreach (MethodDefinition method in type.Methods) {
if (method.IsStatic && method.HasCustomAttributes) { if (method.IsStatic && method.HasCustomAttributes) {
@ -88,32 +85,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
} }
} }
private bool TypeIsExposedBy(MethodDefinition method)
{
if (method.IsPrivate)
return false;
// exclude methods with 'semantics'. for example, property getters & setters.
if (method.SemanticsAttributes != MethodSemanticsAttributes.None)
return false;
if (method.ReturnType.Resolve() == analyzedType)
return true;
if (method.HasParameters) {
foreach (var parameter in method.Parameters) {
if (parameter.ParameterType.Resolve() == analyzedType)
return true;
}
}
return false;
}
public static bool CanShow(TypeDefinition type) public static bool CanShow(TypeDefinition type)
{ {
return !(type.IsEnum); return !(type.IsEnum);
} }
} }
} }

17
ILSpy/TreeNodes/Analyzer/AnalyzedTypeInstantiationsTreeNode.cs

@ -27,11 +27,11 @@ using Mono.Cecil.Cil;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{ {
class AnalyzedTypeInstantiationsTreeNode : AnalyzerTreeNode internal sealed class AnalyzedTypeInstantiationsTreeNode : AnalyzerTreeNode
{ {
TypeDefinition analyzedType; private readonly TypeDefinition analyzedType;
ThreadingSupport threading; private readonly ThreadingSupport threading;
bool IsSystemObject; private readonly bool isSystemObject;
public AnalyzedTypeInstantiationsTreeNode(TypeDefinition analyzedType) public AnalyzedTypeInstantiationsTreeNode(TypeDefinition analyzedType)
{ {
@ -42,7 +42,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
this.threading = new ThreadingSupport(); this.threading = new ThreadingSupport();
this.LazyLoading = true; this.LazyLoading = true;
this.IsSystemObject = (analyzedType.FullName == "System.Object"); this.isSystemObject = (analyzedType.FullName == "System.Object");
} }
public override object Text public override object Text
@ -69,7 +69,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
} }
} }
IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct) private IEnumerable<SharpTreeNode> FetchChildren(CancellationToken ct)
{ {
ScopedWhereUsedScopeAnalyzer<SharpTreeNode> analyzer; ScopedWhereUsedScopeAnalyzer<SharpTreeNode> analyzer;
@ -77,7 +77,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
return analyzer.PerformAnalysis(ct); return analyzer.PerformAnalysis(ct);
} }
IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type) private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type)
{ {
foreach (MethodDefinition method in type.Methods) { foreach (MethodDefinition method in type.Methods) {
bool found = false; bool found = false;
@ -87,7 +87,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
// ignore chained constructors // ignore chained constructors
// (since object is the root of everything, we can short circuit the test in this case) // (since object is the root of everything, we can short circuit the test in this case)
if (method.Name == ".ctor" && if (method.Name == ".ctor" &&
(IsSystemObject || analyzedType == type || TypesHierarchyHelpers.IsBaseType(analyzedType, type, false))) (isSystemObject || analyzedType == type || TypesHierarchyHelpers.IsBaseType(analyzedType, type, false)))
continue; continue;
foreach (Instruction instr in method.Body.Instructions) { foreach (Instruction instr in method.Body.Instructions) {
@ -114,6 +114,5 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
} }
return false; return false;
} }
} }
} }

4
ILSpy/TreeNodes/Analyzer/AnalyzedTypeTreeNode.cs

@ -21,9 +21,9 @@ using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{ {
class AnalyzedTypeTreeNode : AnalyzerTreeNode, IMemberTreeNode internal class AnalyzedTypeTreeNode : AnalyzerTreeNode, IMemberTreeNode
{ {
TypeDefinition analyzedType; private readonly TypeDefinition analyzedType;
public AnalyzedTypeTreeNode(TypeDefinition analyzedType) public AnalyzedTypeTreeNode(TypeDefinition analyzedType)
{ {

2
ILSpy/TreeNodes/Analyzer/AnalyzerTreeNode.cs

@ -24,7 +24,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{ {
public class AnalyzerTreeNode : SharpTreeNode public class AnalyzerTreeNode : SharpTreeNode
{ {
Language language; private Language language;
public Language Language public Language Language
{ {

2
ILSpy/TreeNodes/Analyzer/Helpers.cs

@ -24,7 +24,7 @@ using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{ {
static class Helpers internal static class Helpers
{ {
public static bool IsReferencedBy(TypeDefinition type, TypeReference typeRef) public static bool IsReferencedBy(TypeDefinition type, TypeReference typeRef)
{ {

18
ILSpy/TreeNodes/Analyzer/ScopedWhereUsedAnalyzer.cs

@ -108,7 +108,6 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
return FindReferencesInTypeScope(ct); return FindReferencesInTypeScope(ct);
} }
if (memberAccessibility == Accessibility.Internal || if (memberAccessibility == Accessibility.Internal ||
memberAccessibility == Accessibility.FamilyAndInternal || memberAccessibility == Accessibility.FamilyAndInternal ||
typeAccessibility == Accessibility.Internal || typeAccessibility == Accessibility.Internal ||
@ -136,7 +135,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
} }
} }
private Accessibility GetNestedTypeAccessibility(TypeDefinition type) private static Accessibility GetNestedTypeAccessibility(TypeDefinition type)
{ {
Accessibility result; Accessibility result;
switch (type.Attributes & TypeAttributes.VisibilityMask) { switch (type.Attributes & TypeAttributes.VisibilityMask) {
@ -177,22 +176,23 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
Public Public
} }
private IEnumerable<T> FindReferencesInAssemblyAndFriends(CancellationToken ct)
IEnumerable<T> FindReferencesInAssemblyAndFriends(CancellationToken ct)
{ {
var assemblies = GetAssemblyAndAnyFriends(assemblyScope, ct); var assemblies = GetAssemblyAndAnyFriends(assemblyScope, ct);
// use parallelism only on the assembly level (avoid locks within Cecil) // use parallelism only on the assembly level (avoid locks within Cecil)
return assemblies.AsParallel().WithCancellation(ct).SelectMany((AssemblyDefinition a) => FindReferencesInAssembly(a, ct)); return assemblies.AsParallel().WithCancellation(ct).SelectMany((AssemblyDefinition a) => FindReferencesInAssembly(a, ct));
} }
IEnumerable<T> FindReferencesGlobal(CancellationToken ct) private IEnumerable<T> FindReferencesGlobal(CancellationToken ct)
{ {
var assemblies = GetReferencingAssemblies(assemblyScope, ct); var assemblies = GetReferencingAssemblies(assemblyScope, ct);
// use parallelism only on the assembly level (avoid locks within Cecil) // use parallelism only on the assembly level (avoid locks within Cecil)
return assemblies.AsParallel().WithCancellation(ct).SelectMany((AssemblyDefinition asm) => FindReferencesInAssembly(asm, ct)); return assemblies.AsParallel().WithCancellation(ct).SelectMany((AssemblyDefinition asm) => FindReferencesInAssembly(asm, ct));
} }
IEnumerable<T> FindReferencesInAssembly(AssemblyDefinition asm, CancellationToken ct) private IEnumerable<T> FindReferencesInAssembly(AssemblyDefinition asm, CancellationToken ct)
{ {
foreach (TypeDefinition type in TreeTraversal.PreOrder(asm.MainModule.Types, t => t.NestedTypes)) { foreach (TypeDefinition type in TreeTraversal.PreOrder(asm.MainModule.Types, t => t.NestedTypes)) {
ct.ThrowIfCancellationRequested(); ct.ThrowIfCancellationRequested();
@ -203,7 +203,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
} }
} }
IEnumerable<T> FindReferencesInTypeScope(CancellationToken ct) private IEnumerable<T> FindReferencesInTypeScope(CancellationToken ct)
{ {
foreach (TypeDefinition type in TreeTraversal.PreOrder(typeScope, t => t.NestedTypes)) { foreach (TypeDefinition type in TreeTraversal.PreOrder(typeScope, t => t.NestedTypes)) {
ct.ThrowIfCancellationRequested(); ct.ThrowIfCancellationRequested();
@ -214,7 +214,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
} }
} }
IEnumerable<AssemblyDefinition> GetReferencingAssemblies(AssemblyDefinition asm, CancellationToken ct) private IEnumerable<AssemblyDefinition> GetReferencingAssemblies(AssemblyDefinition asm, CancellationToken ct)
{ {
yield return asm; yield return asm;
@ -236,7 +236,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
} }
} }
IEnumerable<AssemblyDefinition> GetAssemblyAndAnyFriends(AssemblyDefinition asm, CancellationToken ct) private IEnumerable<AssemblyDefinition> GetAssemblyAndAnyFriends(AssemblyDefinition asm, CancellationToken ct)
{ {
yield return asm; yield return asm;

24
ILSpy/TreeNodes/AssemblyTreeNode.cs

@ -41,7 +41,6 @@ namespace ICSharpCode.ILSpy.TreeNodes
public sealed class AssemblyTreeNode : ILSpyTreeNode public sealed class AssemblyTreeNode : ILSpyTreeNode
{ {
readonly LoadedAssembly assembly; readonly LoadedAssembly assembly;
readonly List<TypeTreeNode> classes = new List<TypeTreeNode>();
readonly Dictionary<string, NamespaceTreeNode> namespaces = new Dictionary<string, NamespaceTreeNode>(); readonly Dictionary<string, NamespaceTreeNode> namespaces = new Dictionary<string, NamespaceTreeNode>();
public AssemblyTreeNode(LoadedAssembly assembly) public AssemblyTreeNode(LoadedAssembly assembly)
@ -56,20 +55,25 @@ namespace ICSharpCode.ILSpy.TreeNodes
this.LazyLoading = true; this.LazyLoading = true;
} }
public AssemblyList AssemblyList { public AssemblyList AssemblyList
{
get { return assembly.AssemblyList; } get { return assembly.AssemblyList; }
} }
public LoadedAssembly LoadedAssembly { public LoadedAssembly LoadedAssembly
{
get { return assembly; } get { return assembly; }
} }
public override object Text { public override object Text
{
get { return HighlightSearchMatch(assembly.ShortName); } get { return HighlightSearchMatch(assembly.ShortName); }
} }
public override object Icon { public override object Icon
get { {
get
{
if (assembly.IsLoaded) { if (assembly.IsLoaded) {
return assembly.HasLoadError ? Images.AssemblyWarning : Images.Assembly; return assembly.HasLoadError ? Images.AssemblyWarning : Images.Assembly;
} else { } else {
@ -78,7 +82,8 @@ namespace ICSharpCode.ILSpy.TreeNodes
} }
} }
public override bool ShowExpander { public override bool ShowExpander
{
get { return !assembly.HasLoadError; } get { return !assembly.HasLoadError; }
} }
@ -90,7 +95,8 @@ namespace ICSharpCode.ILSpy.TreeNodes
if (assemblyTask.IsFaulted) { if (assemblyTask.IsFaulted) {
RaisePropertyChanged("ShowExpander"); // cannot expand assemblies with load error RaisePropertyChanged("ShowExpander"); // cannot expand assemblies with load error
// observe the exception so that the Task's finalizer doesn't re-throw it // observe the exception so that the Task's finalizer doesn't re-throw it
try { assemblyTask.Wait(); } catch (AggregateException) {} try { assemblyTask.Wait(); }
catch (AggregateException) { }
} else { } else {
RaisePropertyChanged("Text"); // shortname might have changed RaisePropertyChanged("Text"); // shortname might have changed
} }
@ -215,7 +221,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
} }
} }
} }
textView.SaveToDisk(language, new[]{this}, options, dlg.FileName); textView.SaveToDisk(language, new[] { this }, options, dlg.FileName);
} }
return true; return true;
} }

26
ILSpy/TreeNodes/ResourceEntryNode.cs

@ -22,17 +22,25 @@ namespace ICSharpCode.ILSpy.TreeNodes
/// </summary> /// </summary>
public class ResourceEntryNode : ILSpyTreeNode public class ResourceEntryNode : ILSpyTreeNode
{ {
protected readonly string key; private readonly string key;
protected readonly Stream data; private readonly Stream data;
public override object Text { public override object Text
{
get { return key.ToString(); } get { return key.ToString(); }
} }
public override object Icon { public override object Icon
{
get { return Images.Resource; } get { return Images.Resource; }
} }
protected Stream Data
{
get { return data; }
}
public ResourceEntryNode(string key, Stream data) public ResourceEntryNode(string key, Stream data)
{ {
if (key == null) if (key == null)
@ -99,7 +107,8 @@ namespace ICSharpCode.ILSpy.TreeNodes
sealed class ImageResourceEntryNode : ResourceEntryNode sealed class ImageResourceEntryNode : ResourceEntryNode
{ {
public ImageResourceEntryNode(string key, Stream data) : base(key, data) public ImageResourceEntryNode(string key, Stream data)
: base(key, data)
{ {
} }
@ -112,17 +121,18 @@ namespace ICSharpCode.ILSpy.TreeNodes
{ {
try { try {
AvalonEditTextOutput output = new AvalonEditTextOutput(); AvalonEditTextOutput output = new AvalonEditTextOutput();
data.Position = 0; Data.Position = 0;
BitmapImage image = new BitmapImage(); BitmapImage image = new BitmapImage();
image.BeginInit(); image.BeginInit();
image.StreamSource = data; image.StreamSource = Data;
image.EndInit(); image.EndInit();
output.AddUIElement(() => new Image { Source = image }); output.AddUIElement(() => new Image { Source = image });
output.WriteLine(); output.WriteLine();
output.AddButton(Images.Save, "Save", delegate { Save(null); }); output.AddButton(Images.Save, "Save", delegate { Save(null); });
textView.Show(output, null); textView.Show(output, null);
return true; return true;
} catch (Exception) { }
catch (Exception) {
return false; return false;
} }
} }

2
ILSpy/TreeNodes/XamlResourceNode.cs

@ -48,7 +48,7 @@ namespace ICSharpCode.ILSpy.Xaml
try { try {
// cache read XAML because stream will be closed after first read // cache read XAML because stream will be closed after first read
if (xaml == null) { if (xaml == null) {
using (var reader = new StreamReader(data)) { using (var reader = new StreamReader(Data)) {
xaml = reader.ReadToEnd(); xaml = reader.ReadToEnd();
} }
} }

Loading…
Cancel
Save