CrystalJsonPackContext
Namespace: SnowBank.Data.Json · struct
State of one packing walk: the settings and resolver in effect, and the recursion guards
Remarks
A context is opened once per root value (see the Pack extension in JsonSerializerExtensions) and passed by ref through every nested Pack call, including the collection and dictionary helpers, so the depth and visited-object guards survive every seam of the walk.
A packer's implementation brackets its body with Enter and Leave, same contract as MarkVisited / Leave: the pairing is not exception-safe by design, a walk that threw is not resumable.
Properties
Depth
int Depth { get; }
Number of values already open above the one being packed
Methods
Create
static CrystalJsonPackContext Create(CrystalJsonSettings settings = null, ICrystalJsonTypeResolver resolver = null, int depth = 0)
Opens a fresh packing walk
settings— Serialization settings for the whole walkresolver— Custom resolver for the whole walkdepth— Number of levels to consider already open, for a walk embedded under an outer structure; the visited stack starts empty either way
Enter
void Enter()
Enters one value of the object graph, counting depth only
For value types, which cannot take part in a reference cycle: skips the visited stack, and avoids boxing the instance
void Enter(object instance)
Enters one value of the object graph: rejects past MaxDepth, and rejects a reference cycle
instance— Value about to be packed; only reference types join the visited stack
Leave
void Leave()
Leaves the value entered by the matching parameterless Enter
void Leave(object instance)
Leaves the value entered by the matching Enter
instance— Same value that was passed to Enter
Fields
Resolver
readonly ICrystalJsonTypeResolver Resolver
Custom resolver in effect for the whole walk
Settings
readonly CrystalJsonSettings Settings
Serialization settings in effect for the whole walk