ILayerStatePersistable
Interfaces · AiDotNet.Serialization
Opt-in contract letting ANY type be carried as layer construction state, without the generator having to learn about it.
Known implementations: HeterogeneousGraphMetadata, SpaceFillingCurveSet
How It Works
Every state type the generator understands today – int, double[], bool[], string[], enums, layer collections, expression trees – required a ValueKind, a Classify case, emission sites and a runtime reader. That is a per-type mechanism in the generator, and a layer author with a novel type could do nothing but wait for the generator to be patched. This contract replaces N of those with one: Classify asks a single question, and a type that answers it works with no generator change at all.
INSTANCE methods, not C# 11 static abstract members: this assembly still targets net471, where
static abstract interface members do not exist. LoadState is therefore called on a
freshly constructed instance, so an implementing type needs a public parameterless constructor.
The generator verifies that at BUILD time and reports it, rather than failing when a model is
restored.
Implementations must round-trip exactly: LoadState(SaveState()) has to reproduce every
value the layer will use. A partial implementation is worse than none, because the clone then
looks correct and computes something else.
Methods
| Method | Summary |
|---|---|
string SaveState() |
Writes this value as text the same type can read back. |
void LoadState(string text) |
Populates a freshly constructed instance from text. |