Collapse the ref-candidate predicate and read inherited member attributes

RecordCandidates and the new IsRecordCandidate share one rule, so a
picker's candidates and a drop's acceptance cannot disagree. Member
attributes are read with Attribute.GetCustomAttributes(member, true):
PropertyInfo.GetCustomAttributes ignores inherit, so a base abstract
property's inspector attributes never reached the override.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-29 11:55:41 +02:00
commit a6382475e4
2 changed files with 67 additions and 6 deletions

View file

@ -33,7 +33,7 @@ namespace GameCult.Caching
internal CultInspectorMetadata(MemberInfo? member)
{
Attributes = member == null ? Array.Empty<Attribute>() : member.GetCustomAttributes(true).OfType<Attribute>().ToArray();
Attributes = member == null ? Array.Empty<Attribute>() : Attribute.GetCustomAttributes(member, true);
var label = Find<CultInspectorLabelAttribute>()?.Label;
Label = string.IsNullOrWhiteSpace(label) ? null : label;
Hidden = Find<CultInspectorHiddenAttribute>() != null;
@ -206,7 +206,7 @@ namespace GameCult.Caching
private CultInspectorClaim ResolveCore(Type valueType, MemberInfo? member)
{
Type? drawer = null;
foreach (var attribute in member?.GetCustomAttributes(true).OfType<Attribute>() ?? Enumerable.Empty<Attribute>())
foreach (var attribute in member == null ? Array.Empty<Attribute>() : Attribute.GetCustomAttributes(member, true))
{
for (var type = attribute.GetType(); type != null && type != typeof(Attribute); type = type.BaseType)
{
@ -513,14 +513,24 @@ namespace GameCult.Caching
// The records a CultRecordRef<T> may point at: every record whose document is a T, by label.
public IReadOnlyList<CultStoredDocument> RecordCandidates(Type recordRefType, IEnumerable<CultStoredDocument> records)
{
var target = ShapeOf(recordRefType).RecordTarget
?? throw new ArgumentException($"{recordRefType.Name} is not a CultRecordRef<T>.", nameof(recordRefType));
var target = RecordTargetOf(recordRefType);
return records
.Where(record => target.IsInstanceOfType(record.Document) && record.Key.Value.Length > 0)
.Where(record => IsCandidateFor(target, record))
.OrderBy(RecordLabel, StringComparer.OrdinalIgnoreCase)
.ToArray();
}
// Whether record may be the value of a recordRefType: the one rule the picker's candidates and a drop share.
public bool IsRecordCandidate(Type recordRefType, CultStoredDocument record) =>
IsCandidateFor(RecordTargetOf(recordRefType), record ?? throw new ArgumentNullException(nameof(record)));
private Type RecordTargetOf(Type recordRefType) =>
ShapeOf(recordRefType).RecordTarget
?? throw new ArgumentException($"{recordRefType.Name} is not a CultRecordRef<T>.", nameof(recordRefType));
private static bool IsCandidateFor(Type target, CultStoredDocument record) =>
target.IsInstanceOfType(record.Document) && record.Key.Value.Length > 0;
public object CreateRecordRef(Type recordRefType, string key)
{
if (ShapeOf(recordRefType).Kind != CultInspectorValueKind.RecordRef)