IMutableJsonContext
Namespace: SnowBank.Data.Json · interface
Context that will record all the changes made to a MutableJsonValue
Properties
Count
int Count { get; }
Number of changes registered on this transaction
HasMutations
bool HasMutations { get; }
Tests if the underlying observed object has been changed during this transaction
Returns false if no changes have been made, or if alls changes did not actually mutate the value.
Methods
FromJson
MutableJsonValue FromJson(JsonValue value)
Wraps a top-level JsonValue into a MutableJsonValue 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 mutated
MutableJsonValue FromJson(MutableJsonValue parent, JsonPathSegment path, JsonValue value)
Wraps a JsonValue into a MutableJsonValue that will be monitored by this context
parent— Parent that contains this valuepath— Name or index of this value in its parentvalue— JSON value that must be wrapped
Mutable value that will notify this context whenever it (or any of its descendant) is mutated
NewArray
JsonArray NewArray()
Creates a new empty array, using the transactions default settings
NewObject
JsonObject NewObject()
Creates a new empty object, using the transactions default settings
RecordDelete
void RecordDelete(IJsonProxyNode instance, JsonPathSegment child)
Records the deletion of an existing field of an object or item of an array
instance— Parent instance (expected to be an object)child— Path of the child (name of field for objects, index of item for arrays)
This records the fact that the field does not exist any longer in the object
Setting a field to null is logically equivalent to deleting the field
Any previous mutation on this item, or any child, should be superseded by this record.
RecordInsertAt
void RecordInsertAt(IJsonProxyNode instance, Index offset, JsonValue argument)
Records the insertion of an item in an array
instance— Parent instance (expected to be an object)offset— Index where to insert the child, or^0to append at the end of the array.argument— Value of the new child
This records the facts that a new item is inserted to an array.
RecordPatch
void RecordPatch(IJsonProxyNode instance, JsonPathSegment child, JsonValue argument)
Records the update of an existing field of an object or item of an array, using a patch definition
instance— Parent instance (expected to be an object)child— Path of the child (name of field for objects, index of item for arrays), or Empty for the document itselfargument— Patch that describes the changes to this field
This records the fact that the value of a field of the object as been patched.
Any previous mutation on this field, or any child, should be merged with this patch
RecordTruncate
void RecordTruncate(IJsonProxyNode instance, int length)
Truncate an array to the specified length
instance— Parent instance (expected to be an array)length— New length of the array
Any item that would fall outside the new bounds of the array will be removed.
If the array is smaller than length, extra null entries will be appended as needed.
RecordUpdate
void RecordUpdate(IJsonProxyNode instance, JsonPathSegment child, JsonValue argument)
Records the update of a field of an object or item of an array, with a new explicit value
instance— Parent instance (expected to be an object)child— Path of the child (name of field for objects, index of item for arrays), or Empty for the document itselfargument— Updated value of the field
This records the fact that the value of a field of the object as been replaced by another value.
Any previous mutation on this field, or any child, is superseded by this record
Reset
void Reset()
Reset the transaction to its initial state, reverting any previous mutations.
This method can be used to reuse the current transaction instance