Skip to content

Commit

Permalink
ExportedTypes, TypeReference and MemberReferences: Use UnknownType/Fa…
Browse files Browse the repository at this point in the history
…keMember for pretty-printing of signatures in TreeView.
  • Loading branch information
siegfriedpammer committed Mar 16, 2024
1 parent 6322442 commit f93c478
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 23 deletions.
7 changes: 4 additions & 3 deletions ILSpy/TreeNodes/AssemblyReferenceReferencedTypesTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;

namespace ICSharpCode.ILSpy.TreeNodes
{
Expand All @@ -28,10 +29,10 @@ namespace ICSharpCode.ILSpy.TreeNodes
/// </summary>
public sealed class AssemblyReferenceReferencedTypesTreeNode : ILSpyTreeNode
{
private readonly PEFile module;
private readonly AssemblyReference r;
readonly MetadataModule module;
readonly AssemblyReference r;

public AssemblyReferenceReferencedTypesTreeNode(PEFile module, AssemblyReference r)
public AssemblyReferenceReferencedTypesTreeNode(MetadataModule module, AssemblyReference r)
{
this.module = module ?? throw new ArgumentNullException(nameof(module));
this.r = r ?? throw new ArgumentNullException(nameof(r));
Expand Down
8 changes: 5 additions & 3 deletions ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;

namespace ICSharpCode.ILSpy.TreeNodes
{
Expand All @@ -29,11 +30,11 @@ namespace ICSharpCode.ILSpy.TreeNodes
/// </summary>
public sealed class AssemblyReferenceTreeNode : ILSpyTreeNode
{
readonly PEFile module;
readonly MetadataModule module;
readonly AssemblyReference r;
readonly AssemblyTreeNode parentAssembly;

public AssemblyReferenceTreeNode(PEFile module, AssemblyReference r, AssemblyTreeNode parentAssembly)
public AssemblyReferenceTreeNode(MetadataModule module, AssemblyReference r, AssemblyTreeNode parentAssembly)
{
this.module = module ?? throw new ArgumentNullException(nameof(module));
this.r = r ?? throw new ArgumentNullException(nameof(r));
Expand Down Expand Up @@ -83,8 +84,9 @@ protected override void LoadChildren()
var referencedModule = resolver.Resolve(r);
if (referencedModule != null)
{
var module = (MetadataModule)referencedModule.GetTypeSystemWithCurrentOptionsOrNull().MainModule;
foreach (var childRef in referencedModule.AssemblyReferences)
this.Children.Add(new AssemblyReferenceTreeNode(referencedModule, childRef, parentAssembly));
this.Children.Add(new AssemblyReferenceTreeNode(module, childRef, parentAssembly));
}
}

Expand Down
12 changes: 7 additions & 5 deletions ILSpy/TreeNodes/ExportedTypeTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,21 @@ namespace ICSharpCode.ILSpy.TreeNodes
/// </summary>
public sealed class ExportedTypeTreeNode : ILSpyTreeNode
{
readonly PEFile module;
private readonly ExportedTypeMetadata r;
readonly MetadataModule module;
readonly ExportedTypeMetadata r;
readonly IType resolvedType;

public ExportedTypeTreeNode(PEFile module, ExportedTypeMetadata r)
public ExportedTypeTreeNode(MetadataModule module, ExportedTypeMetadata r)
{
this.module = module ?? throw new ArgumentNullException(nameof(module));
this.r = r ?? throw new ArgumentNullException(nameof(r));
this.resolvedType = module.ResolveType(r.Handle, default);

this.LazyLoading = true;
}

public override object Text
=> Language.GetEntityName(module, r.Handle, fullName: true, omitGenerics: false) + GetSuffixString(r.Handle);
=> Language.TypeToString(resolvedType, includeNamespace: true) + GetSuffixString(r.Handle);

public override object Icon => Images.Library;

Expand All @@ -55,7 +57,7 @@ protected override void LoadChildren()

public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
language.WriteCommentLine(output, $"{Language.GetEntityName(module, r.Handle, fullName: true, omitGenerics: false)} (Exported, IsForwarder: {r.IsForwarder}, Attributes: {r.Attributes})");
language.WriteCommentLine(output, $"{Language.TypeToString(resolvedType, includeNamespace: true)} (Exported, IsForwarder: {r.IsForwarder}, Attributes: {(int)r.Attributes:X8})");
}
}
}
19 changes: 13 additions & 6 deletions ILSpy/TreeNodes/MemberReferenceTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;

namespace ICSharpCode.ILSpy.TreeNodes
{
Expand All @@ -31,30 +32,36 @@ namespace ICSharpCode.ILSpy.TreeNodes
/// </summary>
public sealed class MemberReferenceTreeNode : ILSpyTreeNode
{
readonly PEFile module;
private readonly MemberReferenceMetadata r;
readonly MetadataModule module;
readonly MemberReferenceMetadata r;
readonly IMember resolvedMember;

public MemberReferenceTreeNode(PEFile module, MemberReferenceMetadata r)
public MemberReferenceTreeNode(MetadataModule module, MemberReferenceMetadata r)
{
this.module = module ?? throw new ArgumentNullException(nameof(module));
this.r = r;
this.resolvedMember = r.MemberReferenceKind switch {
MemberReferenceKind.Method => module.ResolveMethod(r.Handle, default),
MemberReferenceKind.Field => (IMember)module.ResolveEntity(r.Handle),
_ => throw new NotSupportedException(),
};
}

public override object Text => r.Name + GetSuffixString(r.Handle);
public override object Text => Signature + GetSuffixString(r.Handle);

public override object Icon => r.MemberReferenceKind switch {
MemberReferenceKind.Method => Images.Method,
MemberReferenceKind.Field => Images.Field,
_ => Images.Class,
};

public string Signature => Language.GetEntityName(module, r.Handle, fullName: true, omitGenerics: false);
public string Signature => resolvedMember is IMethod m ? Language.MethodToString(m, false, false, false) : Language.FieldToString((IField)resolvedMember, false, false, false);

public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
language.WriteCommentLine(output, Signature);
}

public override object ToolTip => Signature;
public override object ToolTip => Language.GetRichTextTooltip(resolvedMember);
}
}
4 changes: 3 additions & 1 deletion ILSpy/TreeNodes/ReferenceFolderTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpy.Properties;

namespace ICSharpCode.ILSpy.TreeNodes
Expand All @@ -48,8 +49,9 @@ public ReferenceFolderTreeNode(PEFile module, AssemblyTreeNode parentAssembly)
protected override void LoadChildren()
{
var metadata = module.Metadata;
var metadataModule = (MetadataModule)module.GetTypeSystemWithCurrentOptionsOrNull().MainModule;
foreach (var r in module.AssemblyReferences.OrderBy(r => r.Name))
this.Children.Add(new AssemblyReferenceTreeNode(module, r, parentAssembly));
this.Children.Add(new AssemblyReferenceTreeNode(metadataModule, r, parentAssembly));
foreach (var r in metadata.GetModuleReferences().OrderBy(r => metadata.GetString(metadata.GetModuleReference(r).Name)))
this.Children.Add(new ModuleReferenceTreeNode(parentAssembly, r, module));
}
Expand Down
13 changes: 8 additions & 5 deletions ILSpy/TreeNodes/TypeReferenceTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;

namespace ICSharpCode.ILSpy.TreeNodes
{
Expand All @@ -28,19 +29,21 @@ namespace ICSharpCode.ILSpy.TreeNodes
/// </summary>
public sealed class TypeReferenceTreeNode : ILSpyTreeNode
{
readonly PEFile module;
private readonly TypeReferenceMetadata r;
readonly MetadataModule module;
readonly TypeReferenceMetadata r;
readonly IType resolvedType;

public TypeReferenceTreeNode(PEFile module, TypeReferenceMetadata r)
public TypeReferenceTreeNode(MetadataModule module, TypeReferenceMetadata r)
{
this.module = module ?? throw new ArgumentNullException(nameof(module));
this.r = r ?? throw new ArgumentNullException(nameof(r));
this.resolvedType = module.ResolveType(r.Handle, default);

this.LazyLoading = true;
}

public override object Text
=> Language.GetEntityName(module, r.Handle, fullName: true, omitGenerics: false) + GetSuffixString(r.Handle);
=> Language.TypeToString(resolvedType, includeNamespace: false) + GetSuffixString(r.Handle);

public override object Icon => Images.Class;

Expand All @@ -57,7 +60,7 @@ protected override void LoadChildren()

public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
language.WriteCommentLine(output, $"{Language.GetEntityName(module, r.Handle, fullName: true, omitGenerics: false)}");
language.WriteCommentLine(output, Language.TypeToString(resolvedType, includeNamespace: true));
EnsureLazyChildren();
foreach (ILSpyTreeNode child in Children)
{
Expand Down

0 comments on commit f93c478

Please sign in to comment.