Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2872: Expand special handling for sets in Assert.Contains/DoesNotCon…
…tain (v2)
- Loading branch information
1 parent
203b4d9
commit 13bb60b
Showing
3 changed files
with
60 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#if NET5_0_OR_GREATER | ||
|
||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
public class ReadOnlySet<T> : IReadOnlySet<T> | ||
{ | ||
readonly HashSet<T> hashSet; | ||
|
||
public ReadOnlySet( | ||
IEqualityComparer<T> comparer, | ||
params T[] items) => | ||
hashSet = new HashSet<T>(items, comparer); | ||
|
||
public int Count => hashSet.Count; | ||
|
||
public bool Contains(T item) => hashSet.Contains(item); | ||
public IEnumerator<T> GetEnumerator() => hashSet.GetEnumerator(); | ||
public bool IsProperSubsetOf(IEnumerable<T> other) => hashSet.IsProperSubsetOf(other); | ||
public bool IsProperSupersetOf(IEnumerable<T> other) => hashSet.IsProperSupersetOf(other); | ||
public bool IsSubsetOf(IEnumerable<T> other) => hashSet.IsSubsetOf(other); | ||
public bool IsSupersetOf(IEnumerable<T> other) => hashSet.IsSupersetOf(other); | ||
public bool Overlaps(IEnumerable<T> other) => hashSet.Overlaps(other); | ||
public bool SetEquals(IEnumerable<T> other) => hashSet.SetEquals(other); | ||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
} | ||
|
||
#endif |