JsonDiff.cs
1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
namespace UniJSON
{
public enum JsonDiffType
{
KeyAdded,
KeyRemoved,
ValueChanged,
}
public struct JsonDiff
{
public JsonPointer Path;
public JsonDiffType DiffType;
public string Msg;
public static JsonDiff Create<T>(ListTreeNode<T> node, JsonDiffType diffType, string msg)
where T: IListTreeItem, IValue<T>
{
return new JsonDiff
{
Path = JsonPointer.Create(node),
DiffType = diffType,
Msg = msg,
};
}
public override string ToString()
{
switch (DiffType)
{
case JsonDiffType.KeyAdded:
return string.Format("+ {0}: {1}", Path, Msg);
case JsonDiffType.KeyRemoved:
return string.Format("- {0}: {1}", Path, Msg);
case JsonDiffType.ValueChanged:
return string.Format("= {0}: {1}", Path, Msg);
default:
throw new NotImplementedException();
}
}
}
}