mirror of https://github.com/icsharpcode/ILSpy.git
Browse Source
SessionSettings now carries HideEmptyMetadataTables (default true, matching prior behavior) and MetadataTablesTreeNode honors it: when true, tables with zero rows are hidden; when false, every CLI TableIndex is surfaced. The setting persists across launches via ILSpy.xml. There's no options dialog yet to flip it, but the plumbing is in place for a future settings UI to toggle. Assisted-by: Claude:claude-opus-4-7:Claude Codepull/3755/head
3 changed files with 130 additions and 1 deletions
@ -0,0 +1,105 @@
@@ -0,0 +1,105 @@
|
||||
// Copyright (c) 2026 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// 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.
|
||||
|
||||
using System.Linq; |
||||
using System.Reflection.Metadata.Ecma335; |
||||
using System.Threading.Tasks; |
||||
|
||||
using Avalonia.Headless.NUnit; |
||||
|
||||
using AwesomeAssertions; |
||||
|
||||
using ILSpy; |
||||
using ILSpy.AppEnv; |
||||
using ILSpy.Metadata; |
||||
using ILSpy.TreeNodes; |
||||
using ILSpy.ViewModels; |
||||
using ILSpy.Views; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.ILSpy.Tests.Metadata; |
||||
|
||||
[TestFixture] |
||||
public class HideEmptyMetadataTablesTests |
||||
{ |
||||
[AvaloniaTest] |
||||
public async Task Default_Setting_Hides_Tables_With_Zero_Rows() |
||||
{ |
||||
// Default SessionSettings.HideEmptyMetadataTables = true: every child of the
|
||||
// Tables sub-tree must correspond to a non-zero CLI table.
|
||||
|
||||
var settings = AppComposition.Current.GetExport<SettingsService>().SessionSettings; |
||||
settings.HideEmptyMetadataTables = true; |
||||
|
||||
var window = AppComposition.Current.GetExport<MainWindow>(); |
||||
window.Show(); |
||||
var vm = (MainWindowViewModel)window.DataContext!; |
||||
await vm.AssemblyTreeModel.WaitForAssembliesAsync(minimumCount: 1); |
||||
|
||||
var coreLibName = typeof(object).Assembly.GetName().Name!; |
||||
var tables = LoadTablesNode(vm, coreLibName, out var metadata); |
||||
|
||||
tables.Children.OfType<MetadataTableTreeNode>().Should().AllSatisfy(t => |
||||
metadata.GetTableRowCount(t.Kind).Should().BeGreaterThan(0, |
||||
"with HideEmptyMetadataTables=true, every visible table must have at least one row")); |
||||
} |
||||
|
||||
[AvaloniaTest] |
||||
public async Task Disabling_The_Setting_Surfaces_Every_Table_Even_When_Empty() |
||||
{ |
||||
// Flip HideEmptyMetadataTables off and confirm a table that's known empty for
|
||||
// CoreLib (FieldRva, which is rare in modern managed code) shows up among the
|
||||
// children.
|
||||
|
||||
var settings = AppComposition.Current.GetExport<SettingsService>().SessionSettings; |
||||
settings.HideEmptyMetadataTables = false; |
||||
try |
||||
{ |
||||
var window = AppComposition.Current.GetExport<MainWindow>(); |
||||
window.Show(); |
||||
var vm = (MainWindowViewModel)window.DataContext!; |
||||
await vm.AssemblyTreeModel.WaitForAssembliesAsync(minimumCount: 1); |
||||
|
||||
var coreLibName = typeof(object).Assembly.GetName().Name!; |
||||
var tables = LoadTablesNode(vm, coreLibName, out var _); |
||||
|
||||
var visibleKinds = tables.Children.OfType<MetadataTableTreeNode>() |
||||
.Select(t => t.Kind).ToHashSet(); |
||||
visibleKinds.Should().Contain(System.Enum.GetValues<TableIndex>(), |
||||
"with HideEmptyMetadataTables=false, every CLI TableIndex must surface as a child"); |
||||
} |
||||
finally |
||||
{ |
||||
settings.HideEmptyMetadataTables = true; |
||||
} |
||||
} |
||||
|
||||
static MetadataTablesTreeNode LoadTablesNode(MainWindowViewModel vm, string assemblyName, |
||||
out System.Reflection.Metadata.MetadataReader metadata) |
||||
{ |
||||
var assemblyNode = vm.AssemblyTreeModel.FindNode<AssemblyTreeNode>(assemblyName); |
||||
assemblyNode.EnsureLazyChildren(); |
||||
var metadataNode = assemblyNode.Children.OfType<MetadataTreeNode>().Single(); |
||||
metadataNode.EnsureLazyChildren(); |
||||
var tables = metadataNode.Children.OfType<MetadataTablesTreeNode>().Single(); |
||||
tables.EnsureLazyChildren(); |
||||
metadata = assemblyNode.LoadedAssembly.GetMetadataFileOrNull()!.Metadata; |
||||
return tables; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue