Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate the From Value while Adding Delta Operations #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Populate the From Value while Adding Delta Operations
Populate the From Value while Adding Delta Operations
  • Loading branch information
doddag committed Aug 11, 2021
commit 341764382fa88ce3f220b9a0ee72684bded0ecdc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected override void Format(DeltaType type, JsonFormatContext context, JToken
break;

case DeltaType.Deleted:
FormatDeleted(context);
FormatDeleted(context, delta);
break;

case DeltaType.Moved:
Expand Down Expand Up @@ -71,17 +71,17 @@ private void FormatNode(JsonFormatContext context, JToken delta, JToken left)

private void FormatAdded(JsonFormatContext context, JToken delta)
{
context.PushCurrentOp(OperationTypes.Add, delta[0]);
context.PushCurrentOp(OperationTypes.Add, null, delta[0]);
}

private void FormatModified(JsonFormatContext context, JToken delta)
{
context.PushCurrentOp(OperationTypes.Replace, delta[1]);
context.PushCurrentOp(OperationTypes.Replace, delta[0], delta[1]);
}

private void FormatDeleted(JsonFormatContext context)
private void FormatDeleted(JsonFormatContext context, JToken delta)
{
context.PushCurrentOp(OperationTypes.Remove);
context.PushCurrentOp(OperationTypes.Remove, delta[0]);
}

private void FormatMoved(JsonFormatContext context, JToken delta)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ public IList<Operation> Result()

public void PushCurrentOp(string op)
{
Operations.Add(new Operation(op, CurrentPath(), null));
Operations.Add(new Operation(op, CurrentPath(), null, null));
}

public void PushCurrentOp(string op, object value)
public void PushCurrentOp(string op, object from)
{
Operations.Add(new Operation(op, CurrentPath(), null, value));
Operations.Add(new Operation(op, CurrentPath(), from, null));
}

public void PushCurrentOp(string op, object from, object value)
{
Operations.Add(new Operation(op, CurrentPath(), from, value));
}

public void PushMoveOp(string to)
Expand Down
4 changes: 2 additions & 2 deletions Src/JsonDiffPatchDotNet/Formatters/JsonPatch/Operation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public Operation(string op, string path, string from)
From = from;
}

public Operation(string op, string path, string from, object value)
public Operation(string op, string path, object from, object value)
{
Op = op;
Path = path;
Expand All @@ -28,7 +28,7 @@ public Operation(string op, string path, string from, object value)
public string Op { get; set; }

[JsonProperty("from")]
public string From { get; set; }
public object From { get; set; }

[JsonProperty("value")]
public object Value { get; set; }
Expand Down