コード例 #1
0
        private JsonPatchResult _Remove(JsonValue json)
        {
            if (string.IsNullOrEmpty(Path))
            {
                json.Object.Clear();
                return(new JsonPatchResult(json));
            }

            var(target, key, index, found) = JsonPointerFunctions.ResolvePointer(json, Path);
            if (!found)
            {
                return(new JsonPatchResult(json, $"Path '{Path}' not found."));
            }

            switch (target.Type)
            {
            case JsonValueType.Object:
                target.Object.Remove(key);
                break;

            case JsonValueType.Array:
                target.Array.RemoveAt(index);
                break;

            default:
                return(new JsonPatchResult(json, $"Cannot remove a value from a '{target.Type}'"));
            }

            return(new JsonPatchResult(json));
        }
コード例 #2
0
        private JsonPatchResult _RemoveAtPath(JsonValue json, string path)
        {
            if (string.IsNullOrEmpty(Path))
            {
                json.Object.Clear();
                return(new JsonPatchResult(json));
            }

            var(target, key, index, found) = JsonPointerFunctions.ResolvePointer(json, path);
            if (!found)
            {
                return(new JsonPatchResult(json, $"Path '{path}' not found."));
            }

            switch (target !.Type)
            {