diff --git a/src/libraries/System.Collections/ref/System.Collections.cs b/src/libraries/System.Collections/ref/System.Collections.cs index 028b1637eb4825..7a15ca70fb3e51 100644 --- a/src/libraries/System.Collections/ref/System.Collections.cs +++ b/src/libraries/System.Collections/ref/System.Collections.cs @@ -47,6 +47,8 @@ public static partial class CollectionExtensions public static TValue GetValueOrDefault(this System.Collections.Generic.IReadOnlyDictionary dictionary, TKey key, TValue defaultValue) { throw null; } public static bool Remove(this System.Collections.Generic.IDictionary dictionary, TKey key, [System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out TValue value) { throw null; } public static bool TryAdd(this System.Collections.Generic.IDictionary dictionary, TKey key, TValue value) { throw null; } + public static System.Collections.ObjectModel.ReadOnlyCollection AsReadOnly(this IList list) { throw null; } + public static System.Collections.ObjectModel.ReadOnlyDictionary AsReadOnly(this IDictionary dictionary) where TKey : notnull { throw null; } } public abstract partial class Comparer : System.Collections.Generic.IComparer, System.Collections.IComparer { diff --git a/src/libraries/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs b/src/libraries/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs index 7a5bce9b0a1d4e..4f5c545603dbbe 100644 --- a/src/libraries/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs +++ b/src/libraries/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Collections.ObjectModel; using System.Diagnostics.CodeAnalysis; namespace System.Collections.Generic @@ -55,5 +56,32 @@ public static bool Remove(this IDictionary dictionar value = default; return false; } + + /// + /// Returns a read-only wrapper + /// for the specified list. + /// + /// The type of elements in the collection. + /// The list to wrap. + /// An object that acts as a read-only wrapper around the current . + /// is null. + public static ReadOnlyCollection AsReadOnly(this IList list) + { + return new ReadOnlyCollection(list); + } + + /// + /// Returns a read-only wrapper + /// for the current dictionary. + /// + /// The type of keys in the dictionary. + /// The type of values in the dictionary. + /// The dictionary to wrap. + /// An object that acts as a read-only wrapper around the current . + /// is null. + public static ReadOnlyDictionary AsReadOnly(this IDictionary dictionary) where TKey : notnull + { + return new ReadOnlyDictionary(dictionary); + } } } diff --git a/src/libraries/System.Collections/tests/Generic/CollectionExtensionsTests.cs b/src/libraries/System.Collections/tests/Generic/CollectionExtensionsTests.cs index 153a3111907685..213d9d6faca996 100644 --- a/src/libraries/System.Collections/tests/Generic/CollectionExtensionsTests.cs +++ b/src/libraries/System.Collections/tests/Generic/CollectionExtensionsTests.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; +using System.Collections.ObjectModel; using Xunit; namespace System.Collections.Tests @@ -104,5 +105,39 @@ public void Remove_KeyDoesntExistInIDictionary_ReturnsFalse() Assert.False(dictionary.Remove("key", out var value)); Assert.Equal(default(string), value); } + + [Fact] + public void AsReadOnly_TurnsIListIntoReadOnlyCollection() + { + IList list = new List { "A", "B" }; + ReadOnlyCollection readOnlyCollection = list.AsReadOnly(); + Assert.NotNull(readOnlyCollection); + CollectionAsserts.Equal(list, readOnlyCollection); + } + + [Fact] + public void AsReadOnly_TurnsIDictionaryIntoReadOnlyDictionary() + { + IDictionary dictionary = new Dictionary { ["key1"] = "value1", ["key2"] = "value2" }; + ReadOnlyDictionary readOnlyDictionary = dictionary.AsReadOnly(); + Assert.NotNull(readOnlyDictionary); + Assert.Equal(dictionary["key1"], readOnlyDictionary["key1"]); + Assert.Equal(dictionary["key2"], readOnlyDictionary["key2"]); + Assert.Equal(dictionary.Count, readOnlyDictionary.Count); + } + + [Fact] + public void AsReadOnly_NullIList_ThrowsArgumentNullException() + { + IList list = null; + Assert.Throws("list", () => list.AsReadOnly()); + } + + [Fact] + public void AsReadOnly_NullIDictionary_ThrowsArgumentNullException() + { + IDictionary dictionary = null; + Assert.Throws("dictionary", () => dictionary.AsReadOnly()); + } } } diff --git a/src/libraries/System.ObjectModel/ref/System.ObjectModel.Forwards.cs b/src/libraries/System.ObjectModel/ref/System.ObjectModel.Forwards.cs new file mode 100644 index 00000000000000..df45eb9a68a6ee --- /dev/null +++ b/src/libraries/System.ObjectModel/ref/System.ObjectModel.Forwards.cs @@ -0,0 +1,4 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Collections.ObjectModel.ReadOnlyDictionary<,>))] diff --git a/src/libraries/System.ObjectModel/ref/System.ObjectModel.cs b/src/libraries/System.ObjectModel/ref/System.ObjectModel.cs index 744576e587d067..21cd3dc855f118 100644 --- a/src/libraries/System.ObjectModel/ref/System.ObjectModel.cs +++ b/src/libraries/System.ObjectModel/ref/System.ObjectModel.cs @@ -43,77 +43,6 @@ protected virtual void OnPropertyChanged(System.ComponentModel.PropertyChangedEv protected override void RemoveItem(int index) { } protected override void SetItem(int index, T item) { } } - public partial class ReadOnlyDictionary : System.Collections.Generic.ICollection>, System.Collections.Generic.IDictionary, System.Collections.Generic.IEnumerable>, System.Collections.Generic.IReadOnlyCollection>, System.Collections.Generic.IReadOnlyDictionary, System.Collections.ICollection, System.Collections.IDictionary, System.Collections.IEnumerable where TKey : notnull - { - public ReadOnlyDictionary(System.Collections.Generic.IDictionary dictionary) { } - public int Count { get { throw null; } } - protected System.Collections.Generic.IDictionary Dictionary { get { throw null; } } - public TValue this[TKey key] { get { throw null; } } - public System.Collections.ObjectModel.ReadOnlyDictionary.KeyCollection Keys { get { throw null; } } - bool System.Collections.Generic.ICollection>.IsReadOnly { get { throw null; } } - TValue System.Collections.Generic.IDictionary.this[TKey key] { get { throw null; } set { } } - System.Collections.Generic.ICollection System.Collections.Generic.IDictionary.Keys { get { throw null; } } - System.Collections.Generic.ICollection System.Collections.Generic.IDictionary.Values { get { throw null; } } - System.Collections.Generic.IEnumerable System.Collections.Generic.IReadOnlyDictionary.Keys { get { throw null; } } - System.Collections.Generic.IEnumerable System.Collections.Generic.IReadOnlyDictionary.Values { get { throw null; } } - bool System.Collections.ICollection.IsSynchronized { get { throw null; } } - object System.Collections.ICollection.SyncRoot { get { throw null; } } - bool System.Collections.IDictionary.IsFixedSize { get { throw null; } } - bool System.Collections.IDictionary.IsReadOnly { get { throw null; } } - object? System.Collections.IDictionary.this[object key] { get { throw null; } set { } } - System.Collections.ICollection System.Collections.IDictionary.Keys { get { throw null; } } - System.Collections.ICollection System.Collections.IDictionary.Values { get { throw null; } } - public System.Collections.ObjectModel.ReadOnlyDictionary.ValueCollection Values { get { throw null; } } - public bool ContainsKey(TKey key) { throw null; } - public System.Collections.Generic.IEnumerator> GetEnumerator() { throw null; } - void System.Collections.Generic.ICollection>.Add(System.Collections.Generic.KeyValuePair item) { } - void System.Collections.Generic.ICollection>.Clear() { } - bool System.Collections.Generic.ICollection>.Contains(System.Collections.Generic.KeyValuePair item) { throw null; } - void System.Collections.Generic.ICollection>.CopyTo(System.Collections.Generic.KeyValuePair[] array, int arrayIndex) { } - bool System.Collections.Generic.ICollection>.Remove(System.Collections.Generic.KeyValuePair item) { throw null; } - void System.Collections.Generic.IDictionary.Add(TKey key, TValue value) { } - bool System.Collections.Generic.IDictionary.Remove(TKey key) { throw null; } - void System.Collections.ICollection.CopyTo(System.Array array, int index) { } - void System.Collections.IDictionary.Add(object key, object? value) { } - void System.Collections.IDictionary.Clear() { } - bool System.Collections.IDictionary.Contains(object key) { throw null; } - System.Collections.IDictionaryEnumerator System.Collections.IDictionary.GetEnumerator() { throw null; } - void System.Collections.IDictionary.Remove(object key) { } - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } - public bool TryGetValue(TKey key, [System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out TValue value) { throw null; } - public sealed partial class KeyCollection : System.Collections.Generic.ICollection, System.Collections.Generic.IEnumerable, System.Collections.Generic.IReadOnlyCollection, System.Collections.ICollection, System.Collections.IEnumerable - { - internal KeyCollection() { } - public int Count { get { throw null; } } - bool System.Collections.Generic.ICollection.IsReadOnly { get { throw null; } } - bool System.Collections.ICollection.IsSynchronized { get { throw null; } } - object System.Collections.ICollection.SyncRoot { get { throw null; } } - public void CopyTo(TKey[] array, int arrayIndex) { } - public System.Collections.Generic.IEnumerator GetEnumerator() { throw null; } - void System.Collections.Generic.ICollection.Add(TKey item) { } - void System.Collections.Generic.ICollection.Clear() { } - bool System.Collections.Generic.ICollection.Contains(TKey item) { throw null; } - bool System.Collections.Generic.ICollection.Remove(TKey item) { throw null; } - void System.Collections.ICollection.CopyTo(System.Array array, int index) { } - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } - } - public sealed partial class ValueCollection : System.Collections.Generic.ICollection, System.Collections.Generic.IEnumerable, System.Collections.Generic.IReadOnlyCollection, System.Collections.ICollection, System.Collections.IEnumerable - { - internal ValueCollection() { } - public int Count { get { throw null; } } - bool System.Collections.Generic.ICollection.IsReadOnly { get { throw null; } } - bool System.Collections.ICollection.IsSynchronized { get { throw null; } } - object System.Collections.ICollection.SyncRoot { get { throw null; } } - public void CopyTo(TValue[] array, int arrayIndex) { } - public System.Collections.Generic.IEnumerator GetEnumerator() { throw null; } - void System.Collections.Generic.ICollection.Add(TValue item) { } - void System.Collections.Generic.ICollection.Clear() { } - bool System.Collections.Generic.ICollection.Contains(TValue item) { throw null; } - bool System.Collections.Generic.ICollection.Remove(TValue item) { throw null; } - void System.Collections.ICollection.CopyTo(System.Array array, int index) { } - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } - } - } public partial class ReadOnlyObservableCollection : System.Collections.ObjectModel.ReadOnlyCollection, System.Collections.Specialized.INotifyCollectionChanged, System.ComponentModel.INotifyPropertyChanged { public ReadOnlyObservableCollection(System.Collections.ObjectModel.ObservableCollection list) : base (default(System.Collections.Generic.IList)) { } diff --git a/src/libraries/System.ObjectModel/ref/System.ObjectModel.csproj b/src/libraries/System.ObjectModel/ref/System.ObjectModel.csproj index 9b427746cd8afa..623c85ec556705 100644 --- a/src/libraries/System.ObjectModel/ref/System.ObjectModel.csproj +++ b/src/libraries/System.ObjectModel/ref/System.ObjectModel.csproj @@ -5,6 +5,7 @@ + diff --git a/src/libraries/System.ObjectModel/src/System.ObjectModel.Forwards.cs b/src/libraries/System.ObjectModel/src/System.ObjectModel.Forwards.cs new file mode 100644 index 00000000000000..deb07efe4f82cb --- /dev/null +++ b/src/libraries/System.ObjectModel/src/System.ObjectModel.Forwards.cs @@ -0,0 +1,4 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Collections.ObjectModel.ReadOnlyDictionary<,>))] diff --git a/src/libraries/System.ObjectModel/src/System.ObjectModel.csproj b/src/libraries/System.ObjectModel/src/System.ObjectModel.csproj index 66c53d0dfb08b4..ecf4f2a77fe9e2 100644 --- a/src/libraries/System.ObjectModel/src/System.ObjectModel.csproj +++ b/src/libraries/System.ObjectModel/src/System.ObjectModel.csproj @@ -5,6 +5,7 @@ enable + @@ -12,7 +13,6 @@ - diff --git a/src/libraries/System.ObjectModel/src/System/Collections/CollectionHelpers.cs b/src/libraries/System.ObjectModel/src/System/Collections/CollectionHelpers.cs index 86058208873282..bff227728ecff7 100644 --- a/src/libraries/System.ObjectModel/src/System/Collections/CollectionHelpers.cs +++ b/src/libraries/System.ObjectModel/src/System/Collections/CollectionHelpers.cs @@ -34,40 +34,5 @@ internal static void ValidateCopyToArguments(int sourceCount, Array array, int i throw new ArgumentException(SR.Arg_ArrayPlusOffTooSmall); } } - - internal static void CopyTo(ICollection collection, Array array, int index) - { - ValidateCopyToArguments(collection.Count, array, index); - - if (collection is ICollection nonGenericCollection) - { - // Easy out if the ICollection implements the non-generic ICollection - nonGenericCollection.CopyTo(array, index); - } - else if (array is T[] items) - { - collection.CopyTo(items, index); - } - else - { - // We can't cast array of value type to object[], so we don't support widening of primitive types here. - if (array is not object?[] objects) - { - throw new ArgumentException(SR.Argument_InvalidArrayType, nameof(array)); - } - - try - { - foreach (T item in collection) - { - objects[index++] = item; - } - } - catch (ArrayTypeMismatchException) - { - throw new ArgumentException(SR.Argument_InvalidArrayType, nameof(array)); - } - } - } } } diff --git a/src/libraries/System.ObjectModel/src/System/Collections/Generic/DebugView.cs b/src/libraries/System.ObjectModel/src/System/Collections/Generic/DebugView.cs index 2233d2518fe36c..3ab6a770ca772b 100644 --- a/src/libraries/System.ObjectModel/src/System/Collections/Generic/DebugView.cs +++ b/src/libraries/System.ObjectModel/src/System/Collections/Generic/DebugView.cs @@ -25,25 +25,4 @@ public T[] Items } } } - - internal sealed class DictionaryDebugView where K: notnull - { - private readonly IDictionary _dict; - - public DictionaryDebugView(IDictionary dictionary) - { - _dict = dictionary ?? throw new ArgumentNullException(nameof(dictionary)); - } - - [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)] - public KeyValuePair[] Items - { - get - { - KeyValuePair[] items = new KeyValuePair[_dict.Count]; - _dict.CopyTo(items, 0); - return items; - } - } - } } diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 01fd0776225fa6..9723fc8954385a 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -228,7 +228,9 @@ + + diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/CollectionHelpers.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/CollectionHelpers.cs new file mode 100644 index 00000000000000..89af10ba7109f4 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/CollectionHelpers.cs @@ -0,0 +1,73 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections.Generic; + +namespace System.Collections.ObjectModel +{ + internal static class CollectionHelpers + { + internal static void ValidateCopyToArguments(int sourceCount, Array array, int index) + { + if (array == null) + { + throw new ArgumentNullException(nameof(array)); + } + + if (array.Rank != 1) + { + throw new ArgumentException(SR.Arg_RankMultiDimNotSupported, nameof(array)); + } + + if (array.GetLowerBound(0) != 0) + { + throw new ArgumentException(SR.Arg_NonZeroLowerBound, nameof(array)); + } + + if (index < 0 || index > array.Length) + { + throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum); + } + + if (array.Length - index < sourceCount) + { + throw new ArgumentException(SR.Arg_ArrayPlusOffTooSmall); + } + } + + internal static void CopyTo(ICollection collection, Array array, int index) + { + ValidateCopyToArguments(collection.Count, array, index); + + if (collection is ICollection nonGenericCollection) + { + // Easy out if the ICollection implements the non-generic ICollection + nonGenericCollection.CopyTo(array, index); + } + else if (array is T[] items) + { + collection.CopyTo(items, index); + } + else + { + // We can't cast array of value type to object[], so we don't support widening of primitive types here. + if (array is not object?[] objects) + { + throw new ArgumentException(SR.Argument_InvalidArrayType, nameof(array)); + } + + try + { + foreach (T item in collection) + { + objects[index++] = item; + } + } + catch (ArrayTypeMismatchException) + { + throw new ArgumentException(SR.Argument_InvalidArrayType, nameof(array)); + } + } + } + } +} diff --git a/src/libraries/System.ObjectModel/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs similarity index 98% rename from src/libraries/System.ObjectModel/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs rename to src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs index 428b0663d263ce..57c6b4604dc1d8 100644 --- a/src/libraries/System.ObjectModel/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs @@ -8,7 +8,7 @@ namespace System.Collections.ObjectModel { [Serializable] - [DebuggerTypeProxy(typeof(DictionaryDebugView<,>))] + [DebuggerTypeProxy(typeof(IDictionaryDebugView<,>))] [DebuggerDisplay("Count = {Count}")] [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public class ReadOnlyDictionary : IDictionary, IDictionary, IReadOnlyDictionary where TKey : notnull @@ -248,7 +248,7 @@ public DictionaryEntry Entry IEnumerable IReadOnlyDictionary.Values => Values; - [DebuggerTypeProxy(typeof(CollectionDebugView<>))] + [DebuggerTypeProxy(typeof(ICollectionDebugView<>))] [DebuggerDisplay("Count = {Count}")] public sealed class KeyCollection : ICollection, ICollection, IReadOnlyCollection { @@ -302,7 +302,7 @@ void ICollection.CopyTo(Array array, int index) object ICollection.SyncRoot => (_collection is ICollection coll) ? coll.SyncRoot : this; } - [DebuggerTypeProxy(typeof(CollectionDebugView<>))] + [DebuggerTypeProxy(typeof(ICollectionDebugView<>))] [DebuggerDisplay("Count = {Count}")] public sealed class ValueCollection : ICollection, ICollection, IReadOnlyCollection { diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index 7157e359ccd540..04b63cbf2a8070 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -8657,6 +8657,77 @@ void System.Collections.IList.Insert(int index, object? value) { } void System.Collections.IList.Remove(object? value) { } void System.Collections.IList.RemoveAt(int index) { } } + public partial class ReadOnlyDictionary : System.Collections.Generic.ICollection>, System.Collections.Generic.IDictionary, System.Collections.Generic.IEnumerable>, System.Collections.Generic.IReadOnlyCollection>, System.Collections.Generic.IReadOnlyDictionary, System.Collections.ICollection, System.Collections.IDictionary, System.Collections.IEnumerable where TKey : notnull + { + public ReadOnlyDictionary(System.Collections.Generic.IDictionary dictionary) { } + public int Count { get { throw null; } } + protected System.Collections.Generic.IDictionary Dictionary { get { throw null; } } + public TValue this[TKey key] { get { throw null; } } + public System.Collections.ObjectModel.ReadOnlyDictionary.KeyCollection Keys { get { throw null; } } + bool System.Collections.Generic.ICollection>.IsReadOnly { get { throw null; } } + TValue System.Collections.Generic.IDictionary.this[TKey key] { get { throw null; } set { } } + System.Collections.Generic.ICollection System.Collections.Generic.IDictionary.Keys { get { throw null; } } + System.Collections.Generic.ICollection System.Collections.Generic.IDictionary.Values { get { throw null; } } + System.Collections.Generic.IEnumerable System.Collections.Generic.IReadOnlyDictionary.Keys { get { throw null; } } + System.Collections.Generic.IEnumerable System.Collections.Generic.IReadOnlyDictionary.Values { get { throw null; } } + bool System.Collections.ICollection.IsSynchronized { get { throw null; } } + object System.Collections.ICollection.SyncRoot { get { throw null; } } + bool System.Collections.IDictionary.IsFixedSize { get { throw null; } } + bool System.Collections.IDictionary.IsReadOnly { get { throw null; } } + object? System.Collections.IDictionary.this[object key] { get { throw null; } set { } } + System.Collections.ICollection System.Collections.IDictionary.Keys { get { throw null; } } + System.Collections.ICollection System.Collections.IDictionary.Values { get { throw null; } } + public System.Collections.ObjectModel.ReadOnlyDictionary.ValueCollection Values { get { throw null; } } + public bool ContainsKey(TKey key) { throw null; } + public System.Collections.Generic.IEnumerator> GetEnumerator() { throw null; } + void System.Collections.Generic.ICollection>.Add(System.Collections.Generic.KeyValuePair item) { } + void System.Collections.Generic.ICollection>.Clear() { } + bool System.Collections.Generic.ICollection>.Contains(System.Collections.Generic.KeyValuePair item) { throw null; } + void System.Collections.Generic.ICollection>.CopyTo(System.Collections.Generic.KeyValuePair[] array, int arrayIndex) { } + bool System.Collections.Generic.ICollection>.Remove(System.Collections.Generic.KeyValuePair item) { throw null; } + void System.Collections.Generic.IDictionary.Add(TKey key, TValue value) { } + bool System.Collections.Generic.IDictionary.Remove(TKey key) { throw null; } + void System.Collections.ICollection.CopyTo(System.Array array, int index) { } + void System.Collections.IDictionary.Add(object key, object? value) { } + void System.Collections.IDictionary.Clear() { } + bool System.Collections.IDictionary.Contains(object key) { throw null; } + System.Collections.IDictionaryEnumerator System.Collections.IDictionary.GetEnumerator() { throw null; } + void System.Collections.IDictionary.Remove(object key) { } + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } + public bool TryGetValue(TKey key, [System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out TValue value) { throw null; } + public sealed partial class KeyCollection : System.Collections.Generic.ICollection, System.Collections.Generic.IEnumerable, System.Collections.Generic.IReadOnlyCollection, System.Collections.ICollection, System.Collections.IEnumerable + { + internal KeyCollection() { } + public int Count { get { throw null; } } + bool System.Collections.Generic.ICollection.IsReadOnly { get { throw null; } } + bool System.Collections.ICollection.IsSynchronized { get { throw null; } } + object System.Collections.ICollection.SyncRoot { get { throw null; } } + public void CopyTo(TKey[] array, int arrayIndex) { } + public System.Collections.Generic.IEnumerator GetEnumerator() { throw null; } + void System.Collections.Generic.ICollection.Add(TKey item) { } + void System.Collections.Generic.ICollection.Clear() { } + bool System.Collections.Generic.ICollection.Contains(TKey item) { throw null; } + bool System.Collections.Generic.ICollection.Remove(TKey item) { throw null; } + void System.Collections.ICollection.CopyTo(System.Array array, int index) { } + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } + } + public sealed partial class ValueCollection : System.Collections.Generic.ICollection, System.Collections.Generic.IEnumerable, System.Collections.Generic.IReadOnlyCollection, System.Collections.ICollection, System.Collections.IEnumerable + { + internal ValueCollection() { } + public int Count { get { throw null; } } + bool System.Collections.Generic.ICollection.IsReadOnly { get { throw null; } } + bool System.Collections.ICollection.IsSynchronized { get { throw null; } } + object System.Collections.ICollection.SyncRoot { get { throw null; } } + public void CopyTo(TValue[] array, int arrayIndex) { } + public System.Collections.Generic.IEnumerator GetEnumerator() { throw null; } + void System.Collections.Generic.ICollection.Add(TValue item) { } + void System.Collections.Generic.ICollection.Clear() { } + bool System.Collections.Generic.ICollection.Contains(TValue item) { throw null; } + bool System.Collections.Generic.ICollection.Remove(TValue item) { throw null; } + void System.Collections.ICollection.CopyTo(System.Array array, int index) { } + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } + } + } } namespace System.ComponentModel { diff --git a/src/libraries/shims/ApiCompatBaseline.PreviousNetCoreApp.txt b/src/libraries/shims/ApiCompatBaseline.PreviousNetCoreApp.txt index 32beb555e41775..0fdeb001ef9d87 100644 --- a/src/libraries/shims/ApiCompatBaseline.PreviousNetCoreApp.txt +++ b/src/libraries/shims/ApiCompatBaseline.PreviousNetCoreApp.txt @@ -226,6 +226,8 @@ CannotRemoveAttribute : Attribute 'System.Runtime.CompilerServices.IsReadOnlyAtt CannotRemoveAttribute : Attribute 'System.Runtime.CompilerServices.IsReadOnlyAttribute' exists on 'System.Numerics.Vector.ToString(System.String, System.IFormatProvider)' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.CompilerServices.IsReadOnlyAttribute' exists on 'System.Numerics.Vector.TryCopyTo(System.Span)' in the contract but not the implementation. CannotRemoveAttribute : Attribute 'System.Runtime.CompilerServices.IsReadOnlyAttribute' exists on 'System.Numerics.Vector.TryCopyTo(System.Span)' in the contract but not the implementation. +Compat issues with assembly System.ObjectModel: +TypesMustExist : Type 'System.Collections.ObjectModel.ReadOnlyDictionary' does not exist in the implementation but it does exist in the contract. Compat issues with assembly System.Reflection.Emit: CannotChangeAttribute : Attribute 'System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute' on 'System.Reflection.Emit.EnumBuilder.GetMember(System.String, System.Reflection.MemberTypes, System.Reflection.BindingFlags)' changed from '[DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes.All)]' in the contract to '[DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.NonPublicEvents | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.NonPublicMethods | DynamicallyAccessedMemberTypes.NonPublicNestedTypes | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.PublicEvents | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicNestedTypes | DynamicallyAccessedMemberTypes.PublicProperties)]' in the implementation. CannotChangeAttribute : Attribute 'System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute' on 'System.Reflection.Emit.EnumBuilder.GetMembers(System.Reflection.BindingFlags)' changed from '[DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes.All)]' in the contract to '[DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.NonPublicEvents | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.NonPublicMethods | DynamicallyAccessedMemberTypes.NonPublicNestedTypes | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.PublicEvents | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicNestedTypes | DynamicallyAccessedMemberTypes.PublicProperties)]' in the implementation. @@ -303,4 +305,4 @@ CannotRemoveAttribute : Attribute 'System.Diagnostics.CodeAnalysis.DynamicallyAc CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'System.Text.Json.Serialization.JsonConverterAttribute' changed from '[AttributeUsageAttribute(AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Struct, AllowMultiple=false)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Field | AttributeTargets.Interface | AttributeTargets.Property | AttributeTargets.Struct, AllowMultiple=false)]' in the implementation. Compat issues with assembly System.Threading.Tasks.Extensions: CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'System.Runtime.CompilerServices.AsyncMethodBuilderAttribute' changed from '[AttributeUsageAttribute(AttributeTargets.Class | AttributeTargets.Delegate | AttributeTargets.Enum | AttributeTargets.Interface | AttributeTargets.Struct, Inherited=false, AllowMultiple=false)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Class | AttributeTargets.Delegate | AttributeTargets.Enum | AttributeTargets.Interface | AttributeTargets.Method | AttributeTargets.Struct, Inherited=false, AllowMultiple=false)]' in the implementation. -Total Issues: 286 +Total Issues: 287 diff --git a/src/libraries/shims/ApiCompatBaseline.netcoreapp.netstandard.txt b/src/libraries/shims/ApiCompatBaseline.netcoreapp.netstandard.txt index 1d4a30c30f10ea..40ec257771a8bc 100644 --- a/src/libraries/shims/ApiCompatBaseline.netcoreapp.netstandard.txt +++ b/src/libraries/shims/ApiCompatBaseline.netcoreapp.netstandard.txt @@ -630,4 +630,5 @@ CannotSealType : Type 'System.Xml.Schema.XmlSchemaGroupBase' is effectively (has MembersMustExist : Member 'protected void System.Xml.Schema.XmlSchemaGroupBase..ctor()' does not exist in the implementation but it does exist in the contract. CannotMakeMemberNonVirtual : Member 'public System.Xml.Schema.XmlSchemaObjectCollection System.Xml.Schema.XmlSchemaGroupBase.Items' is non-virtual in the implementation but is virtual in the contract. CannotMakeMemberNonVirtual : Member 'public System.Xml.Schema.XmlSchemaObjectCollection System.Xml.Schema.XmlSchemaGroupBase.Items.get()' is non-virtual in the implementation but is virtual in the contract. -Total Issues: 617 +TypesMustExist : Type 'System.Collections.ObjectModel.ReadOnlyDictionary' does not exist in the implementation but it does exist in the contract. +Total Issues: 618