IJsonPacker<T>

Namespace: SnowBank.Data.Json · interface

Types that implement this interface support packing directly into a JsonValue

Remarks

Types that also support the reverse direction should implement as well.

Methods

Pack

JsonValue Pack(ref CrystalJsonPackContext context, T instance)

Converts an instance of this type into the equivalent JsonValue

  • context — State of the walk (settings, resolver, recursion guards), threaded by ref through every nested call
  • instance — Value to convert

Most types will produce a JsonObject, but some simple types may return a packed JsonString, or a tuple represented by a JsonArray.

An implementation brackets its body with Enter / Leave so the depth and cycle guards cover it, and passes the same context to every nested pack call.

To pack a root value without managing a context, use the Pack(instance, settings, resolver) extension in JsonSerializerExtensions, which opens a fresh context and forwards here.