using System; using System.Collections.Generic; using System.Text; using Microsoft.AspNetCore.JsonPatch; using Microsoft.AspNetCore.JsonPatch.Operations; namespace System { public static class JsonPatchHelper { public static T JsonAdd(this T t, string path, object value) where T : class { JsonPatchDocument jsonPatch = new JsonPatchDocument(); jsonPatch.Operations.Add(new Operation("add", path, null, value)); jsonPatch.ApplyTo(t); return t; } public static T JsonRemove(this T t, string path) where T : class { JsonPatchDocument jsonPatch = new JsonPatchDocument(); jsonPatch.Operations.Add(new Operation("remove", path, null, null)); jsonPatch.ApplyTo(t); return t; } public static T JsonReplace(this T t, string path, object value) where T : class { JsonPatchDocument jsonPatch = new JsonPatchDocument(); jsonPatch.Operations.Add(new Operation("replace", path, null, value)); jsonPatch.ApplyTo(t); return t; } public static T JsonMove(this T t, string from, string path) where T : class { JsonPatchDocument jsonPatch = new JsonPatchDocument(); jsonPatch.Operations.Add(new Operation("move", path, from)); jsonPatch.ApplyTo(t); return t; } public static T JsonCopy(this T t, string from, string path) where T : class { JsonPatchDocument jsonPatch = new JsonPatchDocument(); jsonPatch.Operations.Add(new Operation("copy", path, from)); jsonPatch.ApplyTo(t); return t; } } }