Browse Source

Distinguish enum and const fields in the assembly tree

FieldTreeNode used the base Field icon for every kind of field. The
WPF version distinguished EnumValue and Literal so a reader could
tell at a glance whether a member was a backing field, a const, or
an enum case.

Mirror the master logic (master:ILSpy/TreeNodes/FieldTreeNode.cs:60),
but with two scope cuts:

- Use Images.Enum for enum values. We don't have a dedicated
  EnumValue.svg, and the type-level Enum glyph reads correctly in
  context (an enum case sits inside an Enum node).

- Skip the FieldReadOnly branch entirely -- no asset exists yet and
  inventing one isn't in scope for this commit. Readonly fields keep
  falling through to the base Field icon, the same as before.

Detection rule for an enum value: DeclaringType.Kind is Enum AND
ReturnType.Kind is Enum. The second clause is what excludes the
synthesised int32 value__ backing field that every enum carries --
that field's return type is Int32, not the enum itself.

Assisted-by: Claude:claude-opus-4-7:Claude Code
pull/3755/head
Siegfried Pammer 1 month ago
parent
commit
b4c709d5fa
  1. 23
      ILSpy/TreeNodes/FieldTreeNode.cs

23
ILSpy/TreeNodes/FieldTreeNode.cs

@ -43,8 +43,27 @@ namespace ILSpy.TreeNodes @@ -43,8 +43,27 @@ namespace ILSpy.TreeNodes
public override object NavigationText => Language.EntityToString(FieldDefinition, ConversionFlags.ShowDeclaringType);
public override object Icon => Images.Images.GetIcon(Images.Images.Field,
Images.Images.GetOverlay(FieldDefinition.Accessibility), FieldDefinition.IsStatic);
public override object Icon => GetIcon(FieldDefinition);
// Distinguish enum members and const fields from regular instance/static fields so the
// tree reads the way the C# source does. The IsReadOnly / FieldReadOnly variant from
// the WPF era isn't ported because we don't have a dedicated SVG for it yet -- such
// fields fall through to the base Field icon.
public static Avalonia.Media.IImage GetIcon(IField field)
{
// EnumValue: the field's declaring type is an enum and its return type is the enum
// itself -- this excludes the synthesised int32 'value__' backing field.
if (field.DeclaringType.Kind == TypeKind.Enum && field.ReturnType.Kind == TypeKind.Enum)
return Images.Images.GetIcon(Images.Images.Enum,
Images.Images.GetOverlay(field.Accessibility));
if (field.IsConst)
return Images.Images.GetIcon(Images.Images.Literal,
Images.Images.GetOverlay(field.Accessibility));
return Images.Images.GetIcon(Images.Images.Field,
Images.Images.GetOverlay(field.Accessibility), field.IsStatic);
}
public override bool ShowExpander => false;
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)

Loading…
Cancel
Save