Browse Source

Widen enums to underlying int when formatting Copy Row text

Enum.ToString rejects multi-character format specs like "X8", so a
flags column raised FormatException out of Copy Row. Mirror what
HexFormatConverter does at bind-time: widen the value to its
underlying integer (Convert.ChangeType + GetTypeCode) before calling
IFormattable.ToString.

Assisted-by: Claude:claude-opus-4-7:Claude Code
pull/3755/head
Siegfried Pammer 2 months ago
parent
commit
64700f44fa
  1. 14
      ILSpy/Views/MetadataTablePage.axaml.cs

14
ILSpy/Views/MetadataTablePage.axaml.cs

@ -216,9 +216,17 @@ namespace ILSpy.Views @@ -216,9 +216,17 @@ namespace ILSpy.Views
if (value is null)
return string.Empty;
// Mirror the formatting the column itself uses, so what's on the clipboard
// matches what the user sees ("0x06000001" rather than "100663297").
if (!string.IsNullOrEmpty(info?.Format) && value is IFormattable f)
return f.ToString(info.Format, System.Globalization.CultureInfo.InvariantCulture);
// matches what the user sees ("0x06000001" rather than "100663297"). Enum
// values must be widened to their underlying integer first — Enum.ToString
// rejects multi-character format specs like "X8".
if (!string.IsNullOrEmpty(info?.Format))
{
if (value is Enum enumValue)
value = System.Convert.ChangeType(enumValue, enumValue.GetTypeCode(),
System.Globalization.CultureInfo.InvariantCulture);
if (value is IFormattable f)
return f.ToString(info.Format, System.Globalization.CultureInfo.InvariantCulture);
}
return value.ToString() ?? string.Empty;
}

Loading…
Cancel
Save