public void Merge(string prefix, JsonDiffResult o)
        {
            var k = o.Keys();
            var c = k.Length;

            for (var i = 0; i < c; i++)
            {
                var newKey = prefix + "." + k[i];
                this.Add(newKey, o.Get(k[i]));
            }
        }
Example #2
0
        public JsonDiffResult Compare(object obj1, object obj2)
        {
            var d1     = this.Parse(obj1);
            var d2     = this.Parse(obj2);
            var result = new JsonDiffResult();

            if (d1.Equals(d2))
            {
                return(result);
            }

            foreach (var o in d1)
            {
                if (d2.ContainsKey(o.Key))
                {
                    if (!o.Value.Equals(d2[o.Key]))
                    {
                        if (o.Value.GetType() == typeof(JObject))
                        {
                            var subResult = this.Compare(o.Value, d2[o.Key]);
                            if (subResult.Count() > 0)
                            {
                                result.Add(o.Key, "updated");
                                result.Merge(o.Key, subResult);
                            }
                        }
                        else
                        {
                            result.Add(o.Key, "updated");
                        }
                    }
                }
                else
                {
                    result.Add(o.Key, "deleted");
                }
            }

            foreach (var o in d2)
            {
                if (!d1.ContainsKey(o.Key))
                {
                    result.Add(o.Key, "added");
                }
            }

            return(result);
        }