/// <summary> /// Provides an implementation of <see cref="ISet{T}.IsSubsetOf"/>. /// </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> /// <param name="comparer">The comparer.</param> /// <returns>The result of <see cref="ISet{T}.IsSubsetOf"/>.</returns> /// <remarks> /// <para> /// From <see href="https://msdn.microsoft.com/en-us/library/dd412074(v=vs.110).aspx"/>; /// Determines whether a set is a subset of a specified collection. /// </para><para> /// If other contains the same elements as the current set, the current set is still considered a /// subset of other. /// </para><para> /// This method always returns false if the current set has elements that are not in other. /// </para> /// </remarks> public static bool IsSubsetOf <T>(ISet <T> source, IEnumerable <T> other, IEqualityComparer <T> comparer) { Contracts.Requires.That(source != null); Contracts.Requires.That(comparer != null); ISetContracts.IsSubsetOf(other); return(IsSubsetOf(source, other as HashSet <T> ?? new HashSet <T>(other, comparer))); }
/// <summary> /// Provides an implementation of <see cref="ISet{T}.IsSubsetOf"/>. /// </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> /// <returns>The result of <see cref="ISet{T}.IsSubsetOf"/>.</returns> /// <remarks> /// <para> /// From <see href="https://msdn.microsoft.com/en-us/library/dd412074(v=vs.110).aspx"/>; /// Determines whether a set is a subset of a specified collection. /// </para><para> /// If other contains the same elements as the current set, the current set is still considered a /// subset of other. /// </para><para> /// This method always returns false if the current set has elements that are not in other. /// </para> /// </remarks> public static bool IsSubsetOf <T>(ISet <T> source, HashSet <T> other) { Contracts.Requires.That(source != null); ISetContracts.IsSubsetOf(other); if (source.Count > other.Count) { return(false); } return(source.All(other.Contains)); }
/// <inheritdoc /> public bool IsSubsetOf(IEnumerable <IDisposable> other) { ISetContracts.IsSubsetOf(other); return(this.disposables.IsSubsetOf(other)); }