From a6ad9889471cdcc4ac55729480b1d58406d7fb9e Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 6 Jun 2026 21:46:06 +0200 Subject: [PATCH] Show the token-kind byte in the metadata-table tab header The tree node's text leads with the table's token-kind byte (e.g. "02 TypeDef (1234)"), but the opened tab's title dropped it and showed just "TypeDef (1234)". Lead the tab title with the same byte so the two match. Assisted-by: Claude:claude-opus-4-8:Claude Code --- ILSpy.Tests/Metadata/MetadataTokenNavigationTests.cs | 2 +- ILSpy.Tests/Metadata/TypedMetadataTableTreeTests.cs | 8 ++++---- ILSpy/Metadata/MetadataTableTreeNode.cs | 4 +++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ILSpy.Tests/Metadata/MetadataTokenNavigationTests.cs b/ILSpy.Tests/Metadata/MetadataTokenNavigationTests.cs index 89641d4c0..f8c5590b1 100644 --- a/ILSpy.Tests/Metadata/MetadataTokenNavigationTests.cs +++ b/ILSpy.Tests/Metadata/MetadataTokenNavigationTests.cs @@ -75,7 +75,7 @@ public class MetadataTokenNavigationTests // and a fresh metadata page is showing. var factory = (global::ILSpy.Docking.ILSpyDockFactory)vm.DockWorkspace.Factory; var landed = (MetadataTablePageModel)factory.MainTab!.Content!; - landed.Title.Should().StartWith(expectedTableIndex.ToString()); + landed.Title.Should().Contain(expectedTableIndex.ToString()); // title leads with the kind byte landed.Items.Should().HaveCountGreaterThan((int)(expectedRowNumber - 1), "the target row index must be in range for the destination table"); } diff --git a/ILSpy.Tests/Metadata/TypedMetadataTableTreeTests.cs b/ILSpy.Tests/Metadata/TypedMetadataTableTreeTests.cs index 3a95b9961..c5d4ecdda 100644 --- a/ILSpy.Tests/Metadata/TypedMetadataTableTreeTests.cs +++ b/ILSpy.Tests/Metadata/TypedMetadataTableTreeTests.cs @@ -57,7 +57,7 @@ public class TypedMetadataTableTreeTests var tab = await vm.DockWorkspace.WaitForMetadataTabAsync(); TestCapture.Step("assemblyref-grid"); - tab.Title.Should().StartWith("AssemblyRef"); + tab.Title.Should().Contain("AssemblyRef"); // title now leads with the token-kind byte tab.Items.Should().HaveCount(assemblyRefNode.RowCount); var names = tab.Items.Cast() .Select(e => e.Name) @@ -82,7 +82,7 @@ public class TypedMetadataTableTreeTests var tab = await vm.DockWorkspace.WaitForMetadataTabAsync(); TestCapture.Step("typedef-grid"); - tab.Title.Should().StartWith("TypeDef"); + tab.Title.Should().Contain("TypeDef"); // title now leads with the token-kind byte tab.Items.Cast() .Should().Contain(e => e.Name == "Object"); } @@ -112,7 +112,7 @@ public class TypedMetadataTableTreeTests vm.AssemblyTreeModel.SelectNode(methodNode); var tab = await vm.DockWorkspace.WaitForMetadataTabAsync(); TestCapture.Step("methoddef-grid"); - tab.Title.Should().StartWith("MethodDef"); + tab.Title.Should().Contain("MethodDef"); // title now leads with the token-kind byte tab.Columns.Select(c => c.Tag).Should().Contain("RID"); } @@ -132,7 +132,7 @@ public class TypedMetadataTableTreeTests var tab = await vm.DockWorkspace.WaitForMetadataTabAsync(); TestCapture.Step("module-grid"); - tab.Title.Should().StartWith("Module"); + tab.Title.Should().Contain("Module"); // title now leads with the token-kind byte tab.Items.Should().HaveCount(1); var row = (ModuleTableTreeNode.ModuleEntry)tab.Items[0]; row.Name.Should().EndWith(".dll"); diff --git a/ILSpy/Metadata/MetadataTableTreeNode.cs b/ILSpy/Metadata/MetadataTableTreeNode.cs index 9f716f721..f5465b8c3 100644 --- a/ILSpy/Metadata/MetadataTableTreeNode.cs +++ b/ILSpy/Metadata/MetadataTableTreeNode.cs @@ -82,7 +82,9 @@ namespace ILSpy.Metadata // + ReflectionHelper.GetNestedPropertyValue, which return null for every row when // the source's element type is object. var page = new MetadataTablePageModel { - Title = $"{Kind} ({RowCount})", + // Lead with the token-kind byte, mirroring the tree node's Text so the tab header + // reads e.g. "02 TypeDef (1234)". + Title = $"{(byte)Kind:X2} {Kind} ({RowCount})", Items = cached ??= LoadTable(), }; MetadataColumnBuilder.Populate(page);