Esempio n. 1
0
        /// <summary>Ensures set contain only elements that are present either in the current set or in the specified collection, but not both.</summary>
        /// <param name="source">The current set.</param>
        /// <param name="other">The collection to compare to the current set.</param>
        /// <returns>A new set if there is any modification to current sealed set; otherwise, the current set.</returns>
        public static IModels SymmetricExcept(this IModels source, IModels other)
        {
            source.VerifyNotNull(nameof(source));
            other.VerifyNotNull(nameof(other));

            IModels removedModelSet = Models.Empty;

            foreach (var item in source)
            {
                if (other.Contains(item))
                {
                    removedModelSet = removedModelSet.Add(item);
                    source          = source.Remove(item);
                }
            }

            foreach (var item in other)
            {
                if (removedModelSet.Contains(item))
                {
                    source = source.Add(item);
                }
            }

            return(source);
        }
Esempio n. 2
0
        /// <summary>Removes the models to ensure the set contains only models both exist in this set and the specified collection.</summary>
        /// <param name="source">The current set.</param>
        /// <param name="other">The collection to compare to the current set.</param>
        /// <returns>A new set if there is any modification to current set and current set sealed; otherwise, the current set.</returns>
        public static IModels Intersect(this IModels source, IModels other)
        {
            source.VerifyNotNull(nameof(source));
            other.VerifyNotNull(nameof(other));

            foreach (var item in source)
            {
                if (!other.Contains(item))
                {
                    source = source.Remove(item);
                }
            }
            return(source);
        }