/// <summary> /// Append a DiffResult<T> to a list, merging common results. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="diff">The list of DiffResults.</param> /// <param name="value">The new value to add to the list.</param> /// <param name="owner">The owner (source, target or both) of the value.</param> private static void AppendResult <T>(List <DiffResult <T> > diff, T value, DiffOwner owner) { // If the last entry in the list has the same owner as the new value, // just append the new value to the old entry. if (diff.Count > 0) { DiffResult <T> lastResult = diff[diff.Count - 1]; if (lastResult.Owner == owner) { lastResult.Value.Add(value); return; } } // Otherwise, just add a new entry to the list. DiffResult <T> result = new DiffResult <T>() { Owner = owner, }; result.Value.Add(value); diff.Add(result); }
/// <summary> /// Prepend a DiffResult<T> to a list, merging common results. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="diff">The list of DiffResults.</param> /// <param name="value">The new value to add to the list.</param> /// <param name="owner">The owner (source, target or both) of the value.</param> private static void PrependResult <T>(List <DiffResult <T> > diff, T value, DiffOwner owner) { // If the first entry in the list has the same owner as the new value, // just prepend the new value to the old entry. if (diff.Count > 0) { DiffResult <T> firstResult = diff[0]; if (firstResult.Owner == owner) { firstResult.Value.Insert(0, value); return; } } // Otherwise, just add a new entry to the start of the list. DiffResult <T> result = new DiffResult <T>() { Owner = owner, }; result.Value.Add(value); diff.Insert(0, result); }