static void TestValidDiff(Hashtable a, Hashtable b, HashDiff diff) { diff.Apply(a); HashDiff newdiff = JsonDiff.Diff(a, b); System.Diagnostics.Debug.Assert(newdiff.Empty()); }
/// <summary> /// Finds the difference operation between two Json value items. /// </summary> private static DiffOperation DiffValue(object first, object second) { if (first == null && second == null) { return(null); } else if (second == null) { return(new RemoveOperation()); } else if (first == null) { return(new ChangeOperation(second)); } else if (first.GetType() != second.GetType()) { return(new ChangeOperation(second)); } else if (first is double) { return((double)first == (double)second ? null : new ChangeOperation(second)); } else if (first is bool) { return((bool)first == (bool)second ? null : new ChangeOperation(second)); } else if (first is string) { return((string)first == (string)second ? null : new ChangeOperation(second)); } else if (first is Hashtable) { HashDiff subdiff = Diff(first as Hashtable, second as Hashtable); return(subdiff.Empty() ? null : new ChangeObjectOperation(subdiff)); } else if (first is ArrayList) { if (AreIdArrays(first as ArrayList, second as ArrayList)) { HashDiff subdiff = IdDiff(first as ArrayList, second as ArrayList); return(subdiff.Empty() ? null : new ChangeIdArrayOperation(subdiff)); } else { PositionArrayDiff subdiff = PositionDiff(first as ArrayList, second as ArrayList); return(subdiff.Empty() ? null : new ChangePositionArrayOperation(subdiff)); } } else { throw new System.Exception("error"); } }