C# Class Microsoft.AspNetCore.JsonPatch.Adapters.ObjectAdapter

Inheritance: IObjectAdapter
Show file Open project: aspnet/JsonPatch

Public Methods

Method Description
Add ( Operation operation, object objectToApplyTo ) : void

The "add" operation performs one of the following functions, depending upon what the target location references: o If the target location specifies an array index, a new value is inserted into the array at the specified index. o If the target location specifies an object member that does not already exist, a new member is added to the object. o If the target location specifies an object member that does exist, that member's value is replaced. The operation object MUST contain a "value" member whose content specifies the value to be added. For example: { "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] } When the operation is applied, the target location MUST reference one of: o The root of the target document - whereupon the specified value becomes the entire content of the target document. o A member to add to an existing object - whereupon the supplied value is added to that object at the indicated location. If the member already exists, it is replaced by the specified value. o An element to add to an existing array - whereupon the supplied value is added to the array at the indicated location. Any elements at or above the specified index are shifted one position to the right. The specified index MUST NOT be greater than the number of elements in the array. If the "-" character is used to index the end of the array (see [RFC6901]), this has the effect of appending the value to the array. Because this operation is designed to add to existing objects and arrays, its target location will often not exist. Although the pointer's error handling algorithm will thus be invoked, this specification defines the error handling behavior for "add" pointers to ignore that error and add the value as specified. However, the object itself or an array containing it does need to exist, and it remains an error for that not to be the case. For example, an "add" with a target location of "/a/b" starting with this document: { "a": { "foo": 1 } } is not an error, because "a" exists, and "b" will be added to its value. It is an error in this document: { "q": { "bar": 2 } } because "a" does not exist.

Copy ( Operation operation, object objectToApplyTo ) : void

The "copy" operation copies the value at a specified location to the target location. The operation object MUST contain a "from" member, which is a string containing a JSON Pointer value that references the location in the target document to copy the value from. The "from" location MUST exist for the operation to be successful. For example: { "op": "copy", "from": "/a/b/c", "path": "/a/b/e" } This operation is functionally identical to an "add" operation at the target location using the value specified in the "from" member. Note: even though it's the same functionally, we do not call add with the value specified in from for performance reasons (multiple checks of same requirements).

Move ( Operation operation, object objectToApplyTo ) : void

The "move" operation removes the value at a specified location and adds it to the target location. The operation object MUST contain a "from" member, which is a string containing a JSON Pointer value that references the location in the target document to move the value from. The "from" location MUST exist for the operation to be successful. For example: { "op": "move", "from": "/a/b/c", "path": "/a/b/d" } This operation is functionally identical to a "remove" operation on the "from" location, followed immediately by an "add" operation at the target location with the value that was just removed. The "from" location MUST NOT be a proper prefix of the "path" location; i.e., a location cannot be moved into one of its children.

ObjectAdapter ( IContractResolver contractResolver, Action logErrorAction ) : System

Initializes a new instance of ObjectAdapter.

Remove ( Operation operation, object objectToApplyTo ) : void

The "remove" operation removes the value at the target location. The target location MUST exist for the operation to be successful. For example: { "op": "remove", "path": "/a/b/c" } If removing an element from an array, any elements above the specified index are shifted one position to the left.

Replace ( Operation operation, object objectToApplyTo ) : void

The "replace" operation replaces the value at the target location with a new value. The operation object MUST contain a "value" member whose content specifies the replacement value. The target location MUST exist for the operation to be successful. For example: { "op": "replace", "path": "/a/b/c", "value": 42 } This operation is functionally identical to a "remove" operation for a value, followed immediately by an "add" operation at the same location with the replacement value. Note: even though it's the same functionally, we do not call remove + add for performance reasons (multiple checks of same requirements).

Private Methods

Method Description
Add ( string path, object value, object objectToApplyTo, Operation operationToReport ) : void

Add is used by various operations (eg: add, copy, ...), yet through different operations; This method allows code reuse yet reporting the correct operation on error

ConvertToActualType ( Type propertyType, object value ) : ConversionResult
GetActualPropertyPath ( string propertyPath, object objectToApplyTo, Operation operationToReport ) : ActualPropertyPathResult
GetIListType ( Type type ) : Type
GetValueAtLocation ( string location, object objectToGetValueFrom, Operation operationToReport ) : GetValueResult

Method is used by Copy and Move to avoid duplicate code

IsGenericListType ( Type type ) : bool
IsNonStringArray ( Type type ) : bool
LogError ( JsonPatchError jsonPatchError ) : void
Remove ( string path, object objectToApplyTo, Operation operationToReport ) : RemovedPropertyTypeResult

Remove is used by various operations (eg: remove, move, ...), yet through different operations; This method allows code reuse yet reporting the correct operation on error. The return value contains the type of the item that has been removed (and a bool possibly signifying an error) This can be used by other methods, like replace, to ensure that we can pass in the correctly typed value to whatever method follows.

Method Details

Add() public method

The "add" operation performs one of the following functions, depending upon what the target location references: o If the target location specifies an array index, a new value is inserted into the array at the specified index. o If the target location specifies an object member that does not already exist, a new member is added to the object. o If the target location specifies an object member that does exist, that member's value is replaced. The operation object MUST contain a "value" member whose content specifies the value to be added. For example: { "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] } When the operation is applied, the target location MUST reference one of: o The root of the target document - whereupon the specified value becomes the entire content of the target document. o A member to add to an existing object - whereupon the supplied value is added to that object at the indicated location. If the member already exists, it is replaced by the specified value. o An element to add to an existing array - whereupon the supplied value is added to the array at the indicated location. Any elements at or above the specified index are shifted one position to the right. The specified index MUST NOT be greater than the number of elements in the array. If the "-" character is used to index the end of the array (see [RFC6901]), this has the effect of appending the value to the array. Because this operation is designed to add to existing objects and arrays, its target location will often not exist. Although the pointer's error handling algorithm will thus be invoked, this specification defines the error handling behavior for "add" pointers to ignore that error and add the value as specified. However, the object itself or an array containing it does need to exist, and it remains an error for that not to be the case. For example, an "add" with a target location of "/a/b" starting with this document: { "a": { "foo": 1 } } is not an error, because "a" exists, and "b" will be added to its value. It is an error in this document: { "q": { "bar": 2 } } because "a" does not exist.
public Add ( Operation operation, object objectToApplyTo ) : void
operation Operation The add operation.
objectToApplyTo object Object to apply the operation to.
return void

Copy() public method

The "copy" operation copies the value at a specified location to the target location. The operation object MUST contain a "from" member, which is a string containing a JSON Pointer value that references the location in the target document to copy the value from. The "from" location MUST exist for the operation to be successful. For example: { "op": "copy", "from": "/a/b/c", "path": "/a/b/e" } This operation is functionally identical to an "add" operation at the target location using the value specified in the "from" member. Note: even though it's the same functionally, we do not call add with the value specified in from for performance reasons (multiple checks of same requirements).
public Copy ( Operation operation, object objectToApplyTo ) : void
operation Operation The copy operation.
objectToApplyTo object Object to apply the operation to.
return void

Move() public method

The "move" operation removes the value at a specified location and adds it to the target location. The operation object MUST contain a "from" member, which is a string containing a JSON Pointer value that references the location in the target document to move the value from. The "from" location MUST exist for the operation to be successful. For example: { "op": "move", "from": "/a/b/c", "path": "/a/b/d" } This operation is functionally identical to a "remove" operation on the "from" location, followed immediately by an "add" operation at the target location with the value that was just removed. The "from" location MUST NOT be a proper prefix of the "path" location; i.e., a location cannot be moved into one of its children.
public Move ( Operation operation, object objectToApplyTo ) : void
operation Operation The move operation.
objectToApplyTo object Object to apply the operation to.
return void

ObjectAdapter() public method

Initializes a new instance of ObjectAdapter.
public ObjectAdapter ( IContractResolver contractResolver, Action logErrorAction ) : System
contractResolver IContractResolver The .
logErrorAction Action The for logging .
return System

Remove() public method

The "remove" operation removes the value at the target location. The target location MUST exist for the operation to be successful. For example: { "op": "remove", "path": "/a/b/c" } If removing an element from an array, any elements above the specified index are shifted one position to the left.
public Remove ( Operation operation, object objectToApplyTo ) : void
operation Operation The remove operation.
objectToApplyTo object Object to apply the operation to.
return void

Replace() public method

The "replace" operation replaces the value at the target location with a new value. The operation object MUST contain a "value" member whose content specifies the replacement value. The target location MUST exist for the operation to be successful. For example: { "op": "replace", "path": "/a/b/c", "value": 42 } This operation is functionally identical to a "remove" operation for a value, followed immediately by an "add" operation at the same location with the replacement value. Note: even though it's the same functionally, we do not call remove + add for performance reasons (multiple checks of same requirements).
public Replace ( Operation operation, object objectToApplyTo ) : void
operation Operation The replace operation.
objectToApplyTo object Object to apply the operation to.
return void