Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ namespace dnSpy.Contracts.Documents.TreeView {
public readonly struct NodeFormatter {
static bool IsExe(ModuleDef? mod) => mod is not null && (mod.Characteristics & Characteristics.Dll) == 0;
static bool IsExe(IPEImage? peImage) => peImage is not null && (peImage.ImageNTHeaders.FileHeader.Characteristics & Characteristics.Dll) == 0;
static string? GetDisplayName(IDecompiler decompiler, IMemberRef member) => (decompiler as IDecompilerMemberNameProvider)?.GetDisplayName(member);
static void WriteDisplayName(ITextColorWriter output, IDecompiler decompiler, IMemberRef member, object color, string metadataName) =>
output.Write(color, NameUtilities.CleanIdentifier(GetDisplayName(decompiler, member) ?? metadataName));

static string GetFilename(IDsDocument document) {
string? filename = null;
Expand Down Expand Up @@ -197,7 +200,7 @@ public void Write(ITextColorWriter output, IDecompiler decompiler, ITypeDefOrRef
/// <param name="event">Event</param>
/// <param name="showToken">true to write tokens</param>
public void Write(ITextColorWriter output, IDecompiler decompiler, EventDef @event, bool showToken) {
output.Write(decompiler.MetadataTextColorProvider.GetColor(@event), NameUtilities.CleanIdentifier(@event.Name));
WriteDisplayName(output, decompiler, @event, decompiler.MetadataTextColorProvider.GetColor(@event), @event.Name);
output.WriteSpace();
output.Write(BoxedTextColor.Punctuation, ":");
output.WriteSpace();
Expand Down Expand Up @@ -239,7 +242,7 @@ public void Write(ITextColorWriter output, IDecompiler decompiler, PropertyDef p
/// <param name="field">Field</param>
/// <param name="showToken">true to write tokens</param>
public void WriteField(ITextColorWriter output, IDecompiler decompiler, IField field, bool showToken) {
output.Write(decompiler.MetadataTextColorProvider.GetColor(field), NameUtilities.CleanIdentifier(field.Name));
WriteDisplayName(output, decompiler, field, decompiler.MetadataTextColorProvider.GetColor(field), field.Name);
output.WriteSpace();
output.Write(BoxedTextColor.Punctuation, ":");
output.WriteSpace();
Expand Down Expand Up @@ -270,7 +273,7 @@ void Write(ITextColorWriter output, IDecompiler decompiler, MethodDef? md, IMeth
if (name == ".ctor")
output.Write(decompiler.MetadataTextColorProvider.GetColor(method.DeclaringType), NameUtilities.CleanIdentifier(method.DeclaringType.Name));
else
output.Write(decompiler.MetadataTextColorProvider.GetColor(method), NameUtilities.CleanIdentifier(name));
WriteDisplayName(output, decompiler, method, decompiler.MetadataTextColorProvider.GetColor(method), name);

if (showGenericParams) {
if (m is MethodSpec ms && ms.GenericInstMethodSig is GenericInstMethodSig gis) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright (C) 2026 geocine

This file is part of dnSpy

dnSpy is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

dnSpy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with dnSpy. If not, see <http://www.gnu.org/licenses/>.
*/

using dnlib.DotNet;

namespace dnSpy.Contracts.Decompiler {
/// <summary>
/// Optional member display name provider used by UI formatters outside normal decompiler output.
/// </summary>
public interface IDecompilerMemberNameProvider {
/// <summary>
/// Returns a custom display name for <paramref name="member"/>, or <c>null</c> to use its metadata name.
/// </summary>
/// <param name="member">Member reference</param>
/// <returns></returns>
string? GetDisplayName(IMemberRef member);
}
}
Loading