internal abstract void MergeItem(object content, JsonMergeSettings settings);
/// <summary> /// Merge the specified content into this <see cref="JToken"/> using <see cref="JsonMergeSettings"/>. /// </summary> /// <param name="content">The content to be merged.</param> /// <param name="settings">The <see cref="JsonMergeSettings"/> used to merge the content.</param> public void Merge(object content, JsonMergeSettings settings) { MergeItem(content, settings); }
internal static void MergeEnumerableContent(JContainer target, IEnumerable content, JsonMergeSettings settings) { switch (settings.MergeArrayHandling) { case MergeArrayHandling.Concat: foreach (JToken item in content) { target.Add(item); } break; case MergeArrayHandling.Union: #if HAVE_HASH_SET HashSet <JToken> items = new HashSet <JToken>(target, EqualityComparer); foreach (JToken item in content) { if (items.Add(item)) { target.Add(item); } } #else Dictionary <JToken, bool> items = new Dictionary <JToken, bool>(EqualityComparer); foreach (JToken t in target) { items[t] = true; } foreach (JToken item in content) { if (!items.ContainsKey(item)) { items[item] = true; target.Add(item); } } #endif break; case MergeArrayHandling.Replace: target.ClearItems(); foreach (JToken item in content) { target.Add(item); } break; case MergeArrayHandling.Merge: int i = 0; foreach (object targetItem in content) { if (i < target.Count) { JToken sourceItem = target[i]; JContainer existingContainer = sourceItem as JContainer; if (existingContainer != null) { existingContainer.Merge(targetItem, settings); } else { if (targetItem != null) { JToken contentValue = CreateFromContent(targetItem); if (contentValue.Type != JTokenType.Null) { target[i] = contentValue; } } } } else { target.Add(targetItem); } i++; } break; default: throw new ArgumentOutOfRangeException(nameof(settings), "Unexpected merge array handling when merging JSON."); } }