From 64700f44fa34ea299baccc5d116e1bddd7c2f2be Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 8 May 2026 18:40:50 +0200 Subject: [PATCH] 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 --- ILSpy/Views/MetadataTablePage.axaml.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ILSpy/Views/MetadataTablePage.axaml.cs b/ILSpy/Views/MetadataTablePage.axaml.cs index 65230c0ab..73c3a029b 100644 --- a/ILSpy/Views/MetadataTablePage.axaml.cs +++ b/ILSpy/Views/MetadataTablePage.axaml.cs @@ -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; }