/// <summary> /// Updates a collection of items by removing the exceding items and adding the missing items /// from another set of items. /// </summary> /// <typeparam name="T">The type of the items</typeparam> /// <param name="collection">The collection to update</param> /// <param name="items">The set of items to compare the collection to</param> /// <param name="comparer">The way to determine if two items are equal</param> public static void Update <T>( this Collection <T> collection, IEnumerable <T> items, IEqualityComparer <T> comparer) { var diff = collection.Differences(items, comparer); collection.RemoveAll(diff.Item1); collection.AddAll(diff.Item2); }
public void CollectInto(Collection result) { if (Multityped is Collection collection) { result.AddAll(collection); } else { result.Add(Multityped); } }
public void CollectInto(Collection result) { if (!(Multityped is Collection)) { result.Add(Multityped); return; } result.AddAll((Collection) Multityped); }
/// <summary> /// Updates a collection of items by removing some items and adding others. /// </summary> /// <typeparam name="T">The type of the items</typeparam> /// <param name="collection">The collection to update</param> /// <param name="diff">A tuple with the items to remove and the items to add</param> public static void Update <T>( this Collection <T> collection, Tuple <IEnumerable <T>, IEnumerable <T> > diff) { collection.RemoveAll(diff.Item1); collection.AddAll(diff.Item2); }