Make generated and reflective document members one rule

The generator and CultDocumentRegistry now discover members by the same
steps: most-derived declaration first, override chain collapsed to one
member, attributes read up the override chain, rejections in one order
with one text (GCC001 / InvalidOperationException).

- Accessors are named per document, so documents sharing a [CultName] or
  [CultIndex] base member no longer emit duplicate methods (CS0111).
- Duplicate [Key] slots are refused, including new-hidden fields and
  properties; a hidden persisted member with a different slot is refused.
- String [Key("x")] gets its own message instead of "has no [Key]".
- A persisted property whose set accessor is private, protected or init,
  or a readonly field, is refused instead of CS0272 in generated code.
- Overrides: MessagePack's DynamicObjectResolver reads the base
  declaration's [Key]/[IgnoreMember] (it throws "key is duplicated" for a
  re-keyed override and serializes an override marked [IgnoreMember]).
  An override that changes them is refused in both paths; an override
  that repeats or omits them is accepted and byte-pinned.
- Typed Serialize<T>/Deserialize<T> used static Options and skipped
  generated codecs and declared resolvers; deleted. CultNetDocumentBinding
  and CultMeshSnapshots route through the untyped path with their registry.

DocumentShapeSweepTests compiles each shape through the generator and
compares generated vs reflective schema id, catalog, name/index values
and payload against MessagePack's own bytes, or equal rejection text.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-13 22:00:16 +02:00
commit 7c4bc2bdc0
12 changed files with 602 additions and 127 deletions

View file

@ -80,7 +80,8 @@ namespace GameCult.Networking
Func<byte[], T>? payloadDeserializer = null)
where T : class
{
var descriptor = (registry ?? CultDocumentRegistry.Shared).GetRequired<T>();
var documents = registry ?? CultDocumentRegistry.Shared;
var descriptor = documents.GetRequired<T>();
return new CultNetDocumentBinding(
typeof(T),
string.IsNullOrWhiteSpace(schemaId) ? descriptor.SchemaId : schemaId!,
@ -89,11 +90,11 @@ namespace GameCult.Networking
var typed = (T)document;
return payloadSerializer != null
? payloadSerializer(typed)
: CultDocumentMessagePackSerialization.Serialize(typed);
: CultDocumentMessagePackSerialization.SerializeUntyped(typed, typeof(T), documents);
},
payload => payloadDeserializer != null
? payloadDeserializer(payload)
: CultDocumentMessagePackSerialization.Deserialize<T>(payload));
: (T)CultDocumentMessagePackSerialization.DeserializeUntyped(typeof(T), payload, documents));
}
/// <summary>
@ -111,7 +112,8 @@ namespace GameCult.Networking
throw new ArgumentNullException(nameof(documentType));
}
var descriptor = (registry ?? CultDocumentRegistry.Shared).GetRequired(documentType);
var documents = registry ?? CultDocumentRegistry.Shared;
var descriptor = documents.GetRequired(documentType);
return new CultNetDocumentBinding(
documentType,
string.IsNullOrWhiteSpace(schemaId) ? descriptor.SchemaId : schemaId!,
@ -125,11 +127,11 @@ namespace GameCult.Networking
return payloadSerializer != null
? payloadSerializer(document)
: CultDocumentMessagePackSerialization.SerializeUntyped(document, documentType);
: CultDocumentMessagePackSerialization.SerializeUntyped(document, documentType, documents);
},
payload => payloadDeserializer != null
? payloadDeserializer(payload)
: CultDocumentMessagePackSerialization.DeserializeUntyped(documentType, payload));
: CultDocumentMessagePackSerialization.DeserializeUntyped(documentType, payload, documents));
}
}