Skip to content

Instantly share code, notes, and snippets.

@cezarypiatekGC
Created July 30, 2020 07:41
Show Gist options
  • Save cezarypiatekGC/f7b863832fa78bc15546479a3cd4e71f to your computer and use it in GitHub Desktop.
Save cezarypiatekGC/f7b863832fa78bc15546479a3cd4e71f to your computer and use it in GitHub Desktop.
public static class PatchExtensions
{
public static bool HasBeenChanged<T, TProperty>(this JsonPatchDocument<T> patch, Expression<Func<T, TProperty>> field) where T : class
{
var fieldPathWithPrefix = field.Body.ToString().Replace(".", "/");
var fieldPath = fieldPathWithPrefix.Substring(fieldPathWithPrefix.IndexOf("/", StringComparison.InvariantCulture));
return patch.Operations.Any(x => x.path == fieldPath);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment