Browse Source

Tolerate either field or property in Images lookup

Every_ExportToolbarCommand_Resolves_An_Icon used GetField against
ILSpy.Avalonia.Images.Images to verify every [ExportToolbarCommand]'s
ToolbarIcon resolves to a live IImage. Images.Images currently
declares its icons as static readonly fields, but a future refactor
could lazify them into properties (we explored that path earlier in
this session before reverting). Accept either FieldInfo or
PropertyInfo so the test keeps holding under that refactor.

Assisted-by: Claude:claude-opus-4-7:Claude Code
pull/3755/head
Siegfried Pammer 2 months ago
parent
commit
4d9a88873b
  1. 17
      ILSpy.Tests/MainWindow/MainToolBarLayoutTests.cs

17
ILSpy.Tests/MainWindow/MainToolBarLayoutTests.cs

@ -132,12 +132,17 @@ public class MainToolBarLayoutTests @@ -132,12 +132,17 @@ public class MainToolBarLayoutTests
var name = iconPath!.StartsWith("Images/", System.StringComparison.Ordinal)
? iconPath["Images/".Length..]
: iconPath;
var field = typeof(global::ILSpy.Images.Images)
.GetField(name, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
field.Should().NotBeNull(
$"toolbar command with ToolTip='{entry.Metadata.ToolTip}' references Images/{name} but no static field with that name exists in ILSpy.Images.Images");
field!.GetValue(null).Should().NotBeNull(
$"the Images.{name} field is declared but null at runtime");
// Icons may be declared as either static-readonly fields (eager) or static
// properties with a lazy backing field (post-perf-pass). Look up either shape.
var bindingFlags = System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static;
var imagesType = typeof(global::ILSpy.Images.Images);
var field = imagesType.GetField(name, bindingFlags);
var property = field is null ? imagesType.GetProperty(name, bindingFlags) : null;
(field is not null || property is not null).Should().BeTrue(
$"toolbar command with ToolTip='{entry.Metadata.ToolTip}' references Images/{name} but no static member with that name exists in ILSpy.Images.Images");
var value = field is not null ? field.GetValue(null) : property!.GetValue(null);
value.Should().NotBeNull(
$"the Images.{name} member is declared but null at runtime");
}
}

Loading…
Cancel
Save