-
-
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.
Merge pull request #3092 from fowl2/assemblyUsedBy
add "Referenced Types" under References
- Loading branch information
Showing
22 changed files
with
1,010 additions
and
48 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
103 changes: 103 additions & 0 deletions
103
ICSharpCode.Decompiler/Metadata/ExportedTypeMetadata.cs
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,103 @@ | ||
// 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 | ||
/// <summary> | ||
/// Convenience wrapper for <see cref="ExportedType"/> and <see cref="ExportedTypeHandle"/>. | ||
/// </summary> | ||
public sealed class ExportedTypeMetadata | ||
{ | ||
readonly 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<ExportedTypeMetadata> exportedTypes; | ||
public ImmutableArray<ExportedTypeMetadata> ExportedTypes { | ||
get { | ||
var value = exportedTypes; | ||
if (value.IsDefault) | ||
{ | ||
value = Metadata.ExportedTypes | ||
.Select(r => new ExportedTypeMetadata(Metadata, r)) | ||
.Where(r => r.Implementation == Handle) | ||
.OrderBy(r => r.Namespace) | ||
.ThenBy(r => r.Name) | ||
.ToImmutableArray(); | ||
exportedTypes = value; | ||
} | ||
return value; | ||
} | ||
} | ||
|
||
public ExportedTypeMetadata(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 | ||
} |
69 changes: 69 additions & 0 deletions
69
ICSharpCode.Decompiler/Metadata/MemberReferenceMetadata.cs
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,69 @@ | ||
// 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.Reflection.Metadata; | ||
|
||
namespace ICSharpCode.Decompiler.Metadata | ||
{ | ||
#if !VSADDIN | ||
/// <summary> | ||
/// Convenience wrapper for <see cref="MemberReference"/> and <see cref="MemberReferenceHandle"/>. | ||
/// </summary> | ||
public sealed class MemberReferenceMetadata | ||
{ | ||
readonly MemberReference entry; | ||
|
||
public MetadataReader Metadata { get; } | ||
public MemberReferenceHandle Handle { get; } | ||
|
||
string? name; | ||
|
||
public string Name { | ||
get { | ||
try | ||
{ | ||
return name ??= Metadata.GetString(entry.Name); | ||
} | ||
catch (BadImageFormatException) | ||
{ | ||
return name = $"MR:{Handle}"; | ||
} | ||
} | ||
} | ||
|
||
public EntityHandle Parent => entry.Parent; | ||
|
||
public MemberReferenceKind MemberReferenceKind => entry.GetKind(); | ||
|
||
public MemberReferenceMetadata(MetadataReader metadata, MemberReferenceHandle handle) | ||
{ | ||
Metadata = metadata ?? throw new ArgumentNullException(nameof(metadata)); | ||
if (handle.IsNil) | ||
throw new ArgumentNullException(nameof(handle)); | ||
Handle = handle; | ||
entry = metadata.GetMemberReference(handle); | ||
} | ||
|
||
public override string ToString() | ||
=> Name; | ||
} | ||
#endif | ||
} |
132 changes: 132 additions & 0 deletions
132
ICSharpCode.Decompiler/Metadata/ModuleReferenceMetadata.cs
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,132 @@ | ||
// 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 class ModuleReferenceMetadata /* : IModuleReference*/ | ||
{ | ||
readonly ModuleReference entry; | ||
|
||
public MetadataReader Metadata { get; } | ||
public ModuleReferenceHandle Handle { get; } | ||
|
||
string? name; | ||
public string Name { | ||
get { | ||
if (name == null) | ||
{ | ||
try | ||
{ | ||
name = Metadata.GetString(entry.Name); | ||
} | ||
catch (BadImageFormatException) | ||
{ | ||
name = $"AR:{Handle}"; | ||
} | ||
} | ||
return name; | ||
} | ||
} | ||
|
||
ImmutableArray<CustomAttribute> attributes; | ||
public ImmutableArray<CustomAttribute> Attributes { | ||
get { | ||
var value = attributes; | ||
if (value.IsDefault) | ||
{ | ||
value = entry.GetCustomAttributes().Select(Metadata.GetCustomAttribute).ToImmutableArray(); | ||
attributes = value; | ||
} | ||
return value; | ||
} | ||
} | ||
|
||
ImmutableArray<TypeReferenceMetadata> typeReferences; | ||
public ImmutableArray<TypeReferenceMetadata> TypeReferences { | ||
get { | ||
var value = typeReferences; | ||
if (value.IsDefault) | ||
{ | ||
value = Metadata.TypeReferences | ||
.Select(r => new TypeReferenceMetadata(Metadata, r)) | ||
.Where(r => r.ResolutionScope == Handle) | ||
.OrderBy(r => r.Namespace) | ||
.ThenBy(r => r.Name) | ||
.ToImmutableArray(); | ||
typeReferences = value; | ||
} | ||
return value; | ||
} | ||
} | ||
|
||
ImmutableArray<ExportedTypeMetadata> exportedTypes; | ||
public ImmutableArray<ExportedTypeMetadata> ExportedTypes { | ||
get { | ||
var value = exportedTypes; | ||
if (value.IsDefault) | ||
{ | ||
value = Metadata.ExportedTypes | ||
.Select(r => new ExportedTypeMetadata(Metadata, r)) | ||
.Where(r => r.Implementation == Handle) | ||
.OrderBy(r => r.Namespace) | ||
.ThenBy(r => r.Name) | ||
.ToImmutableArray(); | ||
exportedTypes = value; | ||
} | ||
return value; | ||
} | ||
} | ||
|
||
public ModuleReferenceMetadata(MetadataReader metadata, ModuleReferenceHandle handle) | ||
{ | ||
if (metadata == null) | ||
throw new ArgumentNullException(nameof(metadata)); | ||
if (handle.IsNil) | ||
throw new ArgumentNullException(nameof(handle)); | ||
Metadata = metadata; | ||
Handle = handle; | ||
entry = metadata.GetModuleReference(handle); | ||
} | ||
|
||
public ModuleReferenceMetadata(PEFile module, ModuleReferenceHandle handle) | ||
{ | ||
if (module == null) | ||
throw new ArgumentNullException(nameof(module)); | ||
if (handle.IsNil) | ||
throw new ArgumentNullException(nameof(handle)); | ||
Metadata = module.Metadata; | ||
Handle = handle; | ||
entry = Metadata.GetModuleReference(handle); | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return 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
Oops, something went wrong.