|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | + |
| 4 | +using SystemTextJsonPatch.Operations; |
| 5 | + |
| 6 | +namespace SystemTextJsonPatch.Adapters; |
| 7 | + |
| 8 | +/// <summary> |
| 9 | +/// Defines the operations that can be performed on a JSON patch document. |
| 10 | +/// </summary> |
| 11 | +public interface IObjectAdapter |
| 12 | +{ |
| 13 | + /// <summary> |
| 14 | + /// Using the "add" operation a new value is inserted into the root of the target |
| 15 | + /// document, into the target array at the specified valid index, or to a target object at |
| 16 | + /// the specified location. |
| 17 | + /// |
| 18 | + /// When adding to arrays, the specified index MUST NOT be greater than the number of elements in the array. |
| 19 | + /// To append the value to the array, the index of "-" character is used (see [RFC6901]). |
| 20 | + /// |
| 21 | + /// When adding to an object, if an object member does not already exist, a new member is added to the object at the |
| 22 | + /// specified location or if an object member does exist, that member's value is replaced. |
| 23 | + /// |
| 24 | + /// The operation object MUST contain a "value" member whose content |
| 25 | + /// specifies the value to be added. |
| 26 | + /// |
| 27 | + /// For example: |
| 28 | + /// |
| 29 | + /// { "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] } |
| 30 | + /// |
| 31 | + /// See RFC 6902 <see href="https://tools.ietf.org/html/rfc6902#page-4"/> |
| 32 | + /// </summary> |
| 33 | + /// <param name="operation">The add operation.</param> |
| 34 | + /// <param name="objectToApplyTo">Object to apply the operation to.</param> |
| 35 | + void Add(Operation operation, object objectToApplyTo); |
| 36 | + |
| 37 | + /// <summary> |
| 38 | + /// Using the "copy" operation, a value is copied from a specified location to the |
| 39 | + /// target location. |
| 40 | + /// |
| 41 | + /// The operation object MUST contain a "from" member, which references the location in the |
| 42 | + /// target document to copy the value from. |
| 43 | + /// |
| 44 | + /// The "from" location MUST exist for the operation to be successful. |
| 45 | + /// |
| 46 | + /// For example: |
| 47 | + /// |
| 48 | + /// { "op": "copy", "from": "/a/b/c", "path": "/a/b/e" } |
| 49 | + /// |
| 50 | + /// See RFC 6902 <see href="https://tools.ietf.org/html/rfc6902#page-7"/> |
| 51 | + /// </summary> |
| 52 | + /// <param name="operation">The copy operation.</param> |
| 53 | + /// <param name="objectToApplyTo">Object to apply the operation to.</param> |
| 54 | + void Copy(Operation operation, object objectToApplyTo); |
| 55 | + |
| 56 | + /// <summary> |
| 57 | + /// Using the "move" operation the value at a specified location is removed and |
| 58 | + /// added to the target location. |
| 59 | + /// |
| 60 | + /// The operation object MUST contain a "from" member, which references the location in the |
| 61 | + /// target document to move the value from. |
| 62 | + /// |
| 63 | + /// The "from" location MUST exist for the operation to be successful. |
| 64 | + /// |
| 65 | + /// For example: |
| 66 | + /// |
| 67 | + /// { "op": "move", "from": "/a/b/c", "path": "/a/b/d" } |
| 68 | + /// |
| 69 | + /// A location cannot be moved into one of its children. |
| 70 | + /// |
| 71 | + /// See RFC 6902 <see href="https://tools.ietf.org/html/rfc6902#page-6"/> |
| 72 | + /// </summary> |
| 73 | + /// <param name="operation">The move operation.</param> |
| 74 | + /// <param name="objectToApplyTo">Object to apply the operation to.</param> |
| 75 | + void Move(Operation operation, object objectToApplyTo); |
| 76 | + |
| 77 | + /// <summary> |
| 78 | + /// Using the "remove" operation the value at the target location is removed. |
| 79 | + /// |
| 80 | + /// The target location MUST exist for the operation to be successful. |
| 81 | + /// |
| 82 | + /// For example: |
| 83 | + /// |
| 84 | + /// { "op": "remove", "path": "/a/b/c" } |
| 85 | + /// |
| 86 | + /// If removing an element from an array, any elements above the |
| 87 | + /// specified index are shifted one position to the left. |
| 88 | + /// |
| 89 | + /// See RFC 6902 <see href="https://tools.ietf.org/html/rfc6902#page-6"/> |
| 90 | + /// </summary> |
| 91 | + /// <param name="operation">The remove operation.</param> |
| 92 | + /// <param name="objectToApplyTo">Object to apply the operation to.</param> |
| 93 | + void Remove(Operation operation, object objectToApplyTo); |
| 94 | + |
| 95 | + /// <summary> |
| 96 | + /// Using the "replace" operation the value at the target location is replaced |
| 97 | + /// with a new value. The operation object MUST contain a "value" member |
| 98 | + /// which specifies the replacement value. |
| 99 | + /// |
| 100 | + /// The target location MUST exist for the operation to be successful. |
| 101 | + /// |
| 102 | + /// For example: |
| 103 | + /// |
| 104 | + /// { "op": "replace", "path": "/a/b/c", "value": 42 } |
| 105 | + /// |
| 106 | + /// See RFC 6902 <see href="https://tools.ietf.org/html/rfc6902#page-6"/> |
| 107 | + /// </summary> |
| 108 | + /// <param name="operation">The replace operation.</param> |
| 109 | + /// <param name="objectToApplyTo">Object to apply the operation to.</param> |
| 110 | + void Replace(Operation operation, object objectToApplyTo); |
| 111 | +} |
0 commit comments