protected virtual IMergeResult MergeArray(JArray update, JArray other, IJsonMergeContext context) { if (!JToken.DeepEquals(update, other)) { return(context.Merge(update, other)); } return(context.Noop(update, other)); }
protected virtual IMergeResult MergeObject(JObject update, JObject other, IJsonMergeContext context) { IEnumerable <MergeResult> diffs = from key in UnionKeys(update, other) let diff = (MergeResult)Merge(update[key], other[key], context.Next(key)) select diff; return(context.Multiple(diffs, update, other)); }
public virtual IMergeResult Merge(JToken update, JToken other, IJsonMergeContext context) { if (meta.Contains(update?.Path ?? other?.Path)) { return(context.Noop(update, other)); } if (update == null && other == null) { return(context.Noop(null, null)); } if (update == null || other == null || update.Type != other.Type) { return(context.Merge(update, other)); } //TODO: (jmd 2015-11-23) Could change this into try cast into JValue, JObject, JArray -> Might be easier to read. switch (update.Type) { case JTokenType.Object: return(MergeObject((JObject)update, (JObject)other, context)); case JTokenType.Array: return(MergeArray((JArray)update, (JArray)other, context)); case JTokenType.Integer: case JTokenType.Float: case JTokenType.String: case JTokenType.Boolean: case JTokenType.Null: case JTokenType.Undefined: case JTokenType.Date: case JTokenType.Raw: case JTokenType.Bytes: case JTokenType.Guid: case JTokenType.Uri: case JTokenType.TimeSpan: return(MergeValue((JValue)update, (JValue)other, context)); } throw new ArgumentOutOfRangeException(); }
protected virtual IMergeResult MergeValue(JValue update, JValue other, IJsonMergeContext context) { return(!JToken.DeepEquals(update, other) ? context.Merge(update, other) : context.Noop(update, other)); }