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 Add(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 Remove(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 Replace(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 Move(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 Copy(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; } } }