ObservableJsonTraceCapturingContext

Namespace: SnowBank.Data.Json · class

Implements: IObservableJsonContext

Context that will capture all read access to an ObservableJsonValue into a ObservableJsonTrace

Constructors

ObservableJsonTraceCapturingContext

ObservableJsonTraceCapturingContext()

Properties

Trace

ObservableJsonTrace Trace { get; }

Trace that recorded all reads to the observed document

Methods

FromJson

ObservableJsonValue FromJson(JsonValue value)

Wraps a top-level JsonValue into a ObservableJsonValue that will be monitored by this context

  • value — JSON value that represents the top-most object or array of the document

Mutable value that will notify this context whenever it (or any of its descendant) is accessed

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

Wraps a JsonValue into a ObservableJsonValue that will be monitored by this context

  • parent — Parent that contains this value
  • path — Name or index of this value in its parent
  • value — JSON value that must be wrapped

Mutable value that will notify this context whenever it (or any of its descendant) is accessed

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