From 417d97e156fe1d654628044625c40ce0895c6683 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Wed, 1 May 2019 21:20:50 -0700 Subject: [PATCH] Nullable: System.Collections remainder (non-generic) (dotnet/coreclr#24326) * Nullable: System.Collections remainder (non-generic) * apply feedback Commit migrated from https://github.com/dotnet/coreclr/commit/8811118a19fcd9728753505e93ecac5ff786dab4 --- .../Collections/ObjectModel/ReadOnlyDictionary.cs | 14 +- .../WindowsRuntime/CLRIReferenceImpl.cs | 12 +- .../WindowsRuntime/ListToBindableVectorAdapter.cs | 10 +- .../src/System/Collections/ArrayList.cs | 259 +++++++++++---------- .../src/System/Collections/Comparer.cs | 7 +- .../src/System/Collections/CompatibleComparer.cs | 15 +- .../HashHelpers.SerializationInfoTable.cs | 7 +- .../src/System/Collections/HashHelpers.cs | 2 +- .../src/System/Collections/Hashtable.cs | 113 ++++----- .../src/System/Collections/ICollection.cs | 1 + .../src/System/Collections/IHashCodeProvider.cs | 1 + .../src/System/Collections/IList.cs | 13 +- .../System/Collections/IStructuralComparable.cs | 3 +- .../src/System/Collections/KeyValuePairs.cs | 5 +- .../System/Collections/ListDictionaryInternal.cs | 48 ++-- .../Collections/ObjectModel/ReadOnlyCollection.cs | 6 +- .../src/System/CurrentSystemTimeZone.cs | 2 +- .../src/System/Security/SecurityElement.cs | 18 +- .../src/System/Text/EncodingTable.cs | 2 +- .../System.Private.CoreLib/src/System/Tuple.cs | 16 +- .../src/System/ValueTuple.cs | 18 +- 21 files changed, 292 insertions(+), 280 deletions(-) diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs index d037851..4a4634f 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs @@ -334,7 +334,7 @@ namespace System.Collections.ObjectModel get { return false; } } - object? ICollection.SyncRoot + object ICollection.SyncRoot { get { @@ -349,7 +349,7 @@ namespace System.Collections.ObjectModel Interlocked.CompareExchange(ref m_syncRoot, new object(), null); } } - return m_syncRoot; + return m_syncRoot!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34901 } } @@ -503,7 +503,7 @@ namespace System.Collections.ObjectModel get { return false; } } - object? ICollection.SyncRoot + object ICollection.SyncRoot { get { @@ -515,10 +515,10 @@ namespace System.Collections.ObjectModel } else { - Interlocked.CompareExchange(ref m_syncRoot, new object(), null); + Interlocked.CompareExchange(ref m_syncRoot, new object(), null); // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34901 } } - return m_syncRoot; + return m_syncRoot!; } } @@ -611,7 +611,7 @@ namespace System.Collections.ObjectModel get { return false; } } - object? ICollection.SyncRoot + object ICollection.SyncRoot { get { @@ -626,7 +626,7 @@ namespace System.Collections.ObjectModel Interlocked.CompareExchange(ref m_syncRoot, new object(), null); } } - return m_syncRoot; + return m_syncRoot!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34901 } } diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIReferenceImpl.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIReferenceImpl.cs index b9e9eb6..f51dda6 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIReferenceImpl.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIReferenceImpl.cs @@ -104,7 +104,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // IList & ICollection methods. // This enables two-way data binding and index access in Jupiter // - object IList.this[int index] + object? IList.this[int index] { get { @@ -117,12 +117,12 @@ namespace System.Runtime.InteropServices.WindowsRuntime } } - int IList.Add(object value) + int IList.Add(object? value) { return _list.Add(value); } - bool IList.Contains(object value) + bool IList.Contains(object? value) { return _list.Contains(value); } @@ -148,17 +148,17 @@ namespace System.Runtime.InteropServices.WindowsRuntime } } - int IList.IndexOf(object value) + int IList.IndexOf(object? value) { return _list.IndexOf(value); } - void IList.Insert(int index, object value) + void IList.Insert(int index, object? value) { _list.Insert(index, value); } - void IList.Remove(object value) + void IList.Remove(object? value) { _list.Remove(value); } diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorAdapter.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorAdapter.cs index 828fc15..e2fe340 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorAdapter.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorAdapter.cs @@ -25,7 +25,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // object GetAt(uint index) - internal object GetAt(uint index) + internal object? GetAt(uint index) { IList _this = Unsafe.As(this); EnsureIndexInt32(index, _this.Count); @@ -55,7 +55,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // bool IndexOf(object value, out uint index) - internal bool IndexOf(object value, out uint index) + internal bool IndexOf(object? value, out uint index) { IList _this = Unsafe.As(this); int ind = _this.IndexOf(value); @@ -71,7 +71,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void SetAt(uint index, object value) - internal void SetAt(uint index, object value) + internal void SetAt(uint index, object? value) { IList _this = Unsafe.As(this); EnsureIndexInt32(index, _this.Count); @@ -87,7 +87,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void InsertAt(uint index, object value) - internal void InsertAt(uint index, object value) + internal void InsertAt(uint index, object? value) { IList _this = Unsafe.As(this); @@ -126,7 +126,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime } // void Append(object value) - internal void Append(object value) + internal void Append(object? value) { IList _this = Unsafe.As(this); _this.Add(value); diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/ArrayList.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/ArrayList.cs index d2ccc23..1f6c490 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/ArrayList.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/ArrayList.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable /*============================================================ ** ** Class: ArrayList @@ -33,7 +34,7 @@ namespace System.Collections #endif public class ArrayList : IList, ICloneable { - private object[] _items; // Do not rename (binary serialization) + private object?[] _items = null!; // Do not rename (binary serialization) private int _size; // Do not rename (binary serialization) private int _version; // Do not rename (binary serialization) @@ -161,7 +162,7 @@ namespace System.Collections // Sets or Gets the element at the given index. // - public virtual object this[int index] + public virtual object? this[int index] { get { @@ -195,7 +196,7 @@ namespace System.Collections // increased by one. If required, the capacity of the list is doubled // before adding the new element. // - public virtual int Add(object value) + public virtual int Add(object? value) { if (_size == _items.Length) EnsureCapacity(_size + 1); _items[_size] = value; @@ -232,7 +233,7 @@ namespace System.Collections // The method uses the Array.BinarySearch method to perform the // search. // - public virtual int BinarySearch(int index, int count, object value, IComparer comparer) + public virtual int BinarySearch(int index, int count, object? value, IComparer? comparer) { if (index < 0) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum); @@ -244,12 +245,12 @@ namespace System.Collections return Array.BinarySearch((Array)_items, index, count, value, comparer); } - public virtual int BinarySearch(object value) + public virtual int BinarySearch(object? value) { return BinarySearch(0, Count, value, null); } - public virtual int BinarySearch(object value, IComparer comparer) + public virtual int BinarySearch(object? value, IComparer? comparer) { return BinarySearch(0, Count, value, comparer); } @@ -283,7 +284,7 @@ namespace System.Collections // It does a linear, O(n) search. Equality is determined by calling // item.Equals(). // - public virtual bool Contains(object item) + public virtual bool Contains(object? item) { if (item == null) { @@ -295,7 +296,7 @@ namespace System.Collections else { for (int i = 0; i < _size; i++) - if ((_items[i] != null) && (_items[i].Equals(item))) + if ((_items[i] != null) && (_items[i]!.Equals(item))) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644 return true; return false; } @@ -318,7 +319,7 @@ namespace System.Collections throw new ArgumentException(SR.Arg_RankMultiDimNotSupported, nameof(array)); // Delegate rest of error checking to Array.Copy. - Array.Copy(_items, 0, array, arrayIndex, _size); + Array.Copy(_items, 0, array!, arrayIndex, _size); } // Copies a section of this list to the given array at the given index. @@ -333,7 +334,7 @@ namespace System.Collections throw new ArgumentException(SR.Arg_RankMultiDimNotSupported, nameof(array)); // Delegate rest of error checking to Array.Copy. - Array.Copy(_items, index, array, arrayIndex, count); + Array.Copy(_items, index, array!, arrayIndex, count); } // Ensures that the capacity of this list is at least the given minimum @@ -407,7 +408,7 @@ namespace System.Collections // This method uses the Array.IndexOf method to perform the // search. // - public virtual int IndexOf(object value) + public virtual int IndexOf(object? value) { return Array.IndexOf((Array)_items, value, 0, _size); } @@ -421,7 +422,7 @@ namespace System.Collections // This method uses the Array.IndexOf method to perform the // search. // - public virtual int IndexOf(object value, int startIndex) + public virtual int IndexOf(object? value, int startIndex) { if (startIndex > _size) throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index); @@ -437,7 +438,7 @@ namespace System.Collections // This method uses the Array.IndexOf method to perform the // search. // - public virtual int IndexOf(object value, int startIndex, int count) + public virtual int IndexOf(object? value, int startIndex, int count) { if (startIndex > _size) throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index); @@ -449,7 +450,7 @@ namespace System.Collections // is increased by one. If required, the capacity of the list is doubled // before inserting the new element. // - public virtual void Insert(int index, object value) + public virtual void Insert(int index, object? value) { // Note that insertions at the end are legal. if (index < 0 || index > _size) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); @@ -501,7 +502,7 @@ namespace System.Collections // This method uses the Array.LastIndexOf method to perform the // search. // - public virtual int LastIndexOf(object value) + public virtual int LastIndexOf(object? value) { return LastIndexOf(value, _size - 1, _size); } @@ -515,7 +516,7 @@ namespace System.Collections // This method uses the Array.LastIndexOf method to perform the // search. // - public virtual int LastIndexOf(object value, int startIndex) + public virtual int LastIndexOf(object? value, int startIndex) { if (startIndex >= _size) throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index); @@ -531,7 +532,7 @@ namespace System.Collections // This method uses the Array.LastIndexOf method to perform the // search. // - public virtual int LastIndexOf(object value, int startIndex, int count) + public virtual int LastIndexOf(object? value, int startIndex, int count) { if (Count != 0 && (startIndex < 0 || count < 0)) throw new ArgumentOutOfRangeException(startIndex < 0 ? nameof(startIndex) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum); @@ -566,7 +567,7 @@ namespace System.Collections // Removes the element at the given index. The size of the list is // decreased by one. // - public virtual void Remove(object obj) + public virtual void Remove(object? obj) { int index = IndexOf(obj); if (index >= 0) @@ -615,7 +616,7 @@ namespace System.Collections // Returns an IList that contains count copies of value. // - public static ArrayList Repeat(object value, int count) + public static ArrayList Repeat(object? value, int count) { if (count < 0) throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum); @@ -688,7 +689,7 @@ namespace System.Collections // Sorts the elements in this list. Uses Array.Sort with the // provided comparer. - public virtual void Sort(IComparer comparer) + public virtual void Sort(IComparer? comparer) { Sort(0, Count, comparer); } @@ -701,7 +702,7 @@ namespace System.Collections // // This method uses the Array.Sort method to sort the elements. // - public virtual void Sort(int index, int count, IComparer comparer) + public virtual void Sort(int index, int count, IComparer? comparer) { if (index < 0) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum); @@ -734,12 +735,12 @@ namespace System.Collections // ToArray returns a new Object array containing the contents of the ArrayList. // This requires copying the ArrayList, which is an O(n) operation. - public virtual object[] ToArray() + public virtual object?[] ToArray() { if (_size == 0) return Array.Empty(); - object[] array = new object[_size]; + object?[] array = new object[_size]; Array.Copy(_items, 0, array, 0, _size); return array; } @@ -816,7 +817,7 @@ namespace System.Collections get { return _list.IsSynchronized; } } - public override object this[int index] + public override object? this[int index] { get { @@ -834,7 +835,7 @@ namespace System.Collections get { return _list.SyncRoot; } } - public override int Add(object obj) + public override int Add(object? obj) { int i = _list.Add(obj); _version++; @@ -847,7 +848,7 @@ namespace System.Collections } // Other overloads with automatically work - public override int BinarySearch(int index, int count, object value, IComparer comparer) + public override int BinarySearch(int index, int count, object? value, IComparer? comparer) { if (index < 0 || count < 0) throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum); @@ -896,7 +897,7 @@ namespace System.Collections return new IListWrapper(_list); } - public override bool Contains(object obj) + public override bool Contains(object? obj) { return _list.Contains(obj); } @@ -942,18 +943,18 @@ namespace System.Collections return new IListWrapperEnumWrapper(this, index, count); } - public override int IndexOf(object value) + public override int IndexOf(object? value) { return _list.IndexOf(value); } [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. - public override int IndexOf(object value, int startIndex) + public override int IndexOf(object? value, int startIndex) { return IndexOf(value, startIndex, _list.Count - startIndex); } - public override int IndexOf(object value, int startIndex, int count) + public override int IndexOf(object? value, int startIndex, int count) { if (startIndex < 0 || startIndex > Count) throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index); if (count < 0 || startIndex > Count - count) throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Count); @@ -969,13 +970,13 @@ namespace System.Collections else { for (int i = startIndex; i < endIndex; i++) - if (_list[i] != null && _list[i].Equals(value)) + if (_list[i] != null && _list[i]!.Equals(value)) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644 return i; return -1; } } - public override void Insert(int index, object obj) + public override void Insert(int index, object? obj) { _list.Insert(index, obj); _version++; @@ -989,7 +990,7 @@ namespace System.Collections if (c.Count > 0) { - ArrayList al = _list as ArrayList; + ArrayList? al = _list as ArrayList; if (al != null) { // We need to special case ArrayList. @@ -1009,19 +1010,19 @@ namespace System.Collections } } - public override int LastIndexOf(object value) + public override int LastIndexOf(object? value) { return LastIndexOf(value, _list.Count - 1, _list.Count); } [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. - public override int LastIndexOf(object value, int startIndex) + public override int LastIndexOf(object? value, int startIndex) { return LastIndexOf(value, startIndex, startIndex + 1); } [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. - public override int LastIndexOf(object value, int startIndex, int count) + public override int LastIndexOf(object? value, int startIndex, int count) { if (_list.Count == 0) return -1; @@ -1040,13 +1041,13 @@ namespace System.Collections else { for (int i = startIndex; i >= endIndex; i--) - if (_list[i] != null && _list[i].Equals(value)) + if (_list[i] != null && _list[i]!.Equals(value)) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644 return i; return -1; } } - public override void Remove(object value) + public override void Remove(object? value) { int index = IndexOf(value); if (index >= 0) @@ -1089,7 +1090,7 @@ namespace System.Collections int j = index + count - 1; while (i < j) { - object tmp = _list[i]; + object? tmp = _list[i]; _list[i++] = _list[j]; _list[j--] = tmp; } @@ -1128,7 +1129,7 @@ namespace System.Collections return new Range(this, index, count); } - public override void Sort(int index, int count, IComparer comparer) + public override void Sort(int index, int count, IComparer? comparer) { if (index < 0 || count < 0) throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum); @@ -1145,12 +1146,12 @@ namespace System.Collections } - public override object[] ToArray() + public override object?[] ToArray() { if (Count == 0) - return Array.Empty(); + return Array.Empty(); - object[] array = new object[Count]; + object?[] array = new object[Count]; _list.CopyTo(array, 0); return array; } @@ -1174,7 +1175,7 @@ namespace System.Collections // class that implements all of ArrayList's methods. private sealed class IListWrapperEnumWrapper : IEnumerator, ICloneable { - private IEnumerator _en; + private IEnumerator _en = null!; private int _remaining; private int _initialStartIndex; // for reset private int _initialCount; // for reset @@ -1216,7 +1217,7 @@ namespace System.Collections return r && _remaining-- > 0; } - public object Current + public object? Current { get { @@ -1291,7 +1292,7 @@ namespace System.Collections get { return true; } } - public override object this[int index] + public override object? this[int index] { get { @@ -1314,7 +1315,7 @@ namespace System.Collections get { return _root; } } - public override int Add(object value) + public override int Add(object? value) { lock (_root) { @@ -1330,7 +1331,7 @@ namespace System.Collections } } - public override int BinarySearch(object value) + public override int BinarySearch(object? value) { lock (_root) { @@ -1338,7 +1339,7 @@ namespace System.Collections } } - public override int BinarySearch(object value, IComparer comparer) + public override int BinarySearch(object? value, IComparer? comparer) { lock (_root) { @@ -1347,7 +1348,7 @@ namespace System.Collections } [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. - public override int BinarySearch(int index, int count, object value, IComparer comparer) + public override int BinarySearch(int index, int count, object? value, IComparer? comparer) { lock (_root) { @@ -1371,7 +1372,7 @@ namespace System.Collections } } - public override bool Contains(object item) + public override bool Contains(object? item) { lock (_root) { @@ -1421,7 +1422,7 @@ namespace System.Collections } } - public override int IndexOf(object value) + public override int IndexOf(object? value) { lock (_root) { @@ -1430,7 +1431,7 @@ namespace System.Collections } [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. - public override int IndexOf(object value, int startIndex) + public override int IndexOf(object? value, int startIndex) { lock (_root) { @@ -1439,7 +1440,7 @@ namespace System.Collections } [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. - public override int IndexOf(object value, int startIndex, int count) + public override int IndexOf(object? value, int startIndex, int count) { lock (_root) { @@ -1447,7 +1448,7 @@ namespace System.Collections } } - public override void Insert(int index, object value) + public override void Insert(int index, object? value) { lock (_root) { @@ -1464,7 +1465,7 @@ namespace System.Collections } } - public override int LastIndexOf(object value) + public override int LastIndexOf(object? value) { lock (_root) { @@ -1473,7 +1474,7 @@ namespace System.Collections } [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. - public override int LastIndexOf(object value, int startIndex) + public override int LastIndexOf(object? value, int startIndex) { lock (_root) { @@ -1482,7 +1483,7 @@ namespace System.Collections } [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. - public override int LastIndexOf(object value, int startIndex, int count) + public override int LastIndexOf(object? value, int startIndex, int count) { lock (_root) { @@ -1490,7 +1491,7 @@ namespace System.Collections } } - public override void Remove(object value) + public override void Remove(object? value) { lock (_root) { @@ -1550,7 +1551,7 @@ namespace System.Collections } } - public override void Sort(IComparer comparer) + public override void Sort(IComparer? comparer) { lock (_root) { @@ -1559,7 +1560,7 @@ namespace System.Collections } [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. - public override void Sort(int index, int count, IComparer comparer) + public override void Sort(int index, int count, IComparer? comparer) { lock (_root) { @@ -1567,7 +1568,7 @@ namespace System.Collections } } - public override object[] ToArray() + public override object?[] ToArray() { lock (_root) { @@ -1626,7 +1627,7 @@ namespace System.Collections get { return true; } } - public virtual object this[int index] + public virtual object? this[int index] { get { @@ -1649,7 +1650,7 @@ namespace System.Collections get { return _root; } } - public virtual int Add(object value) + public virtual int Add(object? value) { lock (_root) { @@ -1666,7 +1667,7 @@ namespace System.Collections } } - public virtual bool Contains(object item) + public virtual bool Contains(object? item) { lock (_root) { @@ -1690,7 +1691,7 @@ namespace System.Collections } } - public virtual int IndexOf(object value) + public virtual int IndexOf(object? value) { lock (_root) { @@ -1698,7 +1699,7 @@ namespace System.Collections } } - public virtual void Insert(int index, object value) + public virtual void Insert(int index, object? value) { lock (_root) { @@ -1706,7 +1707,7 @@ namespace System.Collections } } - public virtual void Remove(object value) + public virtual void Remove(object? value) { lock (_root) { @@ -1752,7 +1753,7 @@ namespace System.Collections get { return _list.IsSynchronized; } } - public virtual object this[int index] + public virtual object? this[int index] { get { @@ -1769,7 +1770,7 @@ namespace System.Collections get { return _list.SyncRoot; } } - public virtual int Add(object obj) + public virtual int Add(object? obj) { throw new NotSupportedException(SR.NotSupported_FixedSizeCollection); } @@ -1779,7 +1780,7 @@ namespace System.Collections throw new NotSupportedException(SR.NotSupported_FixedSizeCollection); } - public virtual bool Contains(object obj) + public virtual bool Contains(object? obj) { return _list.Contains(obj); } @@ -1794,17 +1795,17 @@ namespace System.Collections return _list.GetEnumerator(); } - public virtual int IndexOf(object value) + public virtual int IndexOf(object? value) { return _list.IndexOf(value); } - public virtual void Insert(int index, object obj) + public virtual void Insert(int index, object? obj) { throw new NotSupportedException(SR.NotSupported_FixedSizeCollection); } - public virtual void Remove(object value) + public virtual void Remove(object? value) { throw new NotSupportedException(SR.NotSupported_FixedSizeCollection); } @@ -1845,7 +1846,7 @@ namespace System.Collections get { return _list.IsSynchronized; } } - public override object this[int index] + public override object? this[int index] { get { @@ -1863,7 +1864,7 @@ namespace System.Collections get { return _list.SyncRoot; } } - public override int Add(object obj) + public override int Add(object? obj) { throw new NotSupportedException(SR.NotSupported_FixedSizeCollection); } @@ -1874,7 +1875,7 @@ namespace System.Collections } [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. - public override int BinarySearch(int index, int count, object value, IComparer comparer) + public override int BinarySearch(int index, int count, object? value, IComparer? comparer) { return _list.BinarySearch(index, count, value, comparer); } @@ -1899,7 +1900,7 @@ namespace System.Collections return arrayList; } - public override bool Contains(object obj) + public override bool Contains(object? obj) { return _list.Contains(obj); } @@ -1926,24 +1927,24 @@ namespace System.Collections return _list.GetEnumerator(index, count); } - public override int IndexOf(object value) + public override int IndexOf(object? value) { return _list.IndexOf(value); } [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. - public override int IndexOf(object value, int startIndex) + public override int IndexOf(object? value, int startIndex) { return _list.IndexOf(value, startIndex); } [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. - public override int IndexOf(object value, int startIndex, int count) + public override int IndexOf(object? value, int startIndex, int count) { return _list.IndexOf(value, startIndex, count); } - public override void Insert(int index, object obj) + public override void Insert(int index, object? obj) { throw new NotSupportedException(SR.NotSupported_FixedSizeCollection); } @@ -1954,24 +1955,24 @@ namespace System.Collections throw new NotSupportedException(SR.NotSupported_FixedSizeCollection); } - public override int LastIndexOf(object value) + public override int LastIndexOf(object? value) { return _list.LastIndexOf(value); } [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. - public override int LastIndexOf(object value, int startIndex) + public override int LastIndexOf(object? value, int startIndex) { return _list.LastIndexOf(value, startIndex); } [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. - public override int LastIndexOf(object value, int startIndex, int count) + public override int LastIndexOf(object? value, int startIndex, int count) { return _list.LastIndexOf(value, startIndex, count); } - public override void Remove(object value) + public override void Remove(object? value) { throw new NotSupportedException(SR.NotSupported_FixedSizeCollection); } @@ -2012,13 +2013,13 @@ namespace System.Collections } [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. - public override void Sort(int index, int count, IComparer comparer) + public override void Sort(int index, int count, IComparer? comparer) { _list.Sort(index, count, comparer); _version = _list._version; } - public override object[] ToArray() + public override object?[] ToArray() { return _list.ToArray(); } @@ -2064,7 +2065,7 @@ namespace System.Collections get { return _list.IsSynchronized; } } - public virtual object this[int index] + public virtual object? this[int index] { get { @@ -2081,7 +2082,7 @@ namespace System.Collections get { return _list.SyncRoot; } } - public virtual int Add(object obj) + public virtual int Add(object? obj) { throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection); } @@ -2091,7 +2092,7 @@ namespace System.Collections throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection); } - public virtual bool Contains(object obj) + public virtual bool Contains(object? obj) { return _list.Contains(obj); } @@ -2106,17 +2107,17 @@ namespace System.Collections return _list.GetEnumerator(); } - public virtual int IndexOf(object value) + public virtual int IndexOf(object? value) { return _list.IndexOf(value); } - public virtual void Insert(int index, object obj) + public virtual void Insert(int index, object? obj) { throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection); } - public virtual void Remove(object value) + public virtual void Remove(object? value) { throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection); } @@ -2156,7 +2157,7 @@ namespace System.Collections get { return _list.IsSynchronized; } } - public override object this[int index] + public override object? this[int index] { get { @@ -2173,7 +2174,7 @@ namespace System.Collections get { return _list.SyncRoot; } } - public override int Add(object obj) + public override int Add(object? obj) { throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection); } @@ -2184,7 +2185,7 @@ namespace System.Collections } [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. - public override int BinarySearch(int index, int count, object value, IComparer comparer) + public override int BinarySearch(int index, int count, object? value, IComparer? comparer) { return _list.BinarySearch(index, count, value, comparer); } @@ -2210,7 +2211,7 @@ namespace System.Collections return arrayList; } - public override bool Contains(object obj) + public override bool Contains(object? obj) { return _list.Contains(obj); } @@ -2237,24 +2238,24 @@ namespace System.Collections return _list.GetEnumerator(index, count); } - public override int IndexOf(object value) + public override int IndexOf(object? value) { return _list.IndexOf(value); } [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. - public override int IndexOf(object value, int startIndex) + public override int IndexOf(object? value, int startIndex) { return _list.IndexOf(value, startIndex); } [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. - public override int IndexOf(object value, int startIndex, int count) + public override int IndexOf(object? value, int startIndex, int count) { return _list.IndexOf(value, startIndex, count); } - public override void Insert(int index, object obj) + public override void Insert(int index, object? obj) { throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection); } @@ -2265,24 +2266,24 @@ namespace System.Collections throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection); } - public override int LastIndexOf(object value) + public override int LastIndexOf(object? value) { return _list.LastIndexOf(value); } [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. - public override int LastIndexOf(object value, int startIndex) + public override int LastIndexOf(object? value, int startIndex) { return _list.LastIndexOf(value, startIndex); } [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. - public override int LastIndexOf(object value, int startIndex, int count) + public override int LastIndexOf(object? value, int startIndex, int count) { return _list.LastIndexOf(value, startIndex, count); } - public override void Remove(object value) + public override void Remove(object? value) { throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection); } @@ -2321,12 +2322,12 @@ namespace System.Collections } [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. - public override void Sort(int index, int count, IComparer comparer) + public override void Sort(int index, int count, IComparer? comparer) { throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection); } - public override object[] ToArray() + public override object?[] ToArray() { return _list.ToArray(); } @@ -2353,7 +2354,7 @@ namespace System.Collections private int _index; private int _endIndex; // Where to stop. private int _version; - private object _currentElement; + private object? _currentElement; private int _startIndex; // Save this for Reset. internal ArrayListEnumerator(ArrayList list, int index, int count) @@ -2384,7 +2385,7 @@ namespace System.Collections return false; } - public object Current + public object? Current { get { @@ -2436,7 +2437,7 @@ namespace System.Collections _version++; } - public override int Add(object value) + public override int Add(object? value) { InternalUpdateRange(); _baseList.Insert(_baseIndex + _baseSize, value); @@ -2461,7 +2462,7 @@ namespace System.Collections } } - public override int BinarySearch(int index, int count, object value, IComparer comparer) + public override int BinarySearch(int index, int count, object? value, IComparer? comparer) { if (index < 0 || count < 0) throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum); @@ -2508,7 +2509,7 @@ namespace System.Collections return arrayList; } - public override bool Contains(object item) + public override bool Contains(object? item) { InternalUpdateRange(); if (item == null) @@ -2521,7 +2522,7 @@ namespace System.Collections else { for (int i = 0; i < _baseSize; i++) - if (_baseList[_baseIndex + i] != null && _baseList[_baseIndex + i].Equals(item)) + if (_baseList[_baseIndex + i] != null && _baseList[_baseIndex + i]!.Equals(item)) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644 return true; return false; } @@ -2619,7 +2620,7 @@ namespace System.Collections } - public override int IndexOf(object value) + public override int IndexOf(object? value) { InternalUpdateRange(); int i = _baseList.IndexOf(value, _baseIndex, _baseSize); @@ -2627,7 +2628,7 @@ namespace System.Collections return -1; } - public override int IndexOf(object value, int startIndex) + public override int IndexOf(object? value, int startIndex) { if (startIndex < 0) throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_NeedNonNegNum); @@ -2640,7 +2641,7 @@ namespace System.Collections return -1; } - public override int IndexOf(object value, int startIndex, int count) + public override int IndexOf(object? value, int startIndex, int count) { if (startIndex < 0 || startIndex > _baseSize) throw new ArgumentOutOfRangeException(nameof(startIndex), SR.ArgumentOutOfRange_Index); @@ -2654,7 +2655,7 @@ namespace System.Collections return -1; } - public override void Insert(int index, object value) + public override void Insert(int index, object? value) { if (index < 0 || index > _baseSize) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index); @@ -2682,7 +2683,7 @@ namespace System.Collections } } - public override int LastIndexOf(object value) + public override int LastIndexOf(object? value) { InternalUpdateRange(); int i = _baseList.LastIndexOf(value, _baseIndex + _baseSize - 1, _baseSize); @@ -2691,13 +2692,13 @@ namespace System.Collections } [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. - public override int LastIndexOf(object value, int startIndex) + public override int LastIndexOf(object? value, int startIndex) { return LastIndexOf(value, startIndex, startIndex + 1); } [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. - public override int LastIndexOf(object value, int startIndex, int count) + public override int LastIndexOf(object? value, int startIndex, int count) { InternalUpdateRange(); if (_baseSize == 0) @@ -2767,7 +2768,7 @@ namespace System.Collections } } - public override void Sort(int index, int count, IComparer comparer) + public override void Sort(int index, int count, IComparer? comparer) { if (index < 0 || count < 0) throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum); @@ -2779,7 +2780,7 @@ namespace System.Collections InternalUpdateVersion(); } - public override object this[int index] + public override object? this[int index] { get { @@ -2796,11 +2797,11 @@ namespace System.Collections } } - public override object[] ToArray() + public override object?[] ToArray() { InternalUpdateRange(); if (_baseSize == 0) - return Array.Empty(); + return Array.Empty(); object[] array = new object[_baseSize]; Array.Copy(_baseList._items, _baseIndex, array, 0, _baseSize); return array; @@ -2828,7 +2829,7 @@ namespace System.Collections private ArrayList _list; private int _index; private int _version; - private object _currentElement; + private object? _currentElement; private bool _isArrayList; // this object is used to indicate enumeration has not started or has terminated private static object s_dummyObject = new object(); @@ -2881,11 +2882,11 @@ namespace System.Collections } } - public object Current + public object? Current { get { - object temp = _currentElement; + object? temp = _currentElement; if (s_dummyObject == temp) { // check if enumeration has not started or has terminated if (_index == -1) @@ -2927,7 +2928,7 @@ namespace System.Collections } [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)] - public object[] Items + public object?[] Items { get { diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Comparer.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Comparer.cs index 24a6cbf..2b02433 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Comparer.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Comparer.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable /*============================================================ ** ** Purpose: Default IComparer implementation. @@ -35,7 +36,7 @@ namespace System.Collections if (info == null) throw new ArgumentNullException(nameof(info)); - _compareInfo = (CompareInfo)info.GetValue("CompareInfo", typeof(CompareInfo)); + _compareInfo = (CompareInfo)info.GetValue("CompareInfo", typeof(CompareInfo))!; } public void GetObjectData(SerializationInfo info, StreamingContext context) @@ -52,13 +53,13 @@ namespace System.Collections // If a doesn't implement IComparable and b does, -(b.CompareTo(a)) is returned. // Otherwise an exception is thrown. // - public int Compare(object a, object b) + public int Compare(object? a, object? b) { if (a == b) return 0; if (a == null) return -1; if (b == null) return 1; - string sa = a as string; + string? sa = a as string; if (sa != null && b is string sb) return _compareInfo.Compare(sa, sb); diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/CompatibleComparer.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/CompatibleComparer.cs index 5342dcd..f4042e5 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/CompatibleComparer.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/CompatibleComparer.cs @@ -2,28 +2,29 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable #pragma warning disable 618 // obsolete types namespace System.Collections { internal sealed class CompatibleComparer : IEqualityComparer { - private readonly IHashCodeProvider _hcp; - private readonly IComparer _comparer; + private readonly IHashCodeProvider? _hcp; + private readonly IComparer? _comparer; - internal CompatibleComparer(IHashCodeProvider hashCodeProvider, IComparer comparer) + internal CompatibleComparer(IHashCodeProvider? hashCodeProvider, IComparer? comparer) { _hcp = hashCodeProvider; _comparer = comparer; } - internal IHashCodeProvider HashCodeProvider => _hcp; + internal IHashCodeProvider? HashCodeProvider => _hcp; - internal IComparer Comparer => _comparer; + internal IComparer? Comparer => _comparer; - public new bool Equals(object a, object b) => Compare(a, b) == 0; + public new bool Equals(object? a, object? b) => Compare(a, b) == 0; - public int Compare(object a, object b) + public int Compare(object? a, object? b) { if (a == b) return 0; diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.SerializationInfoTable.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.SerializationInfoTable.cs index d91dfd8..5c627af 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.SerializationInfoTable.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.SerializationInfoTable.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable // Used by Hashtable and Dictionary's SeralizationInfo .ctor's to store the SeralizationInfo // object until OnDeserialization is called. @@ -13,7 +14,7 @@ namespace System.Collections { internal static partial class HashHelpers { - private static ConditionalWeakTable s_serializationInfoTable; + private static ConditionalWeakTable? s_serializationInfoTable; public static ConditionalWeakTable SerializationInfoTable { @@ -22,8 +23,8 @@ namespace System.Collections if (s_serializationInfoTable == null) Interlocked.CompareExchange(ref s_serializationInfoTable, new ConditionalWeakTable(), null); - return s_serializationInfoTable; + return s_serializationInfoTable!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34901 } } } -} \ No newline at end of file +} diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs index ba2c75c..9cb957e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/HashHelpers.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. - +#nullable enable using System.Diagnostics; namespace System.Collections diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Hashtable.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Hashtable.cs index 5c56212..ae8f6d4 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Hashtable.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Hashtable.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable /*============================================================ ** ** Class: Hashtable @@ -127,12 +128,12 @@ namespace System.Collections // This cannot be serialized private struct bucket { - public object key; - public object val; + public object? key; + public object? val; public int hash_coll; // Store hash code; sign bit means there was a collision. } - private bucket[] _buckets; + private bucket[] _buckets = null!; // The total number of entries in the hash table. private int _count; @@ -146,13 +147,13 @@ namespace System.Collections private volatile int _version; private volatile bool _isWriterInProgress; - private ICollection _keys; - private ICollection _values; + private ICollection? _keys; + private ICollection? _values; - private IEqualityComparer _keycomparer; + private IEqualityComparer? _keycomparer; [Obsolete("Please use EqualityComparer property.")] - protected IHashCodeProvider hcp + protected IHashCodeProvider? hcp { get { @@ -178,7 +179,7 @@ namespace System.Collections } else if (_keycomparer == null) { - _keycomparer = new CompatibleComparer(value, (IComparer)null); + _keycomparer = new CompatibleComparer(value, (IComparer?)null); } else { @@ -188,7 +189,7 @@ namespace System.Collections } [Obsolete("Please use KeyComparer properties.")] - protected IComparer comparer + protected IComparer? comparer { get { @@ -214,7 +215,7 @@ namespace System.Collections } else if (_keycomparer == null) { - _keycomparer = new CompatibleComparer((IHashCodeProvider)null, value); + _keycomparer = new CompatibleComparer((IHashCodeProvider?)null, value); } else { @@ -224,7 +225,7 @@ namespace System.Collections } - protected IEqualityComparer EqualityComparer + protected IEqualityComparer? EqualityComparer { get { @@ -290,28 +291,28 @@ namespace System.Collections Debug.Assert(_loadsize < hashsize, "Invalid hashtable loadsize!"); } - public Hashtable(int capacity, float loadFactor, IEqualityComparer equalityComparer) : this(capacity, loadFactor) + public Hashtable(int capacity, float loadFactor, IEqualityComparer? equalityComparer) : this(capacity, loadFactor) { _keycomparer = equalityComparer; } [Obsolete("Please use Hashtable(IEqualityComparer) instead.")] - public Hashtable(IHashCodeProvider hcp, IComparer comparer) + public Hashtable(IHashCodeProvider? hcp, IComparer? comparer) : this(0, 1.0f, hcp, comparer) { } - public Hashtable(IEqualityComparer equalityComparer) : this(0, 1.0f, equalityComparer) + public Hashtable(IEqualityComparer? equalityComparer) : this(0, 1.0f, equalityComparer) { } [Obsolete("Please use Hashtable(int, IEqualityComparer) instead.")] - public Hashtable(int capacity, IHashCodeProvider hcp, IComparer comparer) + public Hashtable(int capacity, IHashCodeProvider? hcp, IComparer? comparer) : this(capacity, 1.0f, hcp, comparer) { } - public Hashtable(int capacity, IEqualityComparer equalityComparer) + public Hashtable(int capacity, IEqualityComparer? equalityComparer) : this(capacity, 1.0f, equalityComparer) { } @@ -327,23 +328,23 @@ namespace System.Collections // dictionary. The hashtable is created with the given load factor. // public Hashtable(IDictionary d, float loadFactor) - : this(d, loadFactor, (IEqualityComparer)null) + : this(d, loadFactor, (IEqualityComparer?)null) { } [Obsolete("Please use Hashtable(IDictionary, IEqualityComparer) instead.")] - public Hashtable(IDictionary d, IHashCodeProvider hcp, IComparer comparer) + public Hashtable(IDictionary d, IHashCodeProvider? hcp, IComparer? comparer) : this(d, 1.0f, hcp, comparer) { } - public Hashtable(IDictionary d, IEqualityComparer equalityComparer) + public Hashtable(IDictionary d, IEqualityComparer? equalityComparer) : this(d, 1.0f, equalityComparer) { } [Obsolete("Please use Hashtable(int, float, IEqualityComparer) instead.")] - public Hashtable(int capacity, float loadFactor, IHashCodeProvider hcp, IComparer comparer) + public Hashtable(int capacity, float loadFactor, IHashCodeProvider? hcp, IComparer? comparer) : this(capacity, loadFactor) { if (hcp != null || comparer != null) @@ -353,7 +354,7 @@ namespace System.Collections } [Obsolete("Please use Hashtable(IDictionary, float, IEqualityComparer) instead.")] - public Hashtable(IDictionary d, float loadFactor, IHashCodeProvider hcp, IComparer comparer) + public Hashtable(IDictionary d, float loadFactor, IHashCodeProvider? hcp, IComparer? comparer) : this((d != null ? d.Count : 0), loadFactor, hcp, comparer) { if (d == null) @@ -364,7 +365,7 @@ namespace System.Collections Add(e.Key, e.Value); } - public Hashtable(IDictionary d, float loadFactor, IEqualityComparer equalityComparer) + public Hashtable(IDictionary d, float loadFactor, IEqualityComparer? equalityComparer) : this((d != null ? d.Count : 0), loadFactor, equalityComparer) { if (d == null) @@ -422,7 +423,7 @@ namespace System.Collections // ArgumentException is thrown if the key is null or if the key is already // present in the hashtable. // - public virtual void Add(object key, object value) + public virtual void Add(object key, object? value) { Insert(key, value, true); } @@ -464,7 +465,7 @@ namespace System.Collections while (bucket > 0) { bucket--; - object keyv = lbuckets[bucket].key; + object? keyv = lbuckets[bucket].key; if ((keyv != null) && (keyv != lbuckets)) { ht[keyv] = lbuckets[bucket].val; @@ -522,7 +523,7 @@ namespace System.Collections // search and is thus be substantially slower than the ContainsKey // method. // - public virtual bool ContainsValue(object value) + public virtual bool ContainsValue(object? value) { if (value == null) { @@ -536,7 +537,7 @@ namespace System.Collections { for (int i = _buckets.Length; --i >= 0;) { - object val = _buckets[i].val; + object? val = _buckets[i].val; if (val != null && val.Equals(value)) return true; } @@ -555,7 +556,7 @@ namespace System.Collections bucket[] lbuckets = _buckets; for (int i = lbuckets.Length; --i >= 0;) { - object keyv = lbuckets[i].key; + object? keyv = lbuckets[i].key; if ((keyv != null) && (keyv != _buckets)) { array.SetValue(keyv, arrayIndex++); @@ -574,7 +575,7 @@ namespace System.Collections bucket[] lbuckets = _buckets; for (int i = lbuckets.Length; --i >= 0;) { - object keyv = lbuckets[i].key; + object? keyv = lbuckets[i].key; if ((keyv != null) && (keyv != _buckets)) { DictionaryEntry entry = new DictionaryEntry(keyv, lbuckets[i].val); @@ -610,7 +611,7 @@ namespace System.Collections bucket[] lbuckets = _buckets; for (int i = lbuckets.Length; --i >= 0;) { - object keyv = lbuckets[i].key; + object? keyv = lbuckets[i].key; if ((keyv != null) && (keyv != _buckets)) { array[index++] = new KeyValuePairs(keyv, lbuckets[i].val); @@ -632,7 +633,7 @@ namespace System.Collections bucket[] lbuckets = _buckets; for (int i = lbuckets.Length; --i >= 0;) { - object keyv = lbuckets[i].key; + object? keyv = lbuckets[i].key; if ((keyv != null) && (keyv != _buckets)) { array.SetValue(lbuckets[i].val, arrayIndex++); @@ -643,7 +644,7 @@ namespace System.Collections // Returns the value associated with the given key. If an entry with the // given key is not found, the returned value is null. // - public virtual object this[object key] + public virtual object? this[object key] { get { @@ -826,7 +827,7 @@ namespace System.Collections // instance in the constructor, this method will call comparer.Compare(item, key). // Otherwise, it will call item.Equals(key). // - protected virtual bool KeyEquals(object item, object key) + protected virtual bool KeyEquals(object? item, object key) { Debug.Assert(key != null, "key can't be null here!"); if (object.ReferenceEquals(_buckets, item)) @@ -884,7 +885,7 @@ namespace System.Collections // Inserts an entry into this hashtable. This method is called from the Set // and Add methods. If the add parameter is true and the given key already // exists in the hashtable, an exception is thrown. - private void Insert(object key, object nvalue, bool add) + private void Insert(object key, object? nvalue, bool add) { if (key == null) { @@ -997,7 +998,7 @@ namespace System.Collections throw new InvalidOperationException(SR.InvalidOperation_HashInsertFailed); } - private void putEntry(bucket[] newBuckets, object key, object nvalue, int hashcode) + private void putEntry(bucket[] newBuckets, object key, object? nvalue, int hashcode) { Debug.Assert(hashcode >= 0, "hashcode >= 0"); // make sure collision bit (sign bit) wasn't set. @@ -1114,7 +1115,7 @@ namespace System.Collections // Also, if the Hashtable is using randomized hashing, serialize the old // view of the _keycomparer so perevious frameworks don't see the new types #pragma warning disable 618 - IEqualityComparer keyComparerForSerilization = _keycomparer; + IEqualityComparer? keyComparerForSerilization = _keycomparer; if (keyComparerForSerilization == null) { @@ -1123,7 +1124,7 @@ namespace System.Collections } else if (keyComparerForSerilization is CompatibleComparer) { - CompatibleComparer c = keyComparerForSerilization as CompatibleComparer; + CompatibleComparer c = (keyComparerForSerilization as CompatibleComparer)!; info.AddValue(ComparerName, c.Comparer, typeof(IComparer)); info.AddValue(HashCodeProviderName, c.HashCodeProvider, typeof(IHashCodeProvider)); } @@ -1170,14 +1171,14 @@ namespace System.Collections } int hashsize = 0; - IComparer c = null; + IComparer? c = null; #pragma warning disable 618 - IHashCodeProvider hcp = null; + IHashCodeProvider? hcp = null; #pragma warning restore 618 - object[] serKeys = null; - object[] serValues = null; + object[]? serKeys = null; + object?[]? serValues = null; SerializationInfoEnumerator enumerator = siInfo.GetEnumerator(); @@ -1192,21 +1193,21 @@ namespace System.Collections hashsize = siInfo.GetInt32(HashSizeName); break; case KeyComparerName: - _keycomparer = (IEqualityComparer)siInfo.GetValue(KeyComparerName, typeof(IEqualityComparer)); + _keycomparer = (IEqualityComparer?)siInfo.GetValue(KeyComparerName, typeof(IEqualityComparer)); break; case ComparerName: - c = (IComparer)siInfo.GetValue(ComparerName, typeof(IComparer)); + c = (IComparer?)siInfo.GetValue(ComparerName, typeof(IComparer)); break; case HashCodeProviderName: #pragma warning disable 618 - hcp = (IHashCodeProvider)siInfo.GetValue(HashCodeProviderName, typeof(IHashCodeProvider)); + hcp = (IHashCodeProvider?)siInfo.GetValue(HashCodeProviderName, typeof(IHashCodeProvider)); #pragma warning restore 618 break; case KeysName: - serKeys = (object[])siInfo.GetValue(KeysName, typeof(object[])); + serKeys = (object[]?)siInfo.GetValue(KeysName, typeof(object[])); break; case ValuesName: - serValues = (object[])siInfo.GetValue(ValuesName, typeof(object[])); + serValues = (object?[]?)siInfo.GetValue(ValuesName, typeof(object[])); break; } } @@ -1377,7 +1378,7 @@ namespace System.Collections get { return true; } } - public override object this[object key] + public override object? this[object key] { get { @@ -1397,7 +1398,7 @@ namespace System.Collections get { return _table.SyncRoot; } } - public override void Add(object key, object value) + public override void Add(object key, object? value) { lock (_table.SyncRoot) { @@ -1427,7 +1428,7 @@ namespace System.Collections return _table.ContainsKey(key); } - public override bool ContainsValue(object key) + public override bool ContainsValue(object? key) { lock (_table.SyncRoot) { @@ -1515,8 +1516,8 @@ namespace System.Collections private int _version; private bool _current; private int _getObjectRetType; // What should GetObject return? - private object _currentKey; - private object _currentValue; + private object? _currentKey; + private object? _currentValue; internal const int Keys = 1; internal const int Values = 2; @@ -1539,7 +1540,7 @@ namespace System.Collections { if (_current == false) throw new InvalidOperationException(SR.InvalidOperation_EnumNotStarted); - return _currentKey; + return _currentKey!; } } @@ -1550,7 +1551,7 @@ namespace System.Collections while (_bucket > 0) { _bucket--; - object keyv = _hashtable._buckets[_bucket].key; + object? keyv = _hashtable._buckets[_bucket].key; if ((keyv != null) && (keyv != _hashtable._buckets)) { _currentKey = keyv; @@ -1569,12 +1570,12 @@ namespace System.Collections { if (_current == false) throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen); - return new DictionaryEntry(_currentKey, _currentValue); + return new DictionaryEntry(_currentKey!, _currentValue); } } - public virtual object Current + public virtual object? Current { get { @@ -1586,11 +1587,11 @@ namespace System.Collections else if (_getObjectRetType == Values) return _currentValue; else - return new DictionaryEntry(_currentKey, _currentValue); + return new DictionaryEntry(_currentKey!, _currentValue); } } - public virtual object Value + public virtual object? Value { get { diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/ICollection.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/ICollection.cs index 65e37c7..95ebb7e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/ICollection.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/ICollection.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System; namespace System.Collections diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/IHashCodeProvider.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/IHashCodeProvider.cs index 7d6c63f..260aab2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/IHashCodeProvider.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/IHashCodeProvider.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable namespace System.Collections { /// diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/IList.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/IList.cs index 25d3b19..0857885 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/IList.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/IList.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System; namespace System.Collections @@ -12,7 +13,7 @@ namespace System.Collections public interface IList : ICollection { // The Item property provides methods to read and edit entries in the List. - object this[int index] + object? this[int index] { get; set; @@ -22,10 +23,10 @@ namespace System.Collections // implementation-dependent, so while ArrayList may always insert // in the last available location, a SortedList most likely would not. // The return value is the position the new element was inserted in. - int Add(object value); + int Add(object? value); // Returns whether the list contains a particular item. - bool Contains(object value); + bool Contains(object? value); // Removes all items from the list. void Clear(); @@ -42,16 +43,16 @@ namespace System.Collections // Returns the index of a particular item, if it is in the list. // Returns -1 if the item isn't in the list. - int IndexOf(object value); + int IndexOf(object? value); // Inserts value into the list at position index. // index must be non-negative and less than or equal to the // number of elements in the list. If index equals the number // of items in the list, then value is appended to the end. - void Insert(int index, object value); + void Insert(int index, object? value); // Removes an item from the list. - void Remove(object value); + void Remove(object? value); // Removes the item at position index. void RemoveAt(int index); diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/IStructuralComparable.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/IStructuralComparable.cs index 9041e0d..b012618 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/IStructuralComparable.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/IStructuralComparable.cs @@ -2,12 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System; namespace System.Collections { public interface IStructuralComparable { - int CompareTo(object other, IComparer comparer); + int CompareTo(object? other, IComparer comparer); } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/KeyValuePairs.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/KeyValuePairs.cs index 9ec6365..2604331 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/KeyValuePairs.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/KeyValuePairs.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable /*============================================================ ** ** Class: KeyValuePairs @@ -22,9 +23,9 @@ namespace System.Collections private readonly object _key; [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private readonly object _value; + private readonly object? _value; - public KeyValuePairs(object key, object value) + public KeyValuePairs(object key, object? value) { _value = value; _key = key; diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/ListDictionaryInternal.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/ListDictionaryInternal.cs index 1bc61db..ce9caed 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/ListDictionaryInternal.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/ListDictionaryInternal.cs @@ -12,7 +12,7 @@ ** ===========================================================*/ - +#nullable enable namespace System.Collections { /// This is a simple implementation of IDictionary using a singly linked list. This @@ -23,7 +23,7 @@ namespace System.Collections // Needs to be public to support binary serialization compatibility public class ListDictionaryInternal : IDictionary { - private DictionaryNode head; // Do not rename (binary serialization) + private DictionaryNode? head; // Do not rename (binary serialization) private int version; // Do not rename (binary serialization) private int count; // Do not rename (binary serialization) @@ -31,7 +31,7 @@ namespace System.Collections { } - public object this[object key] + public object? this[object key] { get { @@ -39,7 +39,7 @@ namespace System.Collections { throw new ArgumentNullException(nameof(key), SR.ArgumentNull_Key); } - DictionaryNode node = head; + DictionaryNode? node = head; while (node != null) { @@ -60,8 +60,8 @@ namespace System.Collections version++; - DictionaryNode last = null; - DictionaryNode node; + DictionaryNode? last = null; + DictionaryNode? node; for (node = head; node != null; node = node.next) { if (node.key.Equals(key)) @@ -142,7 +142,7 @@ namespace System.Collections } } - public void Add(object key, object value) + public void Add(object key, object? value) { if (key == null) { @@ -151,8 +151,8 @@ namespace System.Collections version++; - DictionaryNode last = null; - DictionaryNode node; + DictionaryNode? last = null; + DictionaryNode? node; for (node = head; node != null; node = node.next) { if (node.key.Equals(key)) @@ -195,7 +195,7 @@ namespace System.Collections { throw new ArgumentNullException(nameof(key), SR.ArgumentNull_Key); } - for (DictionaryNode node = head; node != null; node = node.next) + for (DictionaryNode? node = head; node != null; node = node.next) { if (node.key.Equals(key)) { @@ -219,7 +219,7 @@ namespace System.Collections if (array.Length - index < this.Count) throw new ArgumentException(SR.ArgumentOutOfRange_Index, nameof(index)); - for (DictionaryNode node = head; node != null; node = node.next) + for (DictionaryNode? node = head; node != null; node = node.next) { array.SetValue(new DictionaryEntry(node.key, node.value), index); index++; @@ -243,8 +243,8 @@ namespace System.Collections throw new ArgumentNullException(nameof(key), SR.ArgumentNull_Key); } version++; - DictionaryNode last = null; - DictionaryNode node; + DictionaryNode? last = null; + DictionaryNode? node; for (node = head; node != null; node = node.next) { if (node.key.Equals(key)) @@ -263,7 +263,7 @@ namespace System.Collections } else { - last.next = node.next; + last!.next = node.next; } count--; } @@ -271,7 +271,7 @@ namespace System.Collections private class NodeEnumerator : IDictionaryEnumerator { private ListDictionaryInternal list; - private DictionaryNode current; + private DictionaryNode? current; private int version; private bool start; @@ -284,7 +284,9 @@ namespace System.Collections current = null; } +#pragma warning disable CS8612 // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/30958 public object Current +#pragma warning restore CS8612 { get { @@ -316,7 +318,7 @@ namespace System.Collections } } - public object Value + public object? Value { get { @@ -382,7 +384,7 @@ namespace System.Collections throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum); if (array.Length - index < list.Count) throw new ArgumentException(SR.ArgumentOutOfRange_Index, nameof(index)); - for (DictionaryNode node = list.head; node != null; node = node.next) + for (DictionaryNode? node = list.head; node != null; node = node.next) { array.SetValue(isKeys ? node.key : node.value, index); index++; @@ -394,7 +396,7 @@ namespace System.Collections get { int count = 0; - for (DictionaryNode node = list.head; node != null; node = node.next) + for (DictionaryNode? node = list.head; node != null; node = node.next) { count++; } @@ -427,7 +429,7 @@ namespace System.Collections private class NodeKeyValueEnumerator : IEnumerator { private ListDictionaryInternal list; - private DictionaryNode current; + private DictionaryNode? current; private int version; private bool isKeys; private bool start; @@ -441,7 +443,7 @@ namespace System.Collections current = null; } - public object Current + public object? Current { get { @@ -489,9 +491,9 @@ namespace System.Collections [Serializable] private class DictionaryNode { - public object key; - public object value; - public DictionaryNode next; + public object key = null!; + public object? value; + public DictionaryNode? next; } } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyCollection.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyCollection.cs index 10795ac..9ab299b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyCollection.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyCollection.cs @@ -211,7 +211,7 @@ namespace System.Collections.ObjectModel } } - int IList.Add(object value) + int IList.Add(object? value) { ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection); return -1; @@ -247,12 +247,12 @@ namespace System.Collections.ObjectModel return -1; } - void IList.Insert(int index, object value) + void IList.Insert(int index, object? value) { ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection); } - void IList.Remove(object value) + void IList.Remove(object? value) { ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection); } diff --git a/src/libraries/System.Private.CoreLib/src/System/CurrentSystemTimeZone.cs b/src/libraries/System.Private.CoreLib/src/System/CurrentSystemTimeZone.cs index 5b5fdd6..f88ea79 100644 --- a/src/libraries/System.Private.CoreLib/src/System/CurrentSystemTimeZone.cs +++ b/src/libraries/System.Private.CoreLib/src/System/CurrentSystemTimeZone.cs @@ -207,7 +207,7 @@ namespace System } } - return (DaylightTime)m_CachedDaylightChanges[objYear]; + return (DaylightTime)m_CachedDaylightChanges[objYear]!; } // The per-year information is cached in this instance value. As a result it can diff --git a/src/libraries/System.Private.CoreLib/src/System/Security/SecurityElement.cs b/src/libraries/System.Private.CoreLib/src/System/Security/SecurityElement.cs index 197eaa0..bdefc7d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Security/SecurityElement.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Security/SecurityElement.cs @@ -124,7 +124,7 @@ namespace System.Security for (int i = 0; i < iMax; i += 2) { - hashtable.Add(_attributes[i], _attributes[i + 1]); + hashtable.Add(_attributes[i]!, _attributes[i + 1]); } return hashtable; @@ -231,7 +231,7 @@ namespace System.Security for (int i = 0; i < iMax; i += 2) { - string strAttrName = (string)_attributes[i]; + string? strAttrName = (string?)_attributes[i]; if (string.Equals(strAttrName, name)) throw new ArgumentException(SR.Argument_AttributeNamesMustBeUnique); @@ -301,8 +301,8 @@ namespace System.Security for (int i = 0; i < iMax; i++) { - string lhs = (string)_attributes[i]; - string rhs = (string)other._attributes[i]; + string? lhs = (string?)_attributes[i]; + string? rhs = (string?)other._attributes[i]; if (!string.Equals(lhs, rhs)) return false; @@ -524,8 +524,8 @@ namespace System.Security for (int i = 0; i < iMax; i += 2) { - string strAttrName = (string)_attributes[i]; - string strAttrValue = (string)_attributes[i + 1]; + string? strAttrName = (string?)_attributes[i]; + string? strAttrValue = (string?)_attributes[i + 1]; write(obj, strAttrName); write(obj, "=\""); @@ -562,7 +562,7 @@ namespace System.Security for (int i = 0; i < _children.Count; ++i) { - ((SecurityElement)_children[i]).ToString(string.Empty, obj, write); + ((SecurityElement)_children[i]!).ToString(string.Empty, obj, write); } } @@ -591,11 +591,11 @@ namespace System.Security for (int i = 0; i < iMax; i += 2) { - string strAttrName = (string)_attributes[i]; + string? strAttrName = (string?)_attributes[i]; if (string.Equals(strAttrName, name)) { - string strAttrValue = (string)_attributes[i + 1]; + string? strAttrValue = (string?)_attributes[i + 1]; return Unescape(strAttrValue); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/EncodingTable.cs b/src/libraries/System.Private.CoreLib/src/System/Text/EncodingTable.cs index 14c9bbe..7f4d746 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/EncodingTable.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/EncodingTable.cs @@ -34,7 +34,7 @@ namespace System.Text if (name == null) throw new ArgumentNullException(nameof(name)); - object codePageObj; + object? codePageObj; codePageObj = s_nameToCodePage[name]; if (codePageObj != null) diff --git a/src/libraries/System.Private.CoreLib/src/System/Tuple.cs b/src/libraries/System.Private.CoreLib/src/System/Tuple.cs index bcfd4ce..d3f0a91 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Tuple.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Tuple.cs @@ -138,7 +138,7 @@ namespace System return ((IStructuralComparable)this).CompareTo(obj, Comparer.Default); } - int IStructuralComparable.CompareTo(object other, IComparer comparer) + int IStructuralComparable.CompareTo(object? other, IComparer comparer) { if (other == null) return 1; @@ -237,7 +237,7 @@ namespace System return ((IStructuralComparable)this).CompareTo(obj, Comparer.Default); } - int IStructuralComparable.CompareTo(object other, IComparer comparer) + int IStructuralComparable.CompareTo(object? other, IComparer comparer) { if (other == null) return 1; @@ -351,7 +351,7 @@ namespace System return ((IStructuralComparable)this).CompareTo(obj, Comparer.Default); } - int IStructuralComparable.CompareTo(object other, IComparer comparer) + int IStructuralComparable.CompareTo(object? other, IComparer comparer) { if (other == null) return 1; @@ -476,7 +476,7 @@ namespace System return ((IStructuralComparable)this).CompareTo(obj, Comparer.Default); } - int IStructuralComparable.CompareTo(object other, IComparer comparer) + int IStructuralComparable.CompareTo(object? other, IComparer comparer) { if (other == null) return 1; @@ -612,7 +612,7 @@ namespace System return ((IStructuralComparable)this).CompareTo(obj, Comparer.Default); } - int IStructuralComparable.CompareTo(object other, IComparer comparer) + int IStructuralComparable.CompareTo(object? other, IComparer comparer) { if (other == null) return 1; @@ -759,7 +759,7 @@ namespace System return ((IStructuralComparable)this).CompareTo(obj, Comparer.Default); } - int IStructuralComparable.CompareTo(object other, IComparer comparer) + int IStructuralComparable.CompareTo(object? other, IComparer comparer) { if (other == null) return 1; @@ -917,7 +917,7 @@ namespace System return ((IStructuralComparable)this).CompareTo(obj, Comparer.Default); } - int IStructuralComparable.CompareTo(object other, IComparer comparer) + int IStructuralComparable.CompareTo(object? other, IComparer comparer) { if (other == null) return 1; @@ -1091,7 +1091,7 @@ namespace System return ((IStructuralComparable)this).CompareTo(obj, Comparer.Default); } - int IStructuralComparable.CompareTo(object other, IComparer comparer) + int IStructuralComparable.CompareTo(object? other, IComparer comparer) { if (other == null) return 1; diff --git a/src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs b/src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs index b227535..663c1ae 100644 --- a/src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs +++ b/src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs @@ -82,7 +82,7 @@ namespace System return 0; } - int IStructuralComparable.CompareTo(object other, IComparer comparer) + int IStructuralComparable.CompareTo(object? other, IComparer comparer) { if (other == null) return 1; @@ -387,7 +387,7 @@ namespace System return Comparer.Default.Compare(Item1, other.Item1); } - int IStructuralComparable.CompareTo(object other, IComparer comparer) + int IStructuralComparable.CompareTo(object? other, IComparer comparer) { if (other == null) return 1; @@ -582,7 +582,7 @@ namespace System return Comparer.Default.Compare(Item2, other.Item2); } - int IStructuralComparable.CompareTo(object other, IComparer comparer) + int IStructuralComparable.CompareTo(object? other, IComparer comparer) { if (other == null) return 1; @@ -785,7 +785,7 @@ namespace System return Comparer.Default.Compare(Item3, other.Item3); } - int IStructuralComparable.CompareTo(object other, IComparer comparer) + int IStructuralComparable.CompareTo(object? other, IComparer comparer) { if (other == null) return 1; @@ -1005,7 +1005,7 @@ namespace System return Comparer.Default.Compare(Item4, other.Item4); } - int IStructuralComparable.CompareTo(object other, IComparer comparer) + int IStructuralComparable.CompareTo(object? other, IComparer comparer) { if (other == null) return 1; @@ -1244,7 +1244,7 @@ namespace System return Comparer.Default.Compare(Item5, other.Item5); } - int IStructuralComparable.CompareTo(object other, IComparer comparer) + int IStructuralComparable.CompareTo(object? other, IComparer comparer) { if (other == null) return 1; @@ -1502,7 +1502,7 @@ namespace System return Comparer.Default.Compare(Item6, other.Item6); } - int IStructuralComparable.CompareTo(object other, IComparer comparer) + int IStructuralComparable.CompareTo(object? other, IComparer comparer) { if (other == null) return 1; @@ -1779,7 +1779,7 @@ namespace System return Comparer.Default.Compare(Item7, other.Item7); } - int IStructuralComparable.CompareTo(object other, IComparer comparer) + int IStructuralComparable.CompareTo(object? other, IComparer comparer) { if (other == null) return 1; @@ -2081,7 +2081,7 @@ namespace System return Comparer.Default.Compare(Rest, other.Rest); } - int IStructuralComparable.CompareTo(object other, IComparer comparer) + int IStructuralComparable.CompareTo(object? other, IComparer comparer) { if (other == null) return 1; -- 2.7.4