Show unkeyed structs by their writable surface, not a lock rule
The unkeyed struct rule found auto-properties by the compiler's <Name>k__BackingField name and marked the whole struct Unsupported when one was get-only or a field was readonly. Record structs fell out with a generic reason, and settable or init properties beside a field were silently hidden. Editing is in place, so the lock protected nothing. An unkeyed struct now shows its public fields (readonly ones read-only) and its public properties that have a setter (init-only ones read-only). Get-only properties are computed or kept by the in-place edit, so they are not rows; vector swizzles stay out of the inspector. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
838bbfffec
commit
7d59021b57
3 changed files with 35 additions and 26 deletions
|
|
@ -231,11 +231,14 @@ namespace GameCult.Caching.Tests
|
|||
Assert.That(open.Kind, Is.EqualTo(CultInspectorValueKind.Nested));
|
||||
Assert.That(open.Members.Select(member => member.Name), Is.EqualTo(new[] { "x", "y" }));
|
||||
Assert.That(open.Members.All(member => member.IsAssignable), Is.True);
|
||||
foreach (var (locked, member) in new[] { (typeof(InspectReadonlyField), "y"), (typeof(InspectGetOnly), "Id") })
|
||||
{
|
||||
Assert.That(model.ShapeOf(locked).Kind, Is.EqualTo(CultInspectorValueKind.Unsupported), locked.Name);
|
||||
Assert.That(model.ShapeOf(locked).Reason, Does.Contain(locked.Name + "." + member).And.Contain("readonly or get-only"));
|
||||
}
|
||||
(string, bool)[] Rows(Type type) => model.ShapeOf(type).Members.Select(member => (member.Name, member.IsReadOnly)).ToArray();
|
||||
Assert.That(Rows(typeof(InspectMixedStruct)), Is.EqualTo(new[] { ("x", false), ("y", true), ("Settable", false), ("Initable", true) }),
|
||||
"fields, then settable properties; readonly and init are read-only; get-only is not a row");
|
||||
Assert.That(Rows(typeof(InspectRecordStruct)), Is.EqualTo(new[] { ("A", false), ("B", false) }));
|
||||
Assert.That(Rows(typeof(InspectReadonlyRecordStruct)), Is.EqualTo(new[] { ("A", true), ("B", true) }));
|
||||
object boxed = new InspectRecordStruct(1, 2f);
|
||||
model.ShapeOf(typeof(InspectRecordStruct)).Members[0].SetValue(boxed, 5);
|
||||
Assert.That(((InspectRecordStruct)boxed).A, Is.EqualTo(5), "a property edit lands in the boxed struct in place");
|
||||
|
||||
Assert.That(model.ShapeOf(typeof(IDictionary<string, int>)).Kind, Is.EqualTo(CultInspectorValueKind.Dictionary));
|
||||
Assert.That(model.BuildDictionary(typeof(IDictionary<string, int>), new[] { new KeyValuePair<object?, object?>("a", 1) }),
|
||||
|
|
@ -342,17 +345,18 @@ namespace GameCult.Caching.Tests
|
|||
public float Length => x + y;
|
||||
}
|
||||
|
||||
public struct InspectReadonlyField
|
||||
public struct InspectMixedStruct
|
||||
{
|
||||
public float x;
|
||||
public readonly float y;
|
||||
public int Settable { get; set; }
|
||||
public int Initable { get; init; }
|
||||
public int Computed => Settable + 1;
|
||||
}
|
||||
|
||||
public struct InspectGetOnly
|
||||
{
|
||||
public float x;
|
||||
public int Id { get; }
|
||||
}
|
||||
public record struct InspectRecordStruct(int A, float B);
|
||||
|
||||
public readonly record struct InspectReadonlyRecordStruct(int A, float B);
|
||||
|
||||
[MessagePackObject]
|
||||
public readonly record struct InspectKey([property: Key(0)] int Value)
|
||||
|
|
|
|||
Loading…
Reference in a new issue