Exemple #1
0
        /// <summary>
        /// Updates the old collection with new items, while removing the inexistent.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="old"></param>
        /// <param name="fresh"></param>
        /// <returns></returns>
        public static void Update <T>(this IList <T> old, IEnumerable <T> fresh) where T : IEquatable <T>
        {
            if (old == null)
            {
                throw new ArgumentNullException("old");
            }
            if (fresh == null)
            {
                throw new ArgumentNullException("fresh");
            }
            var diff = fresh.Diff(old);

            foreach (var item in diff.Removed)
            {
                old.Remove(item);
            }
            foreach (var item in diff.Added)
            {
                old.Add(item);
            }
        }