-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ExportedType, nested TypeReferences
- Loading branch information
James May
committed
Oct 5, 2023
1 parent
d11b4a1
commit 55b100e
Showing
12 changed files
with
223 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright (c) 2023 James May | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this | ||
// software and associated documentation files (the "Software"), to deal in the Software | ||
// without restriction, including without limitation the rights to use, copy, modify, merge, | ||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons | ||
// to whom the Software is furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all copies or | ||
// substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | ||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
// DEALINGS IN THE SOFTWARE. | ||
|
||
#nullable enable | ||
|
||
using System; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Reflection.Metadata; | ||
|
||
namespace ICSharpCode.Decompiler.Metadata | ||
{ | ||
#if !VSADDIN | ||
public sealed class ExportedType | ||
{ | ||
readonly System.Reflection.Metadata.ExportedType entry; | ||
|
||
public MetadataReader Metadata { get; } | ||
public ExportedTypeHandle Handle { get; } | ||
|
||
string? name; | ||
public string Name { | ||
get { | ||
try | ||
{ | ||
return name ??= Metadata.GetString(entry.Name); | ||
} | ||
catch (BadImageFormatException) | ||
{ | ||
return name = $"ET:{Handle}"; | ||
} | ||
} | ||
} | ||
|
||
string? @namespace; | ||
public string Namespace { | ||
get { | ||
try | ||
{ | ||
return @namespace ??= Metadata.GetString(entry.Namespace); | ||
} | ||
catch (BadImageFormatException) | ||
{ | ||
return @namespace = $"namespace(ET:{Handle})"; | ||
} | ||
} | ||
} | ||
|
||
public EntityHandle Implementation => entry.Implementation; | ||
public TypeAttributes Attributes => entry.Attributes; | ||
public bool IsForwarder => entry.IsForwarder; | ||
public NamespaceDefinition NamespaceDefinition => Metadata.GetNamespaceDefinition(entry.NamespaceDefinition); | ||
|
||
ImmutableArray<ExportedType> exportedTypes; | ||
public ImmutableArray<ExportedType> ExportedTypes { | ||
get { | ||
var value = exportedTypes; | ||
if (value.IsDefault) | ||
{ | ||
value = Metadata.ExportedTypes | ||
.Select(r => new ExportedType(Metadata, r)) | ||
.Where(r => r.Implementation == Handle) | ||
.OrderBy(r => r.Namespace) | ||
.ThenBy(r => r.Name) | ||
.ToImmutableArray(); | ||
exportedTypes = value; | ||
} | ||
return value; | ||
} | ||
} | ||
|
||
public ExportedType(MetadataReader metadata, ExportedTypeHandle handle) | ||
{ | ||
Metadata = metadata ?? throw new ArgumentNullException(nameof(metadata)); | ||
if (handle.IsNil) | ||
throw new ArgumentNullException(nameof(handle)); | ||
Handle = handle; | ||
entry = metadata.GetExportedType(handle); | ||
} | ||
|
||
public override string ToString() => $"{Namespace}::{Name}"; | ||
} | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) 2023 James May | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this | ||
// software and associated documentation files (the "Software"), to deal in the Software | ||
// without restriction, including without limitation the rights to use, copy, modify, merge, | ||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons | ||
// to whom the Software is furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all copies or | ||
// substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | ||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
// DEALINGS IN THE SOFTWARE. | ||
|
||
using System; | ||
|
||
using ICSharpCode.Decompiler; | ||
using ICSharpCode.Decompiler.Metadata; | ||
|
||
using ExportedType = ICSharpCode.Decompiler.Metadata.ExportedType; | ||
|
||
namespace ICSharpCode.ILSpy.TreeNodes | ||
{ | ||
/// <summary> | ||
/// exported type within assembly reference list. | ||
/// </summary> | ||
public sealed class ExportedTypeTreeNode : ILSpyTreeNode | ||
{ | ||
readonly PEFile module; | ||
private readonly ExportedType r; | ||
|
||
public ExportedTypeTreeNode(PEFile module, ExportedType r) | ||
{ | ||
this.module = module ?? throw new ArgumentNullException(nameof(module)); | ||
this.r = r ?? throw new ArgumentNullException(nameof(r)); | ||
|
||
this.LazyLoading = true; | ||
} | ||
|
||
public override object Text | ||
=> Language.GetEntityName(module, r.Handle, fullName: true, omitGenerics: false) + GetSuffixString(r.Handle); | ||
|
||
public override object Icon => Images.Library; | ||
|
||
protected override void LoadChildren() | ||
{ | ||
foreach (var exportedType in r.ExportedTypes) | ||
this.Children.Add(new ExportedTypeTreeNode(module, exportedType)); | ||
} | ||
|
||
public override bool ShowExpander => !r.ExportedTypes.IsEmpty; | ||
|
||
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})"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters