IObservableJsonContext

Namespace: SnowBank.Data.Json · interface

Context that will record all the reads performed on a ObservableJsonValue

Methods

FromJson

ObservableJsonValue FromJson(JsonValue value)

Wraps a top-level JSON into an observable document

ObservableJsonValue FromJson(IJsonProxyNode parent, JsonPathSegment path, JsonValue value)

Wraps a children JSON value into an observable document node

  • parent — Parent node
  • path — Path from the parent node to the child node
  • value — Value of the child node

Returns: Observable child node

RecordRead

void RecordRead(IJsonProxyNode node, JsonPathSegment child, JsonValue argument, ObservableJsonAccess access)

Records the access to a node, or one of its children

  • node — Node that was accessed.
  • child — Path to the accessed child, or Empty if node itself was accessed
  • argument — Current value of the accessed part, or Missing if the part does not exist
  • access — Specifies how the value was used by the reader

If argument is Null, it means the accessed part is present in node, but with a null value.

If argument is Missing, it means the accessed part is not present in node.

ctx.RecordRead(obj, new("hello"), obj["hello"], ObservableJsonAccess.Value); // read the value of the 'hello' field of obj
ctx.RecordRead(arr, new(2), obj[2], ObservableJsonAccess.Value); // read the value of the first item in arr
ctx.RecordRead(obj, default, obj, ObservableJsonAccess.Value); // read the value of the object itself (ex: conversion to a CLR object, serialization to JSON text, ...)
ctx.RecordRead(arr, default, arr, ObservableJsonAccess.Length); // used the length of the array, but not its content (ex: read the Count property, or accessed an item with [^1], ...)
ctx.RecordRead(value, default, value, ObservableJsonAccess.Exists); // tested if the value is null or missing
ctx.RecordRead(obj, new("hello"), obj["hello"], ObservableJsonAccess.Exists); // tested for the present of the 'hello' field of obj

Reset

void Reset()

Reset the context to its initial state, reverting any previous mutations.

This method can be used to reuse the current context for a different session