From 75ca2b35bb92cd20dd90c0f52c7446195def08c4 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Sat, 27 Apr 2024 07:21:43 -0700 Subject: [PATCH 1/3] Revert "Update ICollection usage to IReadOnlyCollection where applicable (#101469)" This reverts commit e92b7d0074adcdb026408bc862f11ac484edeba8. --- .../System/Diagnostics/DiagnosticsHelper.cs | 8 ----- .../Frozen/FrozenSetInternalBase.cs | 12 ------- .../Immutable/ImmutableExtensions.Minimal.cs | 2 -- .../Collections/Generic/PriorityQueue.cs | 2 +- .../System/Collections/Generic/SortedSet.cs | 2 +- .../src/System/Dynamic/ExpandoObject.cs | 32 +------------------ .../src/System/Linq/ParallelEnumerable.cs | 4 +-- .../System.Linq/src/System/Linq/AnyAll.cs | 2 +- .../src/System/Linq/AppendPrepend.SpeedOpt.cs | 4 +-- .../System.Linq/src/System/Linq/Count.cs | 4 +-- .../System/Linq/DefaultIfEmpty.SpeedOpt.cs | 2 +- .../System.Linq/src/System/Linq/ElementAt.cs | 4 +-- .../System.Linq/src/System/Linq/First.cs | 2 +- .../System.Linq/src/System/Linq/Grouping.cs | 17 +--------- .../System.Linq/src/System/Linq/Last.cs | 4 +-- .../System/Linq/OrderedEnumerable.SpeedOpt.cs | 2 +- .../src/System/Linq/Reverse.SpeedOpt.cs | 6 ++-- .../src/System/Linq/SequenceEqual.cs | 4 +-- .../System.Linq/src/System/Linq/Single.cs | 2 +- .../ServiceNameCollection.cs | 2 +- .../Collections/Concurrent/ConcurrentQueue.cs | 2 +- .../System/Collections/Generic/Dictionary.cs | 2 +- .../src/System/Collections/Generic/HashSet.cs | 12 +++---- .../Xml/Xsl/Runtime/XmlQuerySequence.cs | 17 ++-------- .../src/System/Text/Json/Nodes/JsonObject.cs | 7 +--- 25 files changed, 36 insertions(+), 121 deletions(-) diff --git a/src/libraries/Common/src/System/Diagnostics/DiagnosticsHelper.cs b/src/libraries/Common/src/System/Diagnostics/DiagnosticsHelper.cs index dcc9de3e4ad65..ce7f345b0ea9c 100644 --- a/src/libraries/Common/src/System/Diagnostics/DiagnosticsHelper.cs +++ b/src/libraries/Common/src/System/Diagnostics/DiagnosticsHelper.cs @@ -35,22 +35,14 @@ internal static bool CompareTags(List>? sortedTags int size = count / (sizeof(ulong) * 8) + 1; BitMapper bitMapper = new BitMapper(size <= 100 ? stackalloc ulong[size] : new ulong[size]); -#if NET9_0_OR_GREATER // ICollection : IReadOnlyCollection on .NET 9+ - if (tags2 is IReadOnlyCollection> tagsCol) -#else if (tags2 is ICollection> tagsCol) -#endif { if (tagsCol.Count != count) { return false; } -#if NET9_0_OR_GREATER // IList : IReadOnlyList on .NET 9+ - if (tagsCol is IReadOnlyList> secondList) -#else if (tagsCol is IList> secondList) -#endif { for (int i = 0; i < count; i++) { diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/FrozenSetInternalBase.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/FrozenSetInternalBase.cs index 02e5e0cc07cb2..4afe1f7503e75 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/FrozenSetInternalBase.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/FrozenSetInternalBase.cs @@ -32,11 +32,7 @@ private protected override bool IsProperSubsetOfCore(IEnumerable other) { Debug.Assert(_thisSet.Count != 0, "EmptyFrozenSet should have been used."); -#if NET9_0_OR_GREATER // ICollection : IReadOnlyCollection on .NET 9+ - if (other is IReadOnlyCollection otherAsCollection) -#else if (other is ICollection otherAsCollection) -#endif { int otherCount = otherAsCollection.Count; @@ -63,11 +59,7 @@ private protected override bool IsProperSupersetOfCore(IEnumerable other) { Debug.Assert(_thisSet.Count != 0, "EmptyFrozenSet should have been used."); -#if NET9_0_OR_GREATER // ICollection : IReadOnlyCollection on .NET 9+ - if (other is IReadOnlyCollection otherAsCollection) -#else if (other is ICollection otherAsCollection) -#endif { int otherCount = otherAsCollection.Count; @@ -111,11 +103,7 @@ private protected override bool IsSupersetOfCore(IEnumerable other) Debug.Assert(_thisSet.Count != 0, "EmptyFrozenSet should have been used."); // Try to compute the answer based purely on counts. -#if NET9_0_OR_GREATER // ICollection : IReadOnlyCollection on .NET 9+ - if (other is IReadOnlyCollection otherAsCollection) -#else if (other is ICollection otherAsCollection) -#endif { int otherCount = otherAsCollection.Count; diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableExtensions.Minimal.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableExtensions.Minimal.cs index dc9c7d26898b7..66b365bad872b 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableExtensions.Minimal.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableExtensions.Minimal.cs @@ -38,13 +38,11 @@ internal static bool TryGetCount(this IEnumerable sequence, out int count) return true; } -#if !NET9_0_OR_GREATER // ICollection : IReadOnlyCollection on .NET 9+ if (sequence is ICollection collectionOfT) { count = collectionOfT.Count; return true; } -#endif if (sequence is IReadOnlyCollection readOnlyCollection) { diff --git a/src/libraries/System.Collections/src/System/Collections/Generic/PriorityQueue.cs b/src/libraries/System.Collections/src/System/Collections/Generic/PriorityQueue.cs index 072e5ac34d605..5047b76433738 100644 --- a/src/libraries/System.Collections/src/System/Collections/Generic/PriorityQueue.cs +++ b/src/libraries/System.Collections/src/System/Collections/Generic/PriorityQueue.cs @@ -462,7 +462,7 @@ public void EnqueueRange(IEnumerable elements, TPriority priority) ArgumentNullException.ThrowIfNull(elements); int count; - if (elements is IReadOnlyCollection collection && + if (elements is ICollection collection && (count = collection.Count) > _nodes.Length - _size) { Grow(checked(_size + count)); diff --git a/src/libraries/System.Collections/src/System/Collections/Generic/SortedSet.cs b/src/libraries/System.Collections/src/System/Collections/Generic/SortedSet.cs index fd0beccb28a77..2f7406d0d7bf4 100644 --- a/src/libraries/System.Collections/src/System/Collections/Generic/SortedSet.cs +++ b/src/libraries/System.Collections/src/System/Collections/Generic/SortedSet.cs @@ -1323,7 +1323,7 @@ public bool Overlaps(IEnumerable other) if (Count == 0) return false; - if (other is IReadOnlyCollection c && c.Count == 0) + if (other is ICollection c && c.Count == 0) return false; SortedSet? asSorted = other as SortedSet; diff --git a/src/libraries/System.Linq.Expressions/src/System/Dynamic/ExpandoObject.cs b/src/libraries/System.Linq.Expressions/src/System/Dynamic/ExpandoObject.cs index 906ee3fd84fc2..288d01c185dbf 100644 --- a/src/libraries/System.Linq.Expressions/src/System/Dynamic/ExpandoObject.cs +++ b/src/libraries/System.Linq.Expressions/src/System/Dynamic/ExpandoObject.cs @@ -17,7 +17,7 @@ namespace System.Dynamic /// /// Represents an object with members that can be dynamically added and removed at runtime. /// - public sealed class ExpandoObject : IDynamicMetaObjectProvider, IDictionary, IReadOnlyDictionary, INotifyPropertyChanged + public sealed class ExpandoObject : IDynamicMetaObjectProvider, IDictionary, INotifyPropertyChanged { private static readonly MethodInfo s_expandoTryGetValue = typeof(RuntimeOps).GetMethod(nameof(RuntimeOps.ExpandoTryGetValue))!; @@ -618,10 +618,6 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() ICollection IDictionary.Values => new ValueCollection(this); - IEnumerable IReadOnlyDictionary.Keys => new KeyCollection(this); - - IEnumerable IReadOnlyDictionary.Values => new ValueCollection(this); - object? IDictionary.this[string key] { get @@ -640,18 +636,6 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() } } - object? IReadOnlyDictionary.this[string key] - { - get - { - if (!TryGetValueForKey(key, out object? value)) - { - throw System.Linq.Expressions.Error.KeyDoesNotExistInExpando(key); - } - return value; - } - } - void IDictionary.Add(string key, object? value) { this.TryAddMember(key, value); @@ -666,15 +650,6 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() return index >= 0 && data[index] != Uninitialized; } - bool IReadOnlyDictionary.ContainsKey(string key) - { - ArgumentNullException.ThrowIfNull(key); - - ExpandoData data = _data; - int index = data.Class.GetValueIndexCaseSensitive(key); - return index >= 0 && data[index] != Uninitialized; - } - bool IDictionary.Remove(string key) { ArgumentNullException.ThrowIfNull(key); @@ -687,11 +662,6 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() return TryGetValueForKey(key, out value); } - bool IReadOnlyDictionary.TryGetValue(string key, out object? value) - { - return TryGetValueForKey(key, out value); - } - #endregion #region ICollection> Members diff --git a/src/libraries/System.Linq.Parallel/src/System/Linq/ParallelEnumerable.cs b/src/libraries/System.Linq.Parallel/src/System/Linq/ParallelEnumerable.cs index f0885d3d3e7d4..55ef371ea0422 100644 --- a/src/libraries/System.Linq.Parallel/src/System/Linq/ParallelEnumerable.cs +++ b/src/libraries/System.Linq.Parallel/src/System/Linq/ParallelEnumerable.cs @@ -1852,7 +1852,7 @@ public static int Count(this ParallelQuery source) // If the data source is a collection, we can just return the count right away. if (source is ParallelEnumerableWrapper sourceAsWrapper) { - if (sourceAsWrapper.WrappedEnumerable is IReadOnlyCollection sourceAsCollection) + if (sourceAsWrapper.WrappedEnumerable is ICollection sourceAsCollection) { return sourceAsCollection.Count; } @@ -1923,7 +1923,7 @@ public static long LongCount(this ParallelQuery source) // If the data source is a collection, we can just return the count right away. if (source is ParallelEnumerableWrapper sourceAsWrapper) { - if (sourceAsWrapper.WrappedEnumerable is IReadOnlyCollection sourceAsCollection) + if (sourceAsWrapper.WrappedEnumerable is ICollection sourceAsCollection) { return sourceAsCollection.Count; } diff --git a/src/libraries/System.Linq/src/System/Linq/AnyAll.cs b/src/libraries/System.Linq/src/System/Linq/AnyAll.cs index d6d6e4adccdeb..28a3783aa8829 100644 --- a/src/libraries/System.Linq/src/System/Linq/AnyAll.cs +++ b/src/libraries/System.Linq/src/System/Linq/AnyAll.cs @@ -15,7 +15,7 @@ public static bool Any(this IEnumerable source) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source); } - if (source is IReadOnlyCollection gc) + if (source is ICollection gc) { return gc.Count != 0; } diff --git a/src/libraries/System.Linq/src/System/Linq/AppendPrepend.SpeedOpt.cs b/src/libraries/System.Linq/src/System/Linq/AppendPrepend.SpeedOpt.cs index cd6fb6fa171ad..01adb0af01e45 100644 --- a/src/libraries/System.Linq/src/System/Linq/AppendPrepend.SpeedOpt.cs +++ b/src/libraries/System.Linq/src/System/Linq/AppendPrepend.SpeedOpt.cs @@ -127,7 +127,7 @@ public override int GetCount(bool onlyIfCheap) return count == -1 ? -1 : count + 1; } - return !onlyIfCheap || _source is IReadOnlyCollection ? _source.Count() + 1 : -1; + return !onlyIfCheap || _source is ICollection ? _source.Count() + 1 : -1; } public override TSource? TryGetFirst(out bool found) @@ -276,7 +276,7 @@ public override int GetCount(bool onlyIfCheap) return count == -1 ? -1 : count + _appendCount + _prependCount; } - return !onlyIfCheap || _source is IReadOnlyCollection ? _source.Count() + _appendCount + _prependCount : -1; + return !onlyIfCheap || _source is ICollection ? _source.Count() + _appendCount + _prependCount : -1; } } } diff --git a/src/libraries/System.Linq/src/System/Linq/Count.cs b/src/libraries/System.Linq/src/System/Linq/Count.cs index 9b2511e0563c5..6b8819f8c3cbc 100644 --- a/src/libraries/System.Linq/src/System/Linq/Count.cs +++ b/src/libraries/System.Linq/src/System/Linq/Count.cs @@ -15,7 +15,7 @@ public static int Count(this IEnumerable source) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source); } - if (source is IReadOnlyCollection collectionoft) + if (source is ICollection collectionoft) { return collectionoft.Count; } @@ -101,7 +101,7 @@ public static bool TryGetNonEnumeratedCount(this IEnumerable s ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source); } - if (source is IReadOnlyCollection collectionoft) + if (source is ICollection collectionoft) { count = collectionoft.Count; return true; diff --git a/src/libraries/System.Linq/src/System/Linq/DefaultIfEmpty.SpeedOpt.cs b/src/libraries/System.Linq/src/System/Linq/DefaultIfEmpty.SpeedOpt.cs index 45f673f73486a..c89d6797581e9 100644 --- a/src/libraries/System.Linq/src/System/Linq/DefaultIfEmpty.SpeedOpt.cs +++ b/src/libraries/System.Linq/src/System/Linq/DefaultIfEmpty.SpeedOpt.cs @@ -30,7 +30,7 @@ public override List ToList() public override int GetCount(bool onlyIfCheap) { int count; - if (!onlyIfCheap || _source is IReadOnlyCollection || _source is ICollection) + if (!onlyIfCheap || _source is ICollection || _source is ICollection) { count = _source.Count(); } diff --git a/src/libraries/System.Linq/src/System/Linq/ElementAt.cs b/src/libraries/System.Linq/src/System/Linq/ElementAt.cs index 824a152a7764c..97b87f9eba999 100644 --- a/src/libraries/System.Linq/src/System/Linq/ElementAt.cs +++ b/src/libraries/System.Linq/src/System/Linq/ElementAt.cs @@ -16,7 +16,7 @@ public static TSource ElementAt(this IEnumerable source, int i ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source); } - if (source is IReadOnlyList list) + if (source is IList list) { return list[index]; } @@ -115,7 +115,7 @@ public static TSource ElementAt(this IEnumerable source, Index private static TSource? TryGetElementAt(this IEnumerable source, int index, out bool found) { - if (source is IReadOnlyList list) + if (source is IList list) { return (found = (uint)index < (uint)list.Count) ? list[index] : diff --git a/src/libraries/System.Linq/src/System/Linq/First.cs b/src/libraries/System.Linq/src/System/Linq/First.cs index 22532cdb18d13..74ff81c2fec83 100644 --- a/src/libraries/System.Linq/src/System/Linq/First.cs +++ b/src/libraries/System.Linq/src/System/Linq/First.cs @@ -78,7 +78,7 @@ public static TSource FirstOrDefault(this IEnumerable source, private static TSource? TryGetFirstNonIterator(IEnumerable source, out bool found) { - if (source is IReadOnlyList list) + if (source is IList list) { if (list.Count > 0) { diff --git a/src/libraries/System.Linq/src/System/Linq/Grouping.cs b/src/libraries/System.Linq/src/System/Linq/Grouping.cs index 47be36572acad..6e19e4ab384e4 100644 --- a/src/libraries/System.Linq/src/System/Linq/Grouping.cs +++ b/src/libraries/System.Linq/src/System/Linq/Grouping.cs @@ -351,7 +351,7 @@ public interface IGrouping : IEnumerable [DebuggerDisplay("Key = {Key}")] [DebuggerTypeProxy(typeof(SystemLinq_GroupingDebugView<,>))] - internal sealed class Grouping : IGrouping, IList, IReadOnlyList + internal sealed class Grouping : IGrouping, IList { internal readonly TKey _key; internal readonly int _hashCode; @@ -398,8 +398,6 @@ public IEnumerator GetEnumerator() int ICollection.Count => _count; - int IReadOnlyCollection.Count => _count; - bool ICollection.IsReadOnly => true; void ICollection.Add(TElement item) => ThrowHelper.ThrowNotSupportedException(); @@ -433,18 +431,5 @@ TElement IList.this[int index] set => ThrowHelper.ThrowNotSupportedException(); } - - TElement IReadOnlyList.this[int index] - { - get - { - if ((uint)index >= (uint)_count) - { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index); - } - - return _elements[index]; - } - } } } diff --git a/src/libraries/System.Linq/src/System/Linq/Last.cs b/src/libraries/System.Linq/src/System/Linq/Last.cs index e17e409e25e3f..007ee1659c3f5 100644 --- a/src/libraries/System.Linq/src/System/Linq/Last.cs +++ b/src/libraries/System.Linq/src/System/Linq/Last.cs @@ -77,7 +77,7 @@ public static TSource LastOrDefault(this IEnumerable source, F private static TSource? TryGetLastNonIterator(IEnumerable source, out bool found) { - if (source is IReadOnlyList list) + if (source is IList list) { int count = list.Count; if (count > 0) @@ -126,7 +126,7 @@ public static TSource LastOrDefault(this IEnumerable source, F return ordered.TryGetLast(predicate, out found); } - if (source is IReadOnlyList list) + if (source is IList list) { for (int i = list.Count - 1; i >= 0; --i) { diff --git a/src/libraries/System.Linq/src/System/Linq/OrderedEnumerable.SpeedOpt.cs b/src/libraries/System.Linq/src/System/Linq/OrderedEnumerable.SpeedOpt.cs index ac9225303b426..bf65a34b06efa 100644 --- a/src/libraries/System.Linq/src/System/Linq/OrderedEnumerable.SpeedOpt.cs +++ b/src/libraries/System.Linq/src/System/Linq/OrderedEnumerable.SpeedOpt.cs @@ -58,7 +58,7 @@ public override int GetCount(bool onlyIfCheap) return iterator.GetCount(onlyIfCheap); } - return !onlyIfCheap || _source is IReadOnlyCollection || _source is ICollection ? _source.Count() : -1; + return !onlyIfCheap || _source is ICollection || _source is ICollection ? _source.Count() : -1; } internal TElement[] ToArray(int minIdx, int maxIdx) diff --git a/src/libraries/System.Linq/src/System/Linq/Reverse.SpeedOpt.cs b/src/libraries/System.Linq/src/System/Linq/Reverse.SpeedOpt.cs index 168ca818c9611..d1ec26de879af 100644 --- a/src/libraries/System.Linq/src/System/Linq/Reverse.SpeedOpt.cs +++ b/src/libraries/System.Linq/src/System/Linq/Reverse.SpeedOpt.cs @@ -30,7 +30,7 @@ public override int GetCount(bool onlyIfCheap) => public override TSource? TryGetElementAt(int index, out bool found) { - if (_source is IReadOnlyList list) + if (_source is IList list) { int count = list.Count; if ((uint)index < (uint)count) @@ -59,7 +59,7 @@ public override int GetCount(bool onlyIfCheap) => { return iterator.TryGetLast(out found); } - else if (_source is IReadOnlyList list) + else if (_source is IList list) { int count = list.Count; if (count > 0) @@ -95,7 +95,7 @@ public override int GetCount(bool onlyIfCheap) => { return iterator.TryGetFirst(out found); } - else if (_source is IReadOnlyList list) + else if (_source is IList list) { if (list.Count > 0) { diff --git a/src/libraries/System.Linq/src/System/Linq/SequenceEqual.cs b/src/libraries/System.Linq/src/System/Linq/SequenceEqual.cs index 2568721f1ce16..16bf60e686145 100644 --- a/src/libraries/System.Linq/src/System/Linq/SequenceEqual.cs +++ b/src/libraries/System.Linq/src/System/Linq/SequenceEqual.cs @@ -22,7 +22,7 @@ public static bool SequenceEqual(this IEnumerable first, IEnum ThrowHelper.ThrowArgumentNullException(ExceptionArgument.second); } - if (first is IReadOnlyCollection firstCol && second is IReadOnlyCollection secondCol) + if (first is ICollection firstCol && second is ICollection secondCol) { if (first.TryGetSpan(out ReadOnlySpan firstSpan) && second.TryGetSpan(out ReadOnlySpan secondSpan)) { @@ -34,7 +34,7 @@ public static bool SequenceEqual(this IEnumerable first, IEnum return false; } - if (firstCol is IReadOnlyList firstList && secondCol is IReadOnlyList secondList) + if (firstCol is IList firstList && secondCol is IList secondList) { comparer ??= EqualityComparer.Default; diff --git a/src/libraries/System.Linq/src/System/Linq/Single.cs b/src/libraries/System.Linq/src/System/Linq/Single.cs index 78e548e680669..9c7328cc3ff16 100644 --- a/src/libraries/System.Linq/src/System/Linq/Single.cs +++ b/src/libraries/System.Linq/src/System/Linq/Single.cs @@ -69,7 +69,7 @@ public static TSource SingleOrDefault(this IEnumerable source, ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source); } - if (source is IReadOnlyList list) + if (source is IList list) { switch (list.Count) { diff --git a/src/libraries/System.Net.Security/src/System/Security/Authentication/ExtendedProtection/ServiceNameCollection.cs b/src/libraries/System.Net.Security/src/System/Security/Authentication/ExtendedProtection/ServiceNameCollection.cs index 4abe58873916a..532f6e950d6b0 100644 --- a/src/libraries/System.Net.Security/src/System/Security/Authentication/ExtendedProtection/ServiceNameCollection.cs +++ b/src/libraries/System.Net.Security/src/System/Security/Authentication/ExtendedProtection/ServiceNameCollection.cs @@ -147,7 +147,7 @@ private void AddIfNew(string serviceName) /// private static int GetCountOrOne(IEnumerable collection) { - IReadOnlyCollection? c = collection as IReadOnlyCollection; + ICollection? c = collection as ICollection; return c != null ? c.Count : 1; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueue.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueue.cs index 2eff1c59b12ec..bfa9fcf65469e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueue.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueue.cs @@ -89,7 +89,7 @@ public ConcurrentQueue(IEnumerable collection) // case we round its length up to a power of 2, as all segments must // be a power of 2 in length. int length = InitialSegmentLength; - if (collection is IReadOnlyCollection c) + if (collection is ICollection c) { int count = c.Count; if (count > length) diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs index f20e3c5cfee21..9b18d4a125ed2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs @@ -98,7 +98,7 @@ public Dictionary(IDictionary dictionary, IEqualityComparer? public Dictionary(IEnumerable> collection) : this(collection, null) { } public Dictionary(IEnumerable> collection, IEqualityComparer? comparer) : - this((collection as IReadOnlyCollection>)?.Count ?? 0, comparer) + this((collection as ICollection>)?.Count ?? 0, comparer) { if (collection == null) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/HashSet.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/HashSet.cs index 6467164d6becb..3b86548d20a7e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/HashSet.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/HashSet.cs @@ -99,7 +99,7 @@ public HashSet(IEnumerable collection, IEqualityComparer? comparer) : this { // To avoid excess resizes, first set size based on collection's count. The collection may // contain duplicates, so call TrimExcess if resulting HashSet is larger than the threshold. - if (collection is IReadOnlyCollection coll) + if (collection is ICollection coll) { int count = coll.Count; if (count > 0) @@ -513,7 +513,7 @@ public void IntersectWith(IEnumerable other) } // If other is known to be empty, intersection is empty set; remove all elements, and we're done. - if (other is IReadOnlyCollection otherAsCollection) + if (other is ICollection otherAsCollection) { if (otherAsCollection.Count == 0) { @@ -652,7 +652,7 @@ public bool IsProperSubsetOf(IEnumerable other) return false; } - if (other is IReadOnlyCollection otherAsCollection) + if (other is ICollection otherAsCollection) { // No set is a proper subset of an empty set. if (otherAsCollection.Count == 0) @@ -701,7 +701,7 @@ public bool IsSupersetOf(IEnumerable other) } // Try to fall out early based on counts. - if (other is IReadOnlyCollection otherAsCollection) + if (other is ICollection otherAsCollection) { // If other is the empty set then this is a superset. if (otherAsCollection.Count == 0) @@ -745,7 +745,7 @@ public bool IsProperSupersetOf(IEnumerable other) return false; } - if (other is IReadOnlyCollection otherAsCollection) + if (other is ICollection otherAsCollection) { // If other is the empty set then this is a superset. if (otherAsCollection.Count == 0) @@ -838,7 +838,7 @@ public bool SetEquals(IEnumerable other) { // If this count is 0 but other contains at least one element, they can't be equal. if (Count == 0 && - other is IReadOnlyCollection otherAsCollection && + other is ICollection otherAsCollection && otherAsCollection.Count > 0) { return false; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlQuerySequence.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlQuerySequence.cs index 23fc7a5c2e65a..3c7e5b6ad25c3 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlQuerySequence.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlQuerySequence.cs @@ -19,7 +19,7 @@ namespace System.Xml.Xsl.Runtime /// A sequence of Xml values that dynamically expands and allows random access to items. /// [EditorBrowsable(EditorBrowsableState.Never)] - public class XmlQuerySequence : IList, IReadOnlyList, System.Collections.IList + public class XmlQuerySequence : IList, System.Collections.IList { public static readonly XmlQuerySequence Empty = new XmlQuerySequence(); @@ -489,7 +489,7 @@ public void AddClone(XPathItem item) /// A sequence of Xml nodes that dynamically expands and allows random access to items. /// [EditorBrowsable(EditorBrowsableState.Never)] - public sealed class XmlQueryNodeSequence : XmlQuerySequence, IList, IReadOnlyList + public sealed class XmlQueryNodeSequence : XmlQuerySequence, IList { public static new readonly XmlQueryNodeSequence Empty = new XmlQueryNodeSequence(); @@ -731,19 +731,6 @@ XPathItem IList.this[int index] set { throw new NotSupportedException(); } } - /// - /// Return item at the specified index. - /// - XPathItem IReadOnlyList.this[int index] - { - get - { - ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(index, Count); - - return base[index]; - } - } - /// /// Returns the index of the specified value in the sequence. /// diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonObject.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonObject.cs index 021a4ac75b3c7..24f8653053af7 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonObject.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonObject.cs @@ -35,12 +35,7 @@ public JsonObject(IEnumerable> properties, JsonN { bool isCaseInsensitive = IsCaseInsensitive(options); - JsonPropertyDictionary dictionary = -#if NET9_0_OR_GREATER // ICollection : IReadOnlyCollection on .NET 9+ - properties is IReadOnlyCollection> propertiesCollection -#else - properties is ICollection> propertiesCollection -#endif + JsonPropertyDictionary dictionary = properties is ICollection> propertiesCollection ? new(isCaseInsensitive, propertiesCollection.Count) : new(isCaseInsensitive); From 096d59dc3b13474040bc99291da4244170460bed Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Sat, 27 Apr 2024 07:21:55 -0700 Subject: [PATCH 2/3] Revert "Make mutable generic collection interfaces implement read-only collection interfaces (#95830)" This reverts commit a2bd5830ce09cd81d834afd5571bc6c9e5ad879b. --- .../src/System/Array.CoreCLR.cs | 2 +- src/coreclr/vm/array.cpp | 19 +- .../System/Collections/CollectionAsserts.cs | 152 --------------- .../Collections/ICollection.Generic.Tests.cs | 43 ++--- .../Collections/IDictionary.Generic.Tests.cs | 180 +++--------------- .../System/Collections/IList.Generic.Tests.cs | 75 ++++---- .../System/Collections/ISet.Generic.Tests.cs | 53 +++--- .../Generic/CollectionExtensionsTests.cs | 12 -- .../System/Collections/Generic/ICollection.cs | 6 +- .../System/Collections/Generic/IDictionary.cs | 22 +-- .../src/System/Collections/Generic/IList.cs | 6 +- .../src/System/Collections/Generic/ISet.cs | 35 +--- .../System.Runtime/ref/System.Runtime.cs | 49 ++--- 13 files changed, 164 insertions(+), 490 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs index 74e0739848168..de7b3021c458f 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs @@ -694,7 +694,7 @@ public ArrayInitializeCache(RuntimeType arrayType) // it for type and executes it. // // The "T" will reflect the interface used to invoke the method. The actual runtime "this" will be - // array that is castable to "T[]" (i.e. for primitives and valuetypes, it will be exactly + // array that is castable to "T[]" (i.e. for primitivs and valuetypes, it will be exactly // "T[]" - for orefs, it may be a "U[]" where U derives from T.) //---------------------------------------------------------------------------------------- internal sealed class SZArrayHelper diff --git a/src/coreclr/vm/array.cpp b/src/coreclr/vm/array.cpp index e1e2b31e4df64..ffb6e6def99ce 100644 --- a/src/coreclr/vm/array.cpp +++ b/src/coreclr/vm/array.cpp @@ -1210,14 +1210,29 @@ MethodDesc* GetActualImplementationForArrayGenericIListOrIReadOnlyListMethod(Met } CONTRACTL_END + int slot = pItfcMeth->GetSlot(); + + // We need to pick the right starting method depending on the depth of the inheritance chain + static const BinderMethodID startingMethod[] = { + METHOD__SZARRAYHELPER__GETENUMERATOR, // First method of IEnumerable`1 + METHOD__SZARRAYHELPER__GET_COUNT, // First method of ICollection`1/IReadOnlyCollection`1 + METHOD__SZARRAYHELPER__GET_ITEM // First method of IList`1/IReadOnlyList`1 + }; + // Subtract one for the non-generic IEnumerable that the generic enumerable inherits from unsigned int inheritanceDepth = pItfcMeth->GetMethodTable()->GetNumInterfaces() - 1; + PREFIX_ASSUME(0 <= inheritanceDepth && inheritanceDepth < ARRAY_SIZE(startingMethod)); + + MethodDesc *pGenericImplementor = CoreLibBinder::GetMethod((BinderMethodID)(startingMethod[inheritanceDepth] + slot)); - MethodDesc *pGenericImplementor = MemberLoader::FindMethodByName(g_pSZArrayHelperClass, pItfcMeth->GetName()); + // The most common reason for this assert is that the order of the SZArrayHelper methods in + // corelib.h does not match the order they are implemented on the generic interfaces. + _ASSERTE(pGenericImplementor == MemberLoader::FindMethodByName(g_pSZArrayHelperClass, pItfcMeth->GetName())); // OPTIMIZATION: For any method other than GetEnumerator(), we can safely substitute // "Object" for reference-type theT's. This causes fewer methods to be instantiated. - if (inheritanceDepth != 0 && !theT.IsValueType()) + if (startingMethod[inheritanceDepth] != METHOD__SZARRAYHELPER__GETENUMERATOR && + !theT.IsValueType()) { theT = TypeHandle(g_pObjectClass); } diff --git a/src/libraries/Common/tests/System/Collections/CollectionAsserts.cs b/src/libraries/Common/tests/System/Collections/CollectionAsserts.cs index 1e76d40ebb411..2de26be1737fd 100644 --- a/src/libraries/Common/tests/System/Collections/CollectionAsserts.cs +++ b/src/libraries/Common/tests/System/Collections/CollectionAsserts.cs @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System; using System.Collections.Generic; using System.Linq; using Xunit; @@ -10,151 +9,6 @@ namespace System.Collections.Tests { internal static class CollectionAsserts { - public static void HasCount(ICollection collection, int count) - { - Assert.Equal(count, collection.Count); -#if !NETFRAMEWORK - IReadOnlyCollection readOnlyCollection = collection; - Assert.Equal(count, readOnlyCollection.Count); -#endif - } - - public static void EqualAt(IList list, int index, T expected) - { - Assert.Equal(expected, list[index]); -#if !NETFRAMEWORK - IReadOnlyList readOnlyList = list; - Assert.Equal(expected, readOnlyList[index]); -#endif - } - - public static void NotEqualAt(IList list, int index, T expected) - { - Assert.NotEqual(expected, list[index]); -#if !NETFRAMEWORK - IReadOnlyList readOnlyList = list; - Assert.NotEqual(expected, readOnlyList[index]); -#endif - } - - public static void ThrowsElementAt(IList list, int index, Type exceptionType) - { - Assert.Throws(exceptionType, () => list[index]); -#if !NETFRAMEWORK - IReadOnlyList readOnlyList = list; - Assert.Throws(exceptionType, () => readOnlyList[index]); -#endif - } - - public static void ElementAtSucceeds(IList list, int index) - { - T result = list[index]; -#if !NETFRAMEWORK - IReadOnlyList readOnlyList = list; - Assert.Equal(result, readOnlyList[index]); -#endif - } - - public static void EqualAt(IDictionary dictionary, TKey key, TValue expected) - { - Assert.Equal(expected, dictionary[key]); -#if !NETFRAMEWORK - IReadOnlyDictionary readOnlyDictionary = dictionary; - Assert.Equal(expected, readOnlyDictionary[key]); -#endif - } - - public static void ContainsKey(IDictionary dictionary, TKey key, bool expected) - { - Assert.Equal(expected, dictionary.ContainsKey(key)); -#if !NETFRAMEWORK - IReadOnlyDictionary readOnlyDictionary = dictionary; - Assert.Equal(expected, readOnlyDictionary.ContainsKey(key)); -#endif - } - - public static void TryGetValue(IDictionary dictionary, TKey key, bool expected, TValue expectedValue = default) - { - Assert.Equal(expected, dictionary.TryGetValue(key, out TValue value)); - if (expected) - { - Assert.Equal(expectedValue, value); - } -#if !NETFRAMEWORK - IReadOnlyDictionary readOnlyDictionary = dictionary; - Assert.Equal(expected, readOnlyDictionary.TryGetValue(key, out value)); - if (expected) - { - Assert.Equal(expectedValue, value); - } -#endif - } - - public static void Contains(ISet set, T expected) - { - Assert.True(set.Contains(expected)); -#if !NETFRAMEWORK - ICollection collection = set; - Assert.True(collection.Contains(expected)); - IReadOnlySet readOnlySet = set; - Assert.True(readOnlySet.Contains(expected)); -#endif - } - - public static void IsProperSubsetOf(ISet set, IEnumerable enumerable, bool expected) - { - Assert.Equal(expected, set.IsProperSubsetOf(enumerable)); -#if !NETFRAMEWORK - IReadOnlySet readOnlySet = set; - Assert.Equal(expected, readOnlySet.IsProperSubsetOf(enumerable)); -#endif - } - - public static void IsProperSupersetOf(ISet set, IEnumerable enumerable, bool expected) - { - Assert.Equal(expected, set.IsProperSupersetOf(enumerable)); -#if !NETFRAMEWORK - IReadOnlySet readOnlySet = set; - Assert.Equal(expected, readOnlySet.IsProperSupersetOf(enumerable)); -#endif - } - - public static void IsSubsetOf(ISet set, IEnumerable enumerable, bool expected) - { - Assert.Equal(expected, set.IsSubsetOf(enumerable)); -#if !NETFRAMEWORK - IReadOnlySet readOnlySet = set; - Assert.Equal(expected, readOnlySet.IsSubsetOf(enumerable)); -#endif - } - - public static void IsSupersetOf(ISet set, IEnumerable enumerable, bool expected) - { - Assert.Equal(expected, set.IsSupersetOf(enumerable)); -#if !NETFRAMEWORK - IReadOnlySet readOnlySet = set; - Assert.Equal(expected, readOnlySet.IsSupersetOf(enumerable)); -#endif - } - - public static void Overlaps(ISet set, IEnumerable enumerable, bool expected) - { - Assert.Equal(expected, set.Overlaps(enumerable)); -#if !NETFRAMEWORK - IReadOnlySet readOnlySet = set; - Assert.Equal(expected, readOnlySet.Overlaps(enumerable)); -#endif - } - - public static void SetEquals(ISet set, IEnumerable enumerable, bool expected) - { - Assert.Equal(expected, set.SetEquals(enumerable)); -#if !NETFRAMEWORK - IReadOnlySet readOnlySet = set; - Assert.Equal(expected, readOnlySet.SetEquals(enumerable)); -#endif - } - public static void Equal(ICollection expected, ICollection actual) { Assert.Equal(expected == null, actual == null); @@ -189,12 +43,6 @@ public static void Equal(ICollection expected, ICollection actual) return; } Assert.Equal(expected.Count, actual.Count); -#if !NETFRAMEWORK - IReadOnlyCollection readOnlyExpected = expected; - Assert.Equal(expected.Count, readOnlyExpected.Count); - IReadOnlyCollection readOnlyActual = actual; - Assert.Equal(actual.Count, readOnlyActual.Count); -#endif IEnumerator e = expected.GetEnumerator(); IEnumerator a = actual.GetEnumerator(); while (e.MoveNext()) diff --git a/src/libraries/Common/tests/System/Collections/ICollection.Generic.Tests.cs b/src/libraries/Common/tests/System/Collections/ICollection.Generic.Tests.cs index 8ae72dea074ab..a94a9308b99ab 100644 --- a/src/libraries/Common/tests/System/Collections/ICollection.Generic.Tests.cs +++ b/src/libraries/Common/tests/System/Collections/ICollection.Generic.Tests.cs @@ -130,7 +130,7 @@ public void ICollection_Generic_IsReadOnly_Validity(int count) public void ICollection_Generic_Count_Validity(int count) { ICollection collection = GenericICollectionFactory(count); - CollectionAsserts.HasCount(collection, count); + Assert.Equal(count, collection.Count); } #endregion @@ -145,7 +145,7 @@ public virtual void ICollection_Generic_Add_DefaultValue(int count) { ICollection collection = GenericICollectionFactory(count); collection.Add(default(T)); - CollectionAsserts.HasCount(collection, count + 1); + Assert.Equal(count + 1, collection.Count); } } @@ -161,7 +161,7 @@ public void ICollection_Generic_Add_InvalidValueToMiddleOfCollection(int count) collection.Add(invalidValue); for (int i = 0; i < count; i++) collection.Add(CreateT(i)); - CollectionAsserts.HasCount(collection, count * 2); + Assert.Equal(count * 2, collection.Count); }); } } @@ -178,7 +178,7 @@ public void ICollection_Generic_Add_InvalidValueToBeginningOfCollection(int coun collection.Add(invalidValue); for (int i = 0; i < count; i++) collection.Add(CreateT(i)); - CollectionAsserts.HasCount(collection, count); + Assert.Equal(count, collection.Count); }); } } @@ -192,9 +192,8 @@ public void ICollection_Generic_Add_InvalidValueToEndOfCollection(int count) Assert.All(InvalidValues, invalidValue => { ICollection collection = GenericICollectionFactory(count); - collection.Add(invalidValue); - CollectionAsserts.HasCount(collection, count); + Assert.Equal(count, collection.Count); }); } } @@ -209,7 +208,7 @@ public void ICollection_Generic_Add_DuplicateValue(int count) T duplicateValue = CreateT(700); collection.Add(duplicateValue); collection.Add(duplicateValue); - CollectionAsserts.HasCount(collection, count + 2); + Assert.Equal(count + 2, collection.Count); } } @@ -222,7 +221,7 @@ public void ICollection_Generic_Add_AfterCallingClear(int count) ICollection collection = GenericICollectionFactory(count); collection.Clear(); AddToCollection(collection, 5); - CollectionAsserts.HasCount(collection, 5); + Assert.Equal(5, collection.Count); } } @@ -262,7 +261,7 @@ public void ICollection_Generic_Add_AfterRemovingAllItems(int count) for (int i = 0; i < count; i++) collection.Remove(collection.ElementAt(0)); collection.Add(CreateT(254)); - CollectionAsserts.HasCount(collection, 1); + Assert.Equal(1, collection.Count); } } @@ -274,7 +273,7 @@ public void ICollection_Generic_Add_ToReadOnlyCollection(int count) { ICollection collection = GenericICollectionFactory(count); Assert.Throws(() => collection.Add(CreateT(0))); - CollectionAsserts.HasCount(collection, count); + Assert.Equal(count, collection.Count); } } @@ -307,12 +306,12 @@ public void ICollection_Generic_Clear(int count) if (IsReadOnly || AddRemoveClear_ThrowsNotSupported) { Assert.Throws(() => collection.Clear()); - CollectionAsserts.HasCount(collection, count); + Assert.Equal(count, collection.Count); } else { collection.Clear(); - CollectionAsserts.HasCount(collection, 0); + Assert.Equal(0, collection.Count); } } @@ -326,14 +325,14 @@ public void ICollection_Generic_Clear_Repeatedly(int count) Assert.Throws(() => collection.Clear()); Assert.Throws(() => collection.Clear()); Assert.Throws(() => collection.Clear()); - CollectionAsserts.HasCount(collection, count); + Assert.Equal(count, collection.Count); } else { collection.Clear(); collection.Clear(); collection.Clear(); - CollectionAsserts.HasCount(collection, 0); + Assert.Equal(0, collection.Count); } } @@ -435,7 +434,7 @@ public void ICollection_Generic_Contains_ValidValueThatExistsTwiceInTheCollectio T item = CreateT(12); collection.Add(item); collection.Add(item); - CollectionAsserts.HasCount(collection, count + 2); + Assert.Equal(count + 2, collection.Count); } } @@ -568,7 +567,7 @@ public void ICollection_Generic_Remove_DefaultValueNotContainedInCollection(int count--; } Assert.False(collection.Remove(value)); - CollectionAsserts.HasCount(collection, count); + Assert.Equal(count, collection.Count); } } @@ -584,7 +583,7 @@ public void ICollection_Generic_Remove_NonDefaultValueNotContainedInCollection(i while (collection.Contains(value) || Enumerable.Contains(InvalidValues, value)) value = CreateT(seed++); Assert.False(collection.Remove(value)); - CollectionAsserts.HasCount(collection, count); + Assert.Equal(count, collection.Count); } } @@ -603,7 +602,7 @@ public virtual void ICollection_Generic_Remove_DefaultValueContainedInCollection count++; } Assert.True(collection.Remove(value)); - CollectionAsserts.HasCount(collection, count - 1); + Assert.Equal(count - 1, collection.Count); } } @@ -622,7 +621,7 @@ public void ICollection_Generic_Remove_NonDefaultValueContainedInCollection(int count++; } Assert.True(collection.Remove(value)); - CollectionAsserts.HasCount(collection, count - 1); + Assert.Equal(count - 1, collection.Count); } } @@ -640,7 +639,7 @@ public void ICollection_Generic_Remove_ValueThatExistsTwiceInCollection(int coun count += 2; Assert.True(collection.Remove(value)); Assert.True(collection.Contains(value)); - CollectionAsserts.HasCount(collection, count - 1); + Assert.Equal(count - 1, collection.Count); } } @@ -655,7 +654,7 @@ public void ICollection_Generic_Remove_EveryValue(int count) { Assert.True(collection.Remove(value)); }); - CollectionAsserts.HasCount(collection, 0); + Assert.Empty(collection); } } @@ -668,7 +667,7 @@ public void ICollection_Generic_Remove_InvalidValue_ThrowsArgumentException(int { Assert.Throws(() => collection.Remove(value)); }); - CollectionAsserts.HasCount(collection, count); + Assert.Equal(count, collection.Count); } [Theory] diff --git a/src/libraries/Common/tests/System/Collections/IDictionary.Generic.Tests.cs b/src/libraries/Common/tests/System/Collections/IDictionary.Generic.Tests.cs index e6311ec89b4fc..df92ab206f668 100644 --- a/src/libraries/Common/tests/System/Collections/IDictionary.Generic.Tests.cs +++ b/src/libraries/Common/tests/System/Collections/IDictionary.Generic.Tests.cs @@ -266,16 +266,12 @@ public void IDictionary_Generic_ItemGet_DefaultKey(int count) if (!DefaultValueAllowed) { Assert.Throws(() => dictionary[default(TKey)]); -#if !NETFRAMEWORK - IReadOnlyDictionary readOnlyDictionary = dictionary; - Assert.Throws(() => readOnlyDictionary[default(TKey)]); -#endif } else { TValue value = CreateTValue(3452); dictionary[default(TKey)] = value; - CollectionAsserts.EqualAt(dictionary, default(TKey), value); + Assert.Equal(value, dictionary[default(TKey)]); } } } @@ -287,10 +283,6 @@ public void IDictionary_Generic_ItemGet_MissingNonDefaultKey_ThrowsKeyNotFoundEx IDictionary dictionary = GenericIDictionaryFactory(count); TKey missingKey = GetNewKey(dictionary); Assert.Throws(() => dictionary[missingKey]); -#if !NETFRAMEWORK - IReadOnlyDictionary readOnlyDictionary = dictionary; - Assert.Throws(() => readOnlyDictionary[missingKey]); -#endif } [Theory] @@ -304,10 +296,6 @@ public void IDictionary_Generic_ItemGet_MissingDefaultKey_ThrowsKeyNotFoundExcep while (dictionary.ContainsKey(missingKey)) dictionary.Remove(missingKey); Assert.Throws(() => dictionary[missingKey]); -#if !NETFRAMEWORK - IReadOnlyDictionary readOnlyDictionary = dictionary; - Assert.Throws(() => readOnlyDictionary[missingKey]); -#endif } } @@ -318,7 +306,7 @@ public void IDictionary_Generic_ItemGet_PresentKeyReturnsCorrectValue(int count) IDictionary dictionary = GenericIDictionaryFactory(count); foreach (KeyValuePair pair in dictionary) { - CollectionAsserts.EqualAt(dictionary, pair.Key, pair.Value); + Assert.Equal(pair.Value, dictionary[pair.Key]); } } @@ -341,7 +329,7 @@ public void IDictionary_Generic_ItemSet_DefaultKey(int count) { TValue value = CreateTValue(3452); dictionary[default(TKey)] = value; - CollectionAsserts.EqualAt(dictionary, default(TKey), value); + Assert.Equal(value, dictionary[default(TKey)]); } } } @@ -367,7 +355,7 @@ public void IDictionary_Generic_ItemSet_AddsNewValueWhenNotPresent(int count) IDictionary dictionary = GenericIDictionaryFactory(count); TKey missingKey = GetNewKey(dictionary); dictionary[missingKey] = CreateTValue(543); - CollectionAsserts.HasCount(dictionary, count + 1); + Assert.Equal(count + 1, dictionary.Count); } } @@ -382,8 +370,8 @@ public void IDictionary_Generic_ItemSet_ReplacesExistingValueWhenPresent(int cou dictionary.Add(existingKey, CreateTValue(5342)); TValue newValue = CreateTValue(1234); dictionary[existingKey] = newValue; - CollectionAsserts.HasCount(dictionary, count + 1); - CollectionAsserts.EqualAt(dictionary, existingKey, newValue); + Assert.Equal(count + 1, dictionary.Count); + Assert.Equal(newValue, dictionary[existingKey]); } } @@ -398,10 +386,6 @@ public void IDictionary_Generic_Keys_ContainsAllCorrectKeys(int count) IDictionary dictionary = GenericIDictionaryFactory(count); IEnumerable expected = dictionary.Select((pair) => pair.Key); Assert.True(expected.SequenceEqual(dictionary.Keys)); -#if !NETFRAMEWORK - IReadOnlyDictionary readOnlyDictionary = dictionary; - Assert.True(expected.SequenceEqual(readOnlyDictionary.Keys)); -#endif } [Theory] @@ -412,10 +396,6 @@ public void IDictionary_Generic_Keys_ModifyingTheDictionaryUpdatesTheCollection( { IDictionary dictionary = GenericIDictionaryFactory(count); ICollection keys = dictionary.Keys; -#if !NETFRAMEWORK - IReadOnlyDictionary readOnlyDictionary = dictionary; - IEnumerable readOnlyKeys = readOnlyDictionary.Keys; -#endif int previousCount = keys.Count; if (count > 0) Assert.NotEmpty(keys); @@ -423,16 +403,10 @@ public void IDictionary_Generic_Keys_ModifyingTheDictionaryUpdatesTheCollection( if (IDictionary_Generic_Keys_Values_ModifyingTheDictionaryUpdatesTheCollection) { Assert.Empty(keys); -#if !NETFRAMEWORK - Assert.Empty(readOnlyKeys); -#endif } else { Assert.Equal(previousCount, keys.Count); -#if !NETFRAMEWORK - Assert.Equal(previousCount, readOnlyKeys.Count()); -#endif } } } @@ -446,20 +420,11 @@ public void IDictionary_Generic_Keys_Enumeration_ParentDictionaryModifiedInvalid IDictionary dictionary = GenericIDictionaryFactory(count); ICollection keys = dictionary.Keys; IEnumerator keysEnum = keys.GetEnumerator(); -#if !NETFRAMEWORK - IReadOnlyDictionary readOnlyDictionary = dictionary; - IEnumerable readOnlyKeys = readOnlyDictionary.Keys; - IEnumerator readOnlyKeysEnum = readOnlyKeys.GetEnumerator(); -#endif dictionary.Add(GetNewKey(dictionary), CreateTValue(3432)); if (count == 0 ? Enumerator_Empty_ModifiedDuringEnumeration_ThrowsInvalidOperationException : IDictionary_Generic_Keys_Values_Enumeration_ThrowsInvalidOperation_WhenParentModified) { Assert.Throws(() => keysEnum.MoveNext()); Assert.Throws(() => keysEnum.Reset()); -#if !NETFRAMEWORK - Assert.Throws(() => readOnlyKeysEnum.MoveNext()); - Assert.Throws(() => readOnlyKeysEnum.Reset()); -#endif } else { @@ -468,13 +433,6 @@ public void IDictionary_Generic_Keys_Enumeration_ParentDictionaryModifiedInvalid _ = keysEnum.Current; } keysEnum.Reset(); -#if !NETFRAMEWORK - if (readOnlyKeysEnum.MoveNext()) - { - _ = readOnlyKeysEnum.Current; - } - readOnlyKeysEnum.Reset(); -#endif } } } @@ -498,25 +456,10 @@ public void IDictionary_Generic_Keys_Enumeration_Reset(int count) IDictionary dictionary = GenericIDictionaryFactory(count); ICollection keys = dictionary.Keys; IEnumerator enumerator = keys.GetEnumerator(); -#if !NETFRAMEWORK - IReadOnlyDictionary readOnlyDictionary = dictionary; - IEnumerable readOnlyKeys = readOnlyDictionary.Keys; - IEnumerator readOnlyEnumerator = readOnlyKeys.GetEnumerator(); -#endif if (IDictionary_Generic_Keys_Values_Enumeration_ResetImplemented) - { enumerator.Reset(); -#if !NETFRAMEWORK - readOnlyEnumerator.Reset(); -#endif - } else - { Assert.Throws(() => enumerator.Reset()); -#if !NETFRAMEWORK - Assert.Throws(() => readOnlyEnumerator.Reset()); -#endif - } } #endregion @@ -530,10 +473,6 @@ public void IDictionary_Generic_Values_ContainsAllCorrectValues(int count) IDictionary dictionary = GenericIDictionaryFactory(count); IEnumerable expected = dictionary.Select((pair) => pair.Value); Assert.True(expected.SequenceEqual(dictionary.Values)); -#if !NETFRAMEWORK - IReadOnlyDictionary readOnlyDictionary = dictionary; - Assert.True(expected.SequenceEqual(readOnlyDictionary.Values)); -#endif } [Theory] @@ -552,10 +491,6 @@ public void IDictionary_Generic_Values_IncludeDuplicatesMultipleTimes(int count) dictionary.Add(missingKey, pair.Value); } Assert.Equal(count * 2, dictionary.Values.Count); -#if !NETFRAMEWORK - IReadOnlyDictionary readOnlyDictionary = dictionary; - Assert.Equal(count * 2, readOnlyDictionary.Values.Count()); -#endif } } @@ -565,18 +500,9 @@ public void IDictionary_Generic_Values_ModifyingTheDictionaryUpdatesTheCollectio { IDictionary dictionary = GenericIDictionaryFactory(count); ICollection values = dictionary.Values; -#if !NETFRAMEWORK - IReadOnlyDictionary readOnlyDictionary = dictionary; - IEnumerable readOnlyValues = readOnlyDictionary.Values; -#endif int previousCount = values.Count; if (count > 0) - { Assert.NotEmpty(values); -#if !NETFRAMEWORK - Assert.NotEmpty(readOnlyValues); -#endif - } if (!IsReadOnly) { @@ -584,16 +510,10 @@ public void IDictionary_Generic_Values_ModifyingTheDictionaryUpdatesTheCollectio if (IDictionary_Generic_Keys_Values_ModifyingTheDictionaryUpdatesTheCollection) { Assert.Empty(values); -#if !NETFRAMEWORK - Assert.Empty(readOnlyValues); -#endif } else { Assert.Equal(previousCount, values.Count); -#if !NETFRAMEWORK - Assert.Equal(previousCount, readOnlyValues.Count()); -#endif } } } @@ -607,20 +527,11 @@ public void IDictionary_Generic_Values_Enumeration_ParentDictionaryModifiedInval IDictionary dictionary = GenericIDictionaryFactory(count); ICollection values = dictionary.Values; IEnumerator valuesEnum = values.GetEnumerator(); -#if !NETFRAMEWORK - IReadOnlyDictionary readOnlyDictionary = dictionary; - IEnumerable readOnlyValues = readOnlyDictionary.Values; - IEnumerator readOnlyValuesEnum = readOnlyValues.GetEnumerator(); -#endif dictionary.Add(GetNewKey(dictionary), CreateTValue(3432)); if (count == 0 ? Enumerator_Empty_ModifiedDuringEnumeration_ThrowsInvalidOperationException : IDictionary_Generic_Keys_Values_Enumeration_ThrowsInvalidOperation_WhenParentModified) { Assert.Throws(() => valuesEnum.MoveNext()); Assert.Throws(() => valuesEnum.Reset()); -#if !NETFRAMEWORK - Assert.Throws(() => readOnlyValuesEnum.MoveNext()); - Assert.Throws(() => readOnlyValuesEnum.Reset()); -#endif } else { @@ -629,13 +540,6 @@ public void IDictionary_Generic_Values_Enumeration_ParentDictionaryModifiedInval _ = valuesEnum.Current; } valuesEnum.Reset(); -#if !NETFRAMEWORK - if (readOnlyValuesEnum.MoveNext()) - { - _ = readOnlyValuesEnum.Current; - } - readOnlyValuesEnum.Reset(); -#endif } } } @@ -659,25 +563,10 @@ public void IDictionary_Generic_Values_Enumeration_Reset(int count) IDictionary dictionary = GenericIDictionaryFactory(count); ICollection values = dictionary.Values; IEnumerator enumerator = values.GetEnumerator(); -#if !NETFRAMEWORK - IReadOnlyDictionary readOnlyDictionary = dictionary; - IEnumerable readOnlyValues = readOnlyDictionary.Values; - IEnumerator readOnlyEnumerator = readOnlyValues.GetEnumerator(); -#endif if (IDictionary_Generic_Keys_Values_Enumeration_ResetImplemented) - { enumerator.Reset(); -#if !NETFRAMEWORK - readOnlyEnumerator.Reset(); -#endif - } else - { Assert.Throws(() => enumerator.Reset()); -#if !NETFRAMEWORK - Assert.Throws(() => readOnlyEnumerator.Reset()); -#endif - } } #endregion @@ -705,8 +594,8 @@ public void IDictionary_Generic_Add_DefaultKey_DefaultValue(int count) if (DefaultValueAllowed && !IsReadOnly) { dictionary.Add(missingKey, value); - CollectionAsserts.HasCount(dictionary, count + 1); - CollectionAsserts.EqualAt(dictionary, missingKey, value); + Assert.Equal(count + 1, dictionary.Count); + Assert.Equal(value, dictionary[missingKey]); } else if (!IsReadOnly) { @@ -724,8 +613,8 @@ public void IDictionary_Generic_Add_DefaultKey_NonDefaultValue(int count) if (DefaultValueAllowed && !IsReadOnly) { dictionary.Add(missingKey, value); - CollectionAsserts.HasCount(dictionary, count + 1); - CollectionAsserts.EqualAt(dictionary, missingKey, value); + Assert.Equal(count + 1, dictionary.Count); + Assert.Equal(value, dictionary[missingKey]); } else if (!IsReadOnly) { @@ -743,8 +632,8 @@ public void IDictionary_Generic_Add_NonDefaultKey_DefaultValue(int count) TKey missingKey = GetNewKey(dictionary); TValue value = default(TValue); dictionary.Add(missingKey, value); - CollectionAsserts.HasCount(dictionary, count + 1); - CollectionAsserts.EqualAt(dictionary, missingKey, value); + Assert.Equal(count + 1, dictionary.Count); + Assert.Equal(value, dictionary[missingKey]); } } @@ -758,8 +647,8 @@ public void IDictionary_Generic_Add_NonDefaultKey_NonDefaultValue(int count) TKey missingKey = GetNewKey(dictionary); TValue value = CreateTValue(1342); dictionary.Add(missingKey, value); - CollectionAsserts.HasCount(dictionary, count + 1); - CollectionAsserts.EqualAt(dictionary, missingKey, value); + Assert.Equal(count + 1, dictionary.Count); + Assert.Equal(value, dictionary[missingKey]); } } @@ -777,10 +666,6 @@ public void IDictionary_Generic_Add_DuplicateValue(int count) dictionary.Add(GetNewKey(dictionary), duplicate); dictionary.Add(GetNewKey(dictionary), duplicate); Assert.Equal(2, dictionary.Values.Count((value) => value.Equals(duplicate))); -#if !NETFRAMEWORK - IReadOnlyDictionary readOnlyDictionary = dictionary; - Assert.Equal(2, readOnlyDictionary.Values.Count((value) => value.Equals(duplicate))); -#endif } } @@ -807,7 +692,7 @@ public void IDictionary_Generic_Add_DistinctValuesWithHashCollisions(int count) if (dictionary != null) { AddToCollection(dictionary, count); - CollectionAsserts.HasCount(dictionary, count); + Assert.Equal(count, dictionary.Count); } } } @@ -824,7 +709,7 @@ public void IDictionary_Generic_ContainsKey_ValidKeyNotContainedInDictionary(int { IDictionary dictionary = GenericIDictionaryFactory(count); TKey missingKey = GetNewKey(dictionary); - CollectionAsserts.ContainsKey(dictionary, missingKey, false); + Assert.False(dictionary.ContainsKey(missingKey)); } } @@ -837,7 +722,7 @@ public void IDictionary_Generic_ContainsKey_ValidKeyContainedInDictionary(int co IDictionary dictionary = GenericIDictionaryFactory(count); TKey missingKey = GetNewKey(dictionary); dictionary.Add(missingKey, CreateTValue(34251)); - CollectionAsserts.ContainsKey(dictionary, missingKey, true); + Assert.True(dictionary.ContainsKey(missingKey)); } } @@ -854,17 +739,13 @@ public void IDictionary_Generic_ContainsKey_DefaultKeyNotContainedInDictionary(i TKey missingKey = default(TKey); while (dictionary.ContainsKey(missingKey)) dictionary.Remove(missingKey); - CollectionAsserts.ContainsKey(dictionary, missingKey, false); + Assert.False(dictionary.ContainsKey(missingKey)); } } else { // throws ArgumentNullException Assert.Throws(() => dictionary.ContainsKey(default(TKey))); -#if !NETFRAMEWORK - IReadOnlyDictionary readOnlyDictionary = dictionary; - Assert.Throws(() => readOnlyDictionary.ContainsKey(default(TKey))); -#endif } } @@ -878,7 +759,7 @@ public void IDictionary_Generic_ContainsKey_DefaultKeyContainedInDictionary(int TKey missingKey = default(TKey); if (!dictionary.ContainsKey(missingKey)) dictionary.Add(missingKey, CreateTValue(5341)); - CollectionAsserts.ContainsKey(dictionary, missingKey, true); + Assert.True(dictionary.ContainsKey(missingKey)); } } @@ -908,7 +789,7 @@ public void IDictionary_Generic_RemoveKey_EveryKey(int count) { Assert.True(dictionary.Remove(key)); }); - CollectionAsserts.HasCount(dictionary, 0); + Assert.Empty(dictionary); } } @@ -921,7 +802,7 @@ public void IDictionary_Generic_RemoveKey_ValidKeyNotContainedInDictionary(int c IDictionary dictionary = GenericIDictionaryFactory(count); TKey missingKey = GetNewKey(dictionary); Assert.False(dictionary.Remove(missingKey)); - CollectionAsserts.HasCount(dictionary, count); + Assert.Equal(count, dictionary.Count); } } @@ -935,7 +816,7 @@ public void IDictionary_Generic_RemoveKey_ValidKeyContainedInDictionary(int coun TKey missingKey = GetNewKey(dictionary); dictionary.Add(missingKey, CreateTValue(34251)); Assert.True(dictionary.Remove(missingKey)); - CollectionAsserts.HasCount(dictionary, count); + Assert.Equal(count, dictionary.Count); } } @@ -1028,7 +909,8 @@ public void IDictionary_Generic_TryGetValue_ValidKeyNotContainedInDictionary(int IDictionary dictionary = GenericIDictionaryFactory(count); TKey missingKey = GetNewKey(dictionary); TValue value = CreateTValue(5123); - CollectionAsserts.TryGetValue(dictionary, missingKey, false); + TValue outValue; + Assert.False(dictionary.TryGetValue(missingKey, out outValue)); } [Theory] @@ -1040,8 +922,10 @@ public void IDictionary_Generic_TryGetValue_ValidKeyContainedInDictionary(int co IDictionary dictionary = GenericIDictionaryFactory(count); TKey missingKey = GetNewKey(dictionary); TValue value = CreateTValue(5123); + TValue outValue; dictionary.TryAdd(missingKey, value); - CollectionAsserts.TryGetValue(dictionary, missingKey, true, value); + Assert.True(dictionary.TryGetValue(missingKey, out outValue)); + Assert.Equal(value, outValue); } } @@ -1058,16 +942,12 @@ public void IDictionary_Generic_TryGetValue_DefaultKeyNotContainedInDictionary(i TKey missingKey = default(TKey); while (dictionary.ContainsKey(missingKey)) dictionary.Remove(missingKey); - CollectionAsserts.TryGetValue(dictionary, missingKey, false); + Assert.False(dictionary.TryGetValue(missingKey, out outValue)); } } else { Assert.Throws(() => dictionary.TryGetValue(default(TKey), out outValue)); -#if !NETFRAMEWORK - IReadOnlyDictionary readOnlyDictionary = dictionary; - Assert.Throws(() => readOnlyDictionary.TryGetValue(default(TKey), out outValue)); -#endif } } @@ -1080,8 +960,10 @@ public void IDictionary_Generic_TryGetValue_DefaultKeyContainedInDictionary(int IDictionary dictionary = GenericIDictionaryFactory(count); TKey missingKey = default(TKey); TValue value = CreateTValue(5123); + TValue outValue; dictionary.TryAdd(missingKey, value); - CollectionAsserts.TryGetValue(dictionary, missingKey, true, value); + Assert.True(dictionary.TryGetValue(missingKey, out outValue)); + Assert.Equal(value, outValue); } } diff --git a/src/libraries/Common/tests/System/Collections/IList.Generic.Tests.cs b/src/libraries/Common/tests/System/Collections/IList.Generic.Tests.cs index 6d66f143f18d6..44f67e0ca24f8 100644 --- a/src/libraries/Common/tests/System/Collections/IList.Generic.Tests.cs +++ b/src/libraries/Common/tests/System/Collections/IList.Generic.Tests.cs @@ -103,8 +103,8 @@ protected override IEnumerable GetModifyEnumerables(ModifyOper public void IList_Generic_ItemGet_NegativeIndex_ThrowsException(int count) { IList list = GenericIListFactory(count); - CollectionAsserts.ThrowsElementAt(list, -1, IList_Generic_Item_InvalidIndex_ThrowType); - CollectionAsserts.ThrowsElementAt(list, int.MinValue, IList_Generic_Item_InvalidIndex_ThrowType); + Assert.Throws(IList_Generic_Item_InvalidIndex_ThrowType, () => list[-1]); + Assert.Throws(IList_Generic_Item_InvalidIndex_ThrowType, () => list[int.MinValue]); } [Theory] @@ -112,8 +112,8 @@ public void IList_Generic_ItemGet_NegativeIndex_ThrowsException(int count) public void IList_Generic_ItemGet_IndexGreaterThanListCount_ThrowsException(int count) { IList list = GenericIListFactory(count); - CollectionAsserts.ThrowsElementAt(list, count, IList_Generic_Item_InvalidIndex_ThrowType); - CollectionAsserts.ThrowsElementAt(list, count + 1, IList_Generic_Item_InvalidIndex_ThrowType); + Assert.Throws(IList_Generic_Item_InvalidIndex_ThrowType, () => list[count]); + Assert.Throws(IList_Generic_Item_InvalidIndex_ThrowType, () => list[count + 1]); } [Theory] @@ -121,7 +121,8 @@ public void IList_Generic_ItemGet_IndexGreaterThanListCount_ThrowsException(int public void IList_Generic_ItemGet_ValidGetWithinListBounds(int count) { IList list = GenericIListFactory(count); - Assert.All(Enumerable.Range(0, count), index => CollectionAsserts.ElementAtSucceeds(list, index)); + T result; + Assert.All(Enumerable.Range(0, count), index => result = list[index]); } #endregion @@ -138,7 +139,7 @@ public void IList_Generic_ItemSet_NegativeIndex_ThrowsException(int count) T validAdd = CreateT(0); Assert.Throws(IList_Generic_Item_InvalidIndex_ThrowType, () => list[-1] = validAdd); Assert.Throws(IList_Generic_Item_InvalidIndex_ThrowType, () => list[int.MinValue] = validAdd); - CollectionAsserts.HasCount(list, count); + Assert.Equal(count, list.Count); } } @@ -152,7 +153,7 @@ public void IList_Generic_ItemSet_IndexGreaterThanListCount_ThrowsException(int T validAdd = CreateT(0); Assert.Throws(IList_Generic_Item_InvalidIndex_ThrowType, () => list[count] = validAdd); Assert.Throws(IList_Generic_Item_InvalidIndex_ThrowType, () => list[count + 1] = validAdd); - CollectionAsserts.HasCount(list, count); + Assert.Equal(count, list.Count); } } @@ -165,7 +166,7 @@ public void IList_Generic_ItemSet_OnReadOnlyList(int count) IList list = GenericIListFactory(count); T before = list[count / 2]; Assert.Throws(() => list[count / 2] = CreateT(321432)); - CollectionAsserts.EqualAt(list, count / 2, before); + Assert.Equal(before, list[count / 2]); } } @@ -178,7 +179,7 @@ public void IList_Generic_ItemSet_FirstItemToNonDefaultValue(int count) IList list = GenericIListFactory(count); T value = CreateT(123452); list[0] = value; - CollectionAsserts.EqualAt(list, 0, value); + Assert.Equal(value, list[0]); } } @@ -192,12 +193,12 @@ public void IList_Generic_ItemSet_FirstItemToDefaultValue(int count) if (DefaultValueAllowed) { list[0] = default(T); - CollectionAsserts.EqualAt(list, 0, default(T)); + Assert.Equal(default(T), list[0]); } else { Assert.Throws(() => list[0] = default(T)); - CollectionAsserts.NotEqualAt(list, 0, default(T)); + Assert.NotEqual(default(T), list[0]); } } } @@ -212,7 +213,7 @@ public void IList_Generic_ItemSet_LastItemToNonDefaultValue(int count) T value = CreateT(123452); int lastIndex = count > 0 ? count - 1 : 0; list[lastIndex] = value; - CollectionAsserts.EqualAt(list, lastIndex, value); + Assert.Equal(value, list[lastIndex]); } } @@ -227,12 +228,12 @@ public void IList_Generic_ItemSet_LastItemToDefaultValue(int count) if (DefaultValueAllowed) { list[lastIndex] = default(T); - CollectionAsserts.EqualAt(list, lastIndex, default(T)); + Assert.Equal(default(T), list[lastIndex]); } else { Assert.Throws(() => list[lastIndex] = default(T)); - CollectionAsserts.NotEqualAt(list, lastIndex, default(T)); + Assert.NotEqual(default(T), list[lastIndex]); } } } @@ -247,8 +248,8 @@ public void IList_Generic_ItemSet_DuplicateValues(int count) T value = CreateT(123452); list[0] = value; list[1] = value; - CollectionAsserts.EqualAt(list, 0, value); - CollectionAsserts.EqualAt(list, 1, value); + Assert.Equal(value, list[0]); + Assert.Equal(value, list[1]); } } @@ -395,7 +396,7 @@ public void IList_Generic_Insert_NegativeIndex_ThrowsArgumentOutOfRangeException T validAdd = CreateT(0); Assert.Throws(() => list.Insert(-1, validAdd)); Assert.Throws(() => list.Insert(int.MinValue, validAdd)); - CollectionAsserts.HasCount(list, count); + Assert.Equal(count, list.Count); } } @@ -408,8 +409,8 @@ public void IList_Generic_Insert_IndexGreaterThanListCount_Appends(int count) IList list = GenericIListFactory(count); T validAdd = CreateT(12350); list.Insert(count, validAdd); - CollectionAsserts.HasCount(list, count + 1); - CollectionAsserts.EqualAt(list, count, validAdd); + Assert.Equal(count + 1, list.Count); + Assert.Equal(validAdd, list[count]); } } @@ -421,7 +422,7 @@ public void IList_Generic_Insert_ToReadOnlyList(int count) { IList list = GenericIListFactory(count); Assert.Throws(() => list.Insert(count / 2, CreateT(321432))); - CollectionAsserts.HasCount(list, count); + Assert.Equal(count, list.Count); } } @@ -434,8 +435,8 @@ public void IList_Generic_Insert_FirstItemToNonDefaultValue(int count) IList list = GenericIListFactory(count); T value = CreateT(123452); list.Insert(0, value); - CollectionAsserts.EqualAt(list, 0, value); - CollectionAsserts.HasCount(list, count + 1); + Assert.Equal(value, list[0]); + Assert.Equal(count + 1, list.Count); } } @@ -448,8 +449,8 @@ public void IList_Generic_Insert_FirstItemToDefaultValue(int count) IList list = GenericIListFactory(count); T value = default(T); list.Insert(0, value); - CollectionAsserts.EqualAt(list, 0, value); - CollectionAsserts.HasCount(list, count + 1); + Assert.Equal(value, list[0]); + Assert.Equal(count + 1, list.Count); } } @@ -463,8 +464,8 @@ public void IList_Generic_Insert_LastItemToNonDefaultValue(int count) T value = CreateT(123452); int lastIndex = count > 0 ? count - 1 : 0; list.Insert(lastIndex, value); - CollectionAsserts.EqualAt(list, lastIndex, value); - CollectionAsserts.HasCount(list, count + 1); + Assert.Equal(value, list[lastIndex]); + Assert.Equal(count + 1, list.Count); } } @@ -478,8 +479,8 @@ public void IList_Generic_Insert_LastItemToDefaultValue(int count) T value = default(T); int lastIndex = count > 0 ? count - 1 : 0; list.Insert(lastIndex, value); - CollectionAsserts.EqualAt(list, lastIndex, value); - CollectionAsserts.HasCount(list, count + 1); + Assert.Equal(value, list[lastIndex]); + Assert.Equal(count + 1, list.Count); } } @@ -499,9 +500,9 @@ public void IList_Generic_Insert_DuplicateValues(int count) { list.Insert(0, value); list.Insert(1, value); - CollectionAsserts.EqualAt(list, 0, value); - CollectionAsserts.EqualAt(list, 1, value); - CollectionAsserts.HasCount(list, count + 2); + Assert.Equal(value, list[0]); + Assert.Equal(value, list[1]); + Assert.Equal(count + 2, list.Count); } } } @@ -534,7 +535,7 @@ public void IList_Generic_RemoveAt_NegativeIndex_ThrowsArgumentOutOfRangeExcepti T validAdd = CreateT(0); Assert.Throws(() => list.RemoveAt(-1)); Assert.Throws(() => list.RemoveAt(int.MinValue)); - CollectionAsserts.HasCount(list, count); + Assert.Equal(count, list.Count); } } @@ -548,7 +549,7 @@ public void IList_Generic_RemoveAt_IndexGreaterThanListCount_ThrowsArgumentOutOf T validAdd = CreateT(0); Assert.Throws(() => list.RemoveAt(count)); Assert.Throws(() => list.RemoveAt(count + 1)); - CollectionAsserts.HasCount(list, count); + Assert.Equal(count, list.Count); } } @@ -560,7 +561,7 @@ public void IList_Generic_RemoveAt_OnReadOnlyList(int count) { IList list = GenericIListFactory(count); Assert.Throws(() => list.RemoveAt(count / 2)); - CollectionAsserts.HasCount(list, count); + Assert.Equal(count, list.Count); } } @@ -571,11 +572,11 @@ public void IList_Generic_RemoveAt_AllValidIndices(int count) if (!IsReadOnly && !AddRemoveClear_ThrowsNotSupported) { IList list = GenericIListFactory(count); - CollectionAsserts.HasCount(list, count); + Assert.Equal(count, list.Count); Assert.All(Enumerable.Range(0, count).Reverse(), index => { list.RemoveAt(index); - CollectionAsserts.HasCount(list, index); + Assert.Equal(index, list.Count); }); } } @@ -590,7 +591,7 @@ public void IList_Generic_RemoveAt_ZeroMultipleTimes(int count) Assert.All(Enumerable.Range(0, count), index => { list.RemoveAt(0); - CollectionAsserts.HasCount(list, count - index - 1); + Assert.Equal(count - index - 1, list.Count); }); } } diff --git a/src/libraries/Common/tests/System/Collections/ISet.Generic.Tests.cs b/src/libraries/Common/tests/System/Collections/ISet.Generic.Tests.cs index 350faab6f44cb..303001e8bd144 100644 --- a/src/libraries/Common/tests/System/Collections/ISet.Generic.Tests.cs +++ b/src/libraries/Common/tests/System/Collections/ISet.Generic.Tests.cs @@ -84,8 +84,8 @@ public void ICollection_Generic_Add_ReturnValue(int count) Assert.True(set.Add(newValue)); if (!DuplicateValuesAllowed) Assert.False(set.Add(newValue)); - CollectionAsserts.HasCount(set, count + 1); - CollectionAsserts.Contains(set, newValue); + Assert.Equal(count + 1, set.Count); + Assert.True(set.Contains(newValue)); } } @@ -104,7 +104,7 @@ public void ICollection_Generic_Add_DuplicateValue_DoesNothing(int count) duplicateValue = CreateT(seed++); collection.Add(duplicateValue); collection.Add(duplicateValue); - CollectionAsserts.HasCount(collection, count + 1); + Assert.Equal(count + 1, collection.Count); } } } @@ -118,7 +118,7 @@ private void Validate_ExceptWith(ISet set, IEnumerable enumerable) if (set.Count == 0 || enumerable == set) { set.ExceptWith(enumerable); - CollectionAsserts.HasCount(set, 0); + Assert.Equal(0, set.Count); } else { @@ -126,7 +126,7 @@ private void Validate_ExceptWith(ISet set, IEnumerable enumerable) foreach (T element in enumerable) expected.Remove(element); set.ExceptWith(enumerable); - CollectionAsserts.HasCount(set, expected.Count); + Assert.Equal(expected.Count, set.Count); Assert.True(expected.SetEquals(set)); } } @@ -136,7 +136,7 @@ private void Validate_IntersectWith(ISet set, IEnumerable enumerable) if (set.Count == 0 || Enumerable.Count(enumerable) == 0) { set.IntersectWith(enumerable); - CollectionAsserts.HasCount(set, 0); + Assert.Equal(0, set.Count); } else if (set == enumerable) { @@ -152,7 +152,7 @@ private void Validate_IntersectWith(ISet set, IEnumerable enumerable) if (enumerable.Contains(value, comparer)) expected.Add(value); set.IntersectWith(enumerable); - CollectionAsserts.HasCount(set, expected.Count); + Assert.Equal(expected.Count, set.Count); Assert.True(expected.SetEquals(set)); } } @@ -178,7 +178,7 @@ private void Validate_IsProperSubsetOf(ISet set, IEnumerable enumerable) break; } } - CollectionAsserts.IsProperSubsetOf(set, enumerable, !setContainsValueNotInEnumerable && enumerableContainsValueNotInSet); + Assert.Equal(!setContainsValueNotInEnumerable && enumerableContainsValueNotInSet, set.IsProperSubsetOf(enumerable)); } private void Validate_IsProperSupersetOf(ISet set, IEnumerable enumerable) @@ -203,7 +203,7 @@ private void Validate_IsProperSupersetOf(ISet set, IEnumerable enumerable) } } isProperSuperset = isProperSuperset && setContainsElementsNotInEnumerable; - CollectionAsserts.IsProperSupersetOf(set, enumerable, isProperSuperset); + Assert.Equal(isProperSuperset, set.IsProperSupersetOf(enumerable)); } private void Validate_IsSubsetOf(ISet set, IEnumerable enumerable) @@ -212,10 +212,10 @@ private void Validate_IsSubsetOf(ISet set, IEnumerable enumerable) foreach (T value in set) if (!enumerable.Contains(value, comparer)) { - CollectionAsserts.IsSubsetOf(set, enumerable, false); + Assert.False(set.IsSubsetOf(enumerable)); return; } - CollectionAsserts.IsSubsetOf(set, enumerable, true); + Assert.True(set.IsSubsetOf(enumerable)); } private void Validate_IsSupersetOf(ISet set, IEnumerable enumerable) @@ -224,10 +224,10 @@ private void Validate_IsSupersetOf(ISet set, IEnumerable enumerable) foreach (T value in enumerable) if (!set.Contains(value, comparer)) { - CollectionAsserts.IsSupersetOf(set, enumerable, false); + Assert.False(set.IsSupersetOf(enumerable)); return; } - CollectionAsserts.IsSupersetOf(set, enumerable, true); + Assert.True(set.IsSupersetOf(enumerable)); } private void Validate_Overlaps(ISet set, IEnumerable enumerable) @@ -237,11 +237,11 @@ private void Validate_Overlaps(ISet set, IEnumerable enumerable) { if (set.Contains(value, comparer)) { - CollectionAsserts.Overlaps(set, enumerable, true); + Assert.True(set.Overlaps(enumerable)); return; } } - CollectionAsserts.Overlaps(set, enumerable, false); + Assert.False(set.Overlaps(enumerable)); } private void Validate_SetEquals(ISet set, IEnumerable enumerable) @@ -251,7 +251,7 @@ private void Validate_SetEquals(ISet set, IEnumerable enumerable) { if (!enumerable.Contains(value, comparer)) { - CollectionAsserts.SetEquals(set, enumerable, false); + Assert.False(set.SetEquals(enumerable)); return; } } @@ -259,11 +259,11 @@ private void Validate_SetEquals(ISet set, IEnumerable enumerable) { if (!set.Contains(value, comparer)) { - CollectionAsserts.SetEquals(set, enumerable, false); + Assert.False(set.SetEquals(enumerable)); return; } } - CollectionAsserts.SetEquals(set, enumerable, true); + Assert.True(set.SetEquals(enumerable)); } private void Validate_SymmetricExceptWith(ISet set, IEnumerable enumerable) @@ -277,7 +277,7 @@ private void Validate_SymmetricExceptWith(ISet set, IEnumerable enumerable if (!enumerable.Contains(element, comparer)) expected.Add(element); set.SymmetricExceptWith(enumerable); - CollectionAsserts.HasCount(set, expected.Count); + Assert.Equal(expected.Count, set.Count); Assert.True(expected.SetEquals(set)); } @@ -289,7 +289,7 @@ private void Validate_UnionWith(ISet set, IEnumerable enumerable) if (!set.Contains(element, comparer)) expected.Add(element); set.UnionWith(enumerable); - CollectionAsserts.HasCount(set, expected.Count); + Assert.Equal(expected.Count, set.Count); Assert.True(expected.SetEquals(set)); } @@ -308,15 +308,6 @@ public void ISet_Generic_NullEnumerableArgument(int count) Assert.Throws(() => set.IsSupersetOf(null)); Assert.Throws(() => set.Overlaps(null)); Assert.Throws(() => set.SetEquals(null)); -#if !NETFRAMEWORK - IReadOnlySet readOnlySet = set; - Assert.Throws(() => readOnlySet.IsProperSubsetOf(null)); - Assert.Throws(() => readOnlySet.IsProperSupersetOf(null)); - Assert.Throws(() => readOnlySet.IsSubsetOf(null)); - Assert.Throws(() => readOnlySet.IsSupersetOf(null)); - Assert.Throws(() => readOnlySet.Overlaps(null)); - Assert.Throws(() => readOnlySet.SetEquals(null)); -#endif if (!IsReadOnly) { Assert.Throws(() => set.ExceptWith(null)); @@ -511,7 +502,7 @@ public void ISet_Generic_Overlaps_Itself(int setLength) public void ISet_Generic_SetEquals_Itself(int setLength) { ISet set = GenericISetFactory(setLength); - CollectionAsserts.SetEquals(set, set, true); + Assert.True(set.SetEquals(set)); } [Theory] @@ -669,7 +660,7 @@ public void ISet_Generic_SymmetricExceptWith_AfterRemovingElements(EnumerableTyp if (!enumerable.Contains(element, comparer)) expected.Add(element); set.SymmetricExceptWith(enumerable); - CollectionAsserts.HasCount(set, expected.Count); + Assert.Equal(expected.Count, set.Count); Assert.True(expected.SetEquals(set)); } } diff --git a/src/libraries/System.Collections/tests/Generic/CollectionExtensionsTests.cs b/src/libraries/System.Collections/tests/Generic/CollectionExtensionsTests.cs index 6a5b458232fc5..213d9d6faca99 100644 --- a/src/libraries/System.Collections/tests/Generic/CollectionExtensionsTests.cs +++ b/src/libraries/System.Collections/tests/Generic/CollectionExtensionsTests.cs @@ -61,10 +61,6 @@ public void TryAdd_KeyDoesntExistInIDictionary_ReturnsTrue() IDictionary dictionary = new SortedDictionary(); Assert.True(dictionary.TryAdd("key", "value")); Assert.Equal("value", dictionary["key"]); -#if !NETFRAMEWORK - IReadOnlyDictionary readOnlyDictionary = dictionary; - Assert.Equal("value", readOnlyDictionary["key"]); -#endif } [Fact] @@ -73,10 +69,6 @@ public void TryAdd_KeyExistsInIDictionary_ReturnsFalse() IDictionary dictionary = new SortedDictionary() { ["key"] = "value" }; Assert.False(dictionary.TryAdd("key", "value2")); Assert.Equal("value", dictionary["key"]); -#if !NETFRAMEWORK - IReadOnlyDictionary readOnlyDictionary = dictionary; - Assert.Equal("value", readOnlyDictionary["key"]); -#endif } [Fact] @@ -104,10 +96,6 @@ public void Remove_KeyExistsInIDictionary_ReturnsTrue() Assert.True(dictionary.Remove("key", out var value)); Assert.Equal("value", value); Assert.Throws(() => dictionary["key"]); -#if !NETFRAMEWORK - IReadOnlyDictionary readOnlyDictionary = dictionary; - Assert.Throws(() => readOnlyDictionary["key"]); -#endif } [Fact] diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ICollection.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ICollection.cs index 24cf81efb2b44..1c1095f8a5cf7 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ICollection.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ICollection.cs @@ -9,9 +9,9 @@ namespace System.Collections.Generic { // Base interface for all collections, defining enumerators, size, and // synchronization methods. - public interface ICollection : IReadOnlyCollection + public interface ICollection : IEnumerable { - new int Count + int Count { #if MONO [DynamicDependency(nameof(Array.InternalArray__ICollection_get_Count), typeof(Array))] @@ -53,7 +53,5 @@ bool IsReadOnly [DynamicDependency(nameof(Array.InternalArray__ICollection_Remove) + "``1", typeof(Array))] #endif bool Remove(T item); - - int IReadOnlyCollection.Count => Count; } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IDictionary.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IDictionary.cs index 7e3e30d8db092..56a03106c205b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IDictionary.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IDictionary.cs @@ -9,32 +9,32 @@ namespace System.Collections.Generic // Keys can be any non-null object. Values can be any object. // You can look up a value in an IDictionary via the default indexed // property, Items. - public interface IDictionary : ICollection>, IReadOnlyDictionary + public interface IDictionary : ICollection> { // Interfaces are not serializable // The Item property provides methods to read and edit entries // in the Dictionary. - new TValue this[TKey key] + TValue this[TKey key] { get; set; } // Returns a collections of the keys in this dictionary. - new ICollection Keys + ICollection Keys { get; } // Returns a collections of the values in this dictionary. - new ICollection Values + ICollection Values { get; } // Returns whether this dictionary contains a particular key. // - new bool ContainsKey(TKey key); + bool ContainsKey(TKey key); // Adds a key-value pair to the dictionary. // @@ -44,16 +44,6 @@ public interface IDictionary : ICollection.this[TKey key] => this[key]; - - IEnumerable IReadOnlyDictionary.Keys => Keys; - - IEnumerable IReadOnlyDictionary.Values => Values; - - bool IReadOnlyDictionary.ContainsKey(TKey key) => ContainsKey(key); - - bool IReadOnlyDictionary.TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value) => TryGetValue(key, out value); + bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value); } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IList.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IList.cs index ec8098c3ff7ea..f45ae823daf65 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IList.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IList.cs @@ -10,10 +10,10 @@ namespace System.Collections.Generic // An IList is an ordered collection of objects. The exact ordering // is up to the implementation of the list, ranging from a sorted // order to insertion order. - public interface IList : ICollection, IReadOnlyList + public interface IList : ICollection { // The Item property provides methods to read and edit entries in the List. - new T this[int index] + T this[int index] { #if MONO [DynamicDependency(nameof(Array.InternalArray__get_Item) + "``1", typeof(Array))] @@ -46,7 +46,5 @@ public interface IList : ICollection, IReadOnlyList [DynamicDependency(nameof(Array.InternalArray__RemoveAt), typeof(Array))] #endif void RemoveAt(int index); - - T IReadOnlyList.this[int index] => this[index]; } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ISet.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ISet.cs index ce2e8e7c5f4ff..cee05d198cda0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ISet.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ISet.cs @@ -8,7 +8,7 @@ namespace System.Collections.Generic /// by some comparer. It also supports basic set operations such as Union, Intersection, /// Complement and Exclusive Complement. /// - public interface ISet : ICollection, IReadOnlySet + public interface ISet : ICollection { //Add ITEM to the set, return true if added, false if duplicate new bool Add(T item); @@ -26,42 +26,21 @@ public interface ISet : ICollection, IReadOnlySet void SymmetricExceptWith(IEnumerable other); //Check if this set is a subset of other - new bool IsSubsetOf(IEnumerable other); + bool IsSubsetOf(IEnumerable other); //Check if this set is a superset of other - new bool IsSupersetOf(IEnumerable other); + bool IsSupersetOf(IEnumerable other); //Check if this set is a subset of other, but not the same as it - new bool IsProperSupersetOf(IEnumerable other); + bool IsProperSupersetOf(IEnumerable other); //Check if this set is a superset of other, but not the same as it - new bool IsProperSubsetOf(IEnumerable other); + bool IsProperSubsetOf(IEnumerable other); //Check if this set has any elements in common with other - new bool Overlaps(IEnumerable other); + bool Overlaps(IEnumerable other); //Check if this set contains the same and only the same elements as other - new bool SetEquals(IEnumerable other); - - /// - /// Determines if the set contains a specific item - /// - /// The item to check if the set contains. - /// if found; otherwise . - new bool Contains(T item) => ((ICollection)this).Contains(item); - - bool IReadOnlySet.IsSubsetOf(IEnumerable other) => IsSubsetOf(other); - - bool IReadOnlySet.IsSupersetOf(IEnumerable other) => IsSupersetOf(other); - - bool IReadOnlySet.IsProperSupersetOf(IEnumerable other) => IsProperSupersetOf(other); - - bool IReadOnlySet.IsProperSubsetOf(IEnumerable other) => IsProperSubsetOf(other); - - bool IReadOnlySet.Overlaps(IEnumerable other) => Overlaps(other); - - bool IReadOnlySet.SetEquals(IEnumerable other) => SetEquals(other); - - bool IReadOnlySet.Contains(T value) => ((ICollection)this).Contains(value); + bool SetEquals(IEnumerable other); } } diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index c2f175247dc9b..a3f2a4b07e2f4 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -7803,35 +7803,29 @@ public partial interface IAsyncEnumerator : System.IAsyncDisposable T Current { get; } System.Threading.Tasks.ValueTask MoveNextAsync(); } - public partial interface ICollection : System.Collections.Generic.IEnumerable, System.Collections.IEnumerable, System.Collections.Generic.IReadOnlyCollection + public partial interface ICollection : System.Collections.Generic.IEnumerable, System.Collections.IEnumerable { - new int Count { get; } + int Count { get; } bool IsReadOnly { get; } void Add(T item); void Clear(); bool Contains(T item); void CopyTo(T[] array, int arrayIndex); bool Remove(T item); - int System.Collections.Generic.IReadOnlyCollection.Count => Count; } public partial interface IComparer { int Compare(T? x, T? y); } - public partial interface IDictionary : System.Collections.Generic.ICollection>, System.Collections.Generic.IEnumerable>, System.Collections.IEnumerable, System.Collections.Generic.IReadOnlyDictionary, System.Collections.Generic.IReadOnlyCollection> + public partial interface IDictionary : System.Collections.Generic.ICollection>, System.Collections.Generic.IEnumerable>, System.Collections.IEnumerable { - new TValue this[TKey key] { get; set; } - new System.Collections.Generic.ICollection Keys { get; } - new System.Collections.Generic.ICollection Values { get; } + TValue this[TKey key] { get; set; } + System.Collections.Generic.ICollection Keys { get; } + System.Collections.Generic.ICollection Values { get; } void Add(TKey key, TValue value); - new bool ContainsKey(TKey key); + bool ContainsKey(TKey key); bool Remove(TKey key); - new bool TryGetValue(TKey key, [System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out TValue value); - TValue System.Collections.Generic.IReadOnlyDictionary.this[TKey key] => this[key]; - System.Collections.Generic.IEnumerable System.Collections.Generic.IReadOnlyDictionary.Keys => Keys; - System.Collections.Generic.IEnumerable System.Collections.Generic.IReadOnlyDictionary.Values => Values; - bool System.Collections.Generic.IReadOnlyDictionary.ContainsKey(TKey key) => ContainsKey(key); - bool System.Collections.Generic.IReadOnlyDictionary.TryGetValue(TKey key, [System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out TValue value) => TryGetValue(key, out value); + bool TryGetValue(TKey key, [System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out TValue value); } public partial interface IEnumerable : System.Collections.IEnumerable { @@ -7846,13 +7840,12 @@ public partial interface IEqualityComparer bool Equals(T? x, T? y); int GetHashCode([System.Diagnostics.CodeAnalysis.DisallowNullAttribute] T obj); } - public partial interface IList : System.Collections.Generic.ICollection, System.Collections.Generic.IEnumerable, System.Collections.IEnumerable, System.Collections.Generic.IReadOnlyList, System.Collections.Generic.IReadOnlyCollection + public partial interface IList : System.Collections.Generic.ICollection, System.Collections.Generic.IEnumerable, System.Collections.IEnumerable { - new T this[int index] { get; set; } + T this[int index] { get; set; } int IndexOf(T item); void Insert(int index, T item); void RemoveAt(int index); - T System.Collections.Generic.IReadOnlyList.this[int index] => this[index]; } public partial interface IReadOnlyCollection : System.Collections.Generic.IEnumerable, System.Collections.IEnumerable { @@ -7880,27 +7873,19 @@ public partial interface IReadOnlySet : System.Collections.Generic.IEnumerabl bool Overlaps(System.Collections.Generic.IEnumerable other); bool SetEquals(System.Collections.Generic.IEnumerable other); } - public partial interface ISet : System.Collections.Generic.ICollection, System.Collections.Generic.IEnumerable, System.Collections.IEnumerable, System.Collections.Generic.IReadOnlySet, System.Collections.Generic.IReadOnlyCollection + public partial interface ISet : System.Collections.Generic.ICollection, System.Collections.Generic.IEnumerable, System.Collections.IEnumerable { new bool Add(T item); void ExceptWith(System.Collections.Generic.IEnumerable other); void IntersectWith(System.Collections.Generic.IEnumerable other); - new bool IsProperSubsetOf(System.Collections.Generic.IEnumerable other); - new bool IsProperSupersetOf(System.Collections.Generic.IEnumerable other); - new bool IsSubsetOf(System.Collections.Generic.IEnumerable other); - new bool IsSupersetOf(System.Collections.Generic.IEnumerable other); - new bool Overlaps(System.Collections.Generic.IEnumerable other); - new bool SetEquals(System.Collections.Generic.IEnumerable other); + bool IsProperSubsetOf(System.Collections.Generic.IEnumerable other); + bool IsProperSupersetOf(System.Collections.Generic.IEnumerable other); + bool IsSubsetOf(System.Collections.Generic.IEnumerable other); + bool IsSupersetOf(System.Collections.Generic.IEnumerable other); + bool Overlaps(System.Collections.Generic.IEnumerable other); + bool SetEquals(System.Collections.Generic.IEnumerable other); void SymmetricExceptWith(System.Collections.Generic.IEnumerable other); void UnionWith(System.Collections.Generic.IEnumerable other); - new bool Contains(T item) => ((ICollection)this).Contains(item); - bool System.Collections.Generic.IReadOnlySet.Contains(T item) => ((ICollection)this).Contains(item); - bool System.Collections.Generic.IReadOnlySet.IsProperSubsetOf(System.Collections.Generic.IEnumerable other) => IsProperSubsetOf(other); - bool System.Collections.Generic.IReadOnlySet.IsProperSupersetOf(System.Collections.Generic.IEnumerable other) => IsProperSupersetOf(other); - bool System.Collections.Generic.IReadOnlySet.IsSubsetOf(System.Collections.Generic.IEnumerable other) => IsSubsetOf(other); - bool System.Collections.Generic.IReadOnlySet.IsSupersetOf(System.Collections.Generic.IEnumerable other) => IsSupersetOf(other); - bool System.Collections.Generic.IReadOnlySet.Overlaps(System.Collections.Generic.IEnumerable other) => Overlaps(other); - bool System.Collections.Generic.IReadOnlySet.SetEquals(System.Collections.Generic.IEnumerable other) => SetEquals(other); } public partial class KeyNotFoundException : System.SystemException { From 055eb09bbe7de36afbbd0303415a5274df947861 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Sat, 27 Apr 2024 11:43:16 -0700 Subject: [PATCH 3/3] Update src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs --- src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs index de7b3021c458f..74e0739848168 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs @@ -694,7 +694,7 @@ public ArrayInitializeCache(RuntimeType arrayType) // it for type and executes it. // // The "T" will reflect the interface used to invoke the method. The actual runtime "this" will be - // array that is castable to "T[]" (i.e. for primitivs and valuetypes, it will be exactly + // array that is castable to "T[]" (i.e. for primitives and valuetypes, it will be exactly // "T[]" - for orefs, it may be a "U[]" where U derives from T.) //---------------------------------------------------------------------------------------- internal sealed class SZArrayHelper