Ejemplo n.º 1
0
        /// <inheritdoc />
        public void SymmetricExceptWith(IEnumerable <IDisposable> other)
        {
            ISetContracts.SymmetricExceptWith(this, other);

            if (this.IsDisposed)
            {
                return;
            }

            this.disposables.SymmetricExceptWith(other);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Provides an implementation of <see cref="ISet{T}.SymmetricExceptWith"/>.
        /// </summary>
        /// <typeparam name="T">The type of values in the collections.</typeparam>
        /// <param name="source">The source collection that is implementing <see cref="ISet{T}"/>.</param>
        /// <param name="other">The other enumerable.</param>
        /// <remarks>
        /// From <see href="https://msdn.microsoft.com/en-us/library/dd411718(v=vs.110).aspx"/>;
        /// Modifies the current set so that it contains only elements that are present either in
        /// the current set or in the specified collection, but not both.
        /// </remarks>
        public static void SymmetricExceptWith <T>(ISet <T> source, IEnumerable <T> other)
        {
            Contracts.Requires.That(source != null);
            ISetContracts.SymmetricExceptWith(source, other);

            if (source.IsReadOnly)
            {
                return;
            }

            foreach (T value in other)
            {
                // if source contains the value, remove it, otherwise add it
                if (!source.Remove(value))
                {
                    source.Add(value);
                }
            }
        }