Annotate System.Collections.Immutable for nullable (#367)
authorbuyaa-n <bunamnan@microsoft.com>
Mon, 16 Dec 2019 21:09:45 +0000 (13:09 -0800)
committerGitHub <noreply@github.com>
Mon, 16 Dec 2019 21:09:45 +0000 (13:09 -0800)
* Annotate System.Collections.Immutable for nullable

54 files changed:
src/libraries/System.Collections.Immutable/ref/System.Collections.Immutable.cs
src/libraries/System.Collections.Immutable/ref/System.Collections.Immutable.csproj
src/libraries/System.Collections.Immutable/src/System.Collections.Immutable.csproj
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/AllocFreeConcurrentStack.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/DictionaryEnumerator.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/DisposableEnumeratorAdapter_2.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/IBinaryTree.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/IImmutableArray.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/IImmutableList.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/IImmutableListQueries.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableArray.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableArray_1.Builder.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableArray_1.Enumerator.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableArray_1.Minimal.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableArray_1.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary_2.Builder.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary_2.Enumerator.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary_2.HashBucket.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary_2.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableEnumerableDebuggerProxy.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableExtensions.Minimal.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableExtensions.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.Builder.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.Enumerator.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.HashBucket.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableInterlocked.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableList.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableList_1.Builder.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableList_1.Enumerator.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableList_1.Node.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableList_1.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableQueue_1.Enumerator.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableQueue_1.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedDictionary.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedDictionary_2.Builder.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedDictionary_2.Enumerator.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedDictionary_2.Node.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedDictionary_2.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedSet.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedSet_1.Builder.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedSet_1.Enumerator.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedSet_1.Node.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedSet_1.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableStack_1.Enumerator.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableStack_1.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/KeysOrValuesCollectionAccessor.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/SecureObjectPool.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/SortedInt32KeyNode.Enumerator.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/SortedInt32KeyNode.cs
src/libraries/System.Collections.Immutable/src/System/Linq/ImmutableArrayExtensions.cs
src/libraries/System.Collections.Immutable/src/Validation/Requires.cs

index 6805291..0772ea7 100644 (file)
@@ -24,16 +24,16 @@ namespace System.Collections.Immutable
         System.Collections.Immutable.IImmutableList<T> Add(T value);
         System.Collections.Immutable.IImmutableList<T> AddRange(System.Collections.Generic.IEnumerable<T> items);
         System.Collections.Immutable.IImmutableList<T> Clear();
-        int IndexOf(T item, int index, int count, System.Collections.Generic.IEqualityComparer<T> equalityComparer);
+        int IndexOf(T item, int index, int count, System.Collections.Generic.IEqualityComparer<T>? equalityComparer);
         System.Collections.Immutable.IImmutableList<T> Insert(int index, T element);
         System.Collections.Immutable.IImmutableList<T> InsertRange(int index, System.Collections.Generic.IEnumerable<T> items);
-        int LastIndexOf(T item, int index, int count, System.Collections.Generic.IEqualityComparer<T> equalityComparer);
-        System.Collections.Immutable.IImmutableList<T> Remove(T value, System.Collections.Generic.IEqualityComparer<T> equalityComparer);
+        int LastIndexOf(T item, int index, int count, System.Collections.Generic.IEqualityComparer<T>? equalityComparer);
+        System.Collections.Immutable.IImmutableList<T> Remove(T value, System.Collections.Generic.IEqualityComparer<T>? equalityComparer);
         System.Collections.Immutable.IImmutableList<T> RemoveAll(System.Predicate<T> match);
         System.Collections.Immutable.IImmutableList<T> RemoveAt(int index);
-        System.Collections.Immutable.IImmutableList<T> RemoveRange(System.Collections.Generic.IEnumerable<T> items, System.Collections.Generic.IEqualityComparer<T> equalityComparer);
+        System.Collections.Immutable.IImmutableList<T> RemoveRange(System.Collections.Generic.IEnumerable<T> items, System.Collections.Generic.IEqualityComparer<T>? equalityComparer);
         System.Collections.Immutable.IImmutableList<T> RemoveRange(int index, int count);
-        System.Collections.Immutable.IImmutableList<T> Replace(T oldValue, T newValue, System.Collections.Generic.IEqualityComparer<T> equalityComparer);
+        System.Collections.Immutable.IImmutableList<T> Replace(T oldValue, T newValue, System.Collections.Generic.IEqualityComparer<T>? equalityComparer);
         System.Collections.Immutable.IImmutableList<T> SetItem(int index, T value);
     }
     public partial interface IImmutableQueue<T> : System.Collections.Generic.IEnumerable<T>, System.Collections.IEnumerable
@@ -73,9 +73,9 @@ namespace System.Collections.Immutable
     public static partial class ImmutableArray
     {
         public static int BinarySearch<T>(this System.Collections.Immutable.ImmutableArray<T> array, int index, int length, T value) { throw null; }
-        public static int BinarySearch<T>(this System.Collections.Immutable.ImmutableArray<T> array, int index, int length, T value, System.Collections.Generic.IComparer<T> comparer) { throw null; }
+        public static int BinarySearch<T>(this System.Collections.Immutable.ImmutableArray<T> array, int index, int length, T value, System.Collections.Generic.IComparer<T>? comparer) { throw null; }
         public static int BinarySearch<T>(this System.Collections.Immutable.ImmutableArray<T> array, T value) { throw null; }
-        public static int BinarySearch<T>(this System.Collections.Immutable.ImmutableArray<T> array, T value, System.Collections.Generic.IComparer<T> comparer) { throw null; }
+        public static int BinarySearch<T>(this System.Collections.Immutable.ImmutableArray<T> array, T value, System.Collections.Generic.IComparer<T>? comparer) { throw null; }
         public static System.Collections.Immutable.ImmutableArray<T>.Builder CreateBuilder<T>() { throw null; }
         public static System.Collections.Immutable.ImmutableArray<T>.Builder CreateBuilder<T>(int initialCapacity) { throw null; }
         public static System.Collections.Immutable.ImmutableArray<T> CreateRange<T>(System.Collections.Generic.IEnumerable<T> items) { throw null; }
@@ -115,7 +115,7 @@ namespace System.Collections.Immutable
         object System.Collections.ICollection.SyncRoot { get { throw null; } }
         bool System.Collections.IList.IsFixedSize { get { throw null; } }
         bool System.Collections.IList.IsReadOnly { get { throw null; } }
-        object System.Collections.IList.this[int index] { get { throw null; } set { } }
+        object? System.Collections.IList.this[int index] { get { throw null; } set { } }
         public System.Collections.Immutable.ImmutableArray<T> Add(T item) { throw null; }
         public System.Collections.Immutable.ImmutableArray<T> AddRange(System.Collections.Generic.IEnumerable<T> items) { throw null; }
         public System.Collections.Immutable.ImmutableArray<T> AddRange(System.Collections.Immutable.ImmutableArray<T> items) { throw null; }
@@ -132,14 +132,14 @@ namespace System.Collections.Immutable
         public void CopyTo(T[] destination) { }
         public void CopyTo(T[] destination, int destinationIndex) { }
         public bool Equals(System.Collections.Immutable.ImmutableArray<T> other) { throw null; }
-        public override bool Equals(object obj) { throw null; }
+        public override bool Equals(object? obj) { throw null; }
         public System.Collections.Immutable.ImmutableArray<T>.Enumerator GetEnumerator() { throw null; }
         public override int GetHashCode() { throw null; }
         public int IndexOf(T item) { throw null; }
         public int IndexOf(T item, int startIndex) { throw null; }
-        public int IndexOf(T item, int startIndex, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+        public int IndexOf(T item, int startIndex, System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
         public int IndexOf(T item, int startIndex, int count) { throw null; }
-        public int IndexOf(T item, int startIndex, int count, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+        public int IndexOf(T item, int startIndex, int count, System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
         public System.Collections.Immutable.ImmutableArray<T> Insert(int index, T item) { throw null; }
         public System.Collections.Immutable.ImmutableArray<T> InsertRange(int index, System.Collections.Generic.IEnumerable<T> items) { throw null; }
         public System.Collections.Immutable.ImmutableArray<T> InsertRange(int index, System.Collections.Immutable.ImmutableArray<T> items) { throw null; }
@@ -149,28 +149,28 @@ namespace System.Collections.Immutable
         public int LastIndexOf(T item) { throw null; }
         public int LastIndexOf(T item, int startIndex) { throw null; }
         public int LastIndexOf(T item, int startIndex, int count) { throw null; }
-        public int LastIndexOf(T item, int startIndex, int count, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+        public int LastIndexOf(T item, int startIndex, int count, System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
         public System.Collections.Generic.IEnumerable<TResult> OfType<TResult>() { throw null; }
         public static bool operator ==(System.Collections.Immutable.ImmutableArray<T> left, System.Collections.Immutable.ImmutableArray<T> right) { throw null; }
         public static bool operator ==(System.Collections.Immutable.ImmutableArray<T>? left, System.Collections.Immutable.ImmutableArray<T>? right) { throw null; }
         public static bool operator !=(System.Collections.Immutable.ImmutableArray<T> left, System.Collections.Immutable.ImmutableArray<T> right) { throw null; }
         public static bool operator !=(System.Collections.Immutable.ImmutableArray<T>? left, System.Collections.Immutable.ImmutableArray<T>? right) { throw null; }
         public System.Collections.Immutable.ImmutableArray<T> Remove(T item) { throw null; }
-        public System.Collections.Immutable.ImmutableArray<T> Remove(T item, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+        public System.Collections.Immutable.ImmutableArray<T> Remove(T item, System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
         public System.Collections.Immutable.ImmutableArray<T> RemoveAll(System.Predicate<T> match) { throw null; }
         public System.Collections.Immutable.ImmutableArray<T> RemoveAt(int index) { throw null; }
         public System.Collections.Immutable.ImmutableArray<T> RemoveRange(System.Collections.Generic.IEnumerable<T> items) { throw null; }
-        public System.Collections.Immutable.ImmutableArray<T> RemoveRange(System.Collections.Generic.IEnumerable<T> items, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+        public System.Collections.Immutable.ImmutableArray<T> RemoveRange(System.Collections.Generic.IEnumerable<T> items, System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
         public System.Collections.Immutable.ImmutableArray<T> RemoveRange(System.Collections.Immutable.ImmutableArray<T> items) { throw null; }
-        public System.Collections.Immutable.ImmutableArray<T> RemoveRange(System.Collections.Immutable.ImmutableArray<T> items, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+        public System.Collections.Immutable.ImmutableArray<T> RemoveRange(System.Collections.Immutable.ImmutableArray<T> items, System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
         public System.Collections.Immutable.ImmutableArray<T> RemoveRange(int index, int length) { throw null; }
         public System.Collections.Immutable.ImmutableArray<T> Replace(T oldValue, T newValue) { throw null; }
-        public System.Collections.Immutable.ImmutableArray<T> Replace(T oldValue, T newValue, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+        public System.Collections.Immutable.ImmutableArray<T> Replace(T oldValue, T newValue, System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
         public System.Collections.Immutable.ImmutableArray<T> SetItem(int index, T item) { throw null; }
         public System.Collections.Immutable.ImmutableArray<T> Sort() { throw null; }
-        public System.Collections.Immutable.ImmutableArray<T> Sort(System.Collections.Generic.IComparer<T> comparer) { throw null; }
+        public System.Collections.Immutable.ImmutableArray<T> Sort(System.Collections.Generic.IComparer<T>? comparer) { throw null; }
         public System.Collections.Immutable.ImmutableArray<T> Sort(System.Comparison<T> comparison) { throw null; }
-        public System.Collections.Immutable.ImmutableArray<T> Sort(int index, int count, System.Collections.Generic.IComparer<T> comparer) { throw null; }
+        public System.Collections.Immutable.ImmutableArray<T> Sort(int index, int count, System.Collections.Generic.IComparer<T>? comparer) { throw null; }
         void System.Collections.Generic.ICollection<T>.Add(T item) { }
         void System.Collections.Generic.ICollection<T>.Clear() { }
         bool System.Collections.Generic.ICollection<T>.Remove(T item) { throw null; }
@@ -179,27 +179,27 @@ namespace System.Collections.Immutable
         void System.Collections.Generic.IList<T>.RemoveAt(int index) { }
         void System.Collections.ICollection.CopyTo(System.Array array, int index) { }
         System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
-        int System.Collections.IList.Add(object value) { throw null; }
+        int System.Collections.IList.Add(object? value) { throw null; }
         void System.Collections.IList.Clear() { }
-        bool System.Collections.IList.Contains(object value) { throw null; }
-        int System.Collections.IList.IndexOf(object value) { throw null; }
-        void System.Collections.IList.Insert(int index, object value) { }
-        void System.Collections.IList.Remove(object value) { }
+        bool System.Collections.IList.Contains(object? value) { throw null; }
+        int System.Collections.IList.IndexOf(object? value) { throw null; }
+        void System.Collections.IList.Insert(int index, object? value) { }
+        void System.Collections.IList.Remove(object? value) { }
         void System.Collections.IList.RemoveAt(int index) { }
         System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.Add(T value) { throw null; }
         System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.AddRange(System.Collections.Generic.IEnumerable<T> items) { throw null; }
         System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.Clear() { throw null; }
         System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.Insert(int index, T element) { throw null; }
         System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.InsertRange(int index, System.Collections.Generic.IEnumerable<T> items) { throw null; }
-        System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.Remove(T value, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+        System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.Remove(T value, System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
         System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.RemoveAll(System.Predicate<T> match) { throw null; }
         System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.RemoveAt(int index) { throw null; }
-        System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.RemoveRange(System.Collections.Generic.IEnumerable<T> items, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+        System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.RemoveRange(System.Collections.Generic.IEnumerable<T> items, System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
         System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.RemoveRange(int index, int count) { throw null; }
-        System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.Replace(T oldValue, T newValue, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+        System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.Replace(T oldValue, T newValue, System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
         System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.SetItem(int index, T value) { throw null; }
-        int System.Collections.IStructuralComparable.CompareTo(object other, System.Collections.IComparer comparer) { throw null; }
-        bool System.Collections.IStructuralEquatable.Equals(object other, System.Collections.IEqualityComparer comparer) { throw null; }
+        int System.Collections.IStructuralComparable.CompareTo(object? other, System.Collections.IComparer comparer) { throw null; }
+        bool System.Collections.IStructuralEquatable.Equals(object? other, System.Collections.IEqualityComparer comparer) { throw null; }
         int System.Collections.IStructuralEquatable.GetHashCode(System.Collections.IEqualityComparer comparer) { throw null; }
         public System.Collections.Immutable.ImmutableArray<T>.Builder ToBuilder() { throw null; }
         public sealed partial class Builder : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IList<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.Generic.IReadOnlyList<T>, System.Collections.IEnumerable
@@ -226,7 +226,7 @@ namespace System.Collections.Immutable
             public int IndexOf(T item) { throw null; }
             public int IndexOf(T item, int startIndex) { throw null; }
             public int IndexOf(T item, int startIndex, int count) { throw null; }
-            public int IndexOf(T item, int startIndex, int count, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+            public int IndexOf(T item, int startIndex, int count, System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
             public void Insert(int index, T item) { }
 #if !NETSTANDARD1_0
             public ref readonly T ItemRef(int index) { throw null; }
@@ -234,15 +234,15 @@ namespace System.Collections.Immutable
             public int LastIndexOf(T item) { throw null; }
             public int LastIndexOf(T item, int startIndex) { throw null; }
             public int LastIndexOf(T item, int startIndex, int count) { throw null; }
-            public int LastIndexOf(T item, int startIndex, int count, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+            public int LastIndexOf(T item, int startIndex, int count, System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
             public System.Collections.Immutable.ImmutableArray<T> MoveToImmutable() { throw null; }
             public bool Remove(T element) { throw null; }
             public void RemoveAt(int index) { }
             public void Reverse() { }
             public void Sort() { }
-            public void Sort(System.Collections.Generic.IComparer<T> comparer) { }
+            public void Sort(System.Collections.Generic.IComparer<T>? comparer) { }
             public void Sort(System.Comparison<T> comparison) { }
-            public void Sort(int index, int count, System.Collections.Generic.IComparer<T> comparer) { }
+            public void Sort(int index, int count, System.Collections.Generic.IComparer<T>? comparer) { }
             System.Collections.Generic.IEnumerator<T> System.Collections.Generic.IEnumerable<T>.GetEnumerator() { throw null; }
             System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
             public T[] ToArray() { throw null; }
@@ -259,29 +259,30 @@ namespace System.Collections.Immutable
     }
     public static partial class ImmutableDictionary
     {
-        public static bool Contains<TKey, TValue>(this System.Collections.Immutable.IImmutableDictionary<TKey, TValue> map, TKey key, TValue value) { throw null; }
-        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue>.Builder CreateBuilder<TKey, TValue>() { throw null; }
-        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue>.Builder CreateBuilder<TKey, TValue>(System.Collections.Generic.IEqualityComparer<TKey> keyComparer) { throw null; }
-        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue>.Builder CreateBuilder<TKey, TValue>(System.Collections.Generic.IEqualityComparer<TKey> keyComparer, System.Collections.Generic.IEqualityComparer<TValue> valueComparer) { throw null; }
-        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> CreateRange<TKey, TValue>(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> items) { throw null; }
-        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> CreateRange<TKey, TValue>(System.Collections.Generic.IEqualityComparer<TKey> keyComparer, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> items) { throw null; }
-        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> CreateRange<TKey, TValue>(System.Collections.Generic.IEqualityComparer<TKey> keyComparer, System.Collections.Generic.IEqualityComparer<TValue> valueComparer, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> items) { throw null; }
-        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> Create<TKey, TValue>() { throw null; }
-        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> Create<TKey, TValue>(System.Collections.Generic.IEqualityComparer<TKey> keyComparer) { throw null; }
-        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> Create<TKey, TValue>(System.Collections.Generic.IEqualityComparer<TKey> keyComparer, System.Collections.Generic.IEqualityComparer<TValue> valueComparer) { throw null; }
-        public static TValue GetValueOrDefault<TKey, TValue>(this System.Collections.Immutable.IImmutableDictionary<TKey, TValue> dictionary, TKey key) { throw null; }
-        public static TValue GetValueOrDefault<TKey, TValue>(this System.Collections.Immutable.IImmutableDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue) { throw null; }
-        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TKey, TValue>(this System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> source) { throw null; }
-        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TKey, TValue>(this System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> source, System.Collections.Generic.IEqualityComparer<TKey> keyComparer) { throw null; }
-        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TKey, TValue>(this System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> source, System.Collections.Generic.IEqualityComparer<TKey> keyComparer, System.Collections.Generic.IEqualityComparer<TValue> valueComparer) { throw null; }
-        public static System.Collections.Immutable.ImmutableDictionary<TKey, TSource> ToImmutableDictionary<TSource, TKey>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TKey> keySelector) { throw null; }
-        public static System.Collections.Immutable.ImmutableDictionary<TKey, TSource> ToImmutableDictionary<TSource, TKey>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TKey> keySelector, System.Collections.Generic.IEqualityComparer<TKey> keyComparer) { throw null; }
-        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TKey, TValue>(this System.Collections.Immutable.ImmutableDictionary<TKey, TValue>.Builder builder) { throw null; }
-        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TSource, TKey, TValue>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TKey> keySelector, System.Func<TSource, TValue> elementSelector) { throw null; }
-        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TSource, TKey, TValue>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TKey> keySelector, System.Func<TSource, TValue> elementSelector, System.Collections.Generic.IEqualityComparer<TKey> keyComparer) { throw null; }
-        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TSource, TKey, TValue>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TKey> keySelector, System.Func<TSource, TValue> elementSelector, System.Collections.Generic.IEqualityComparer<TKey> keyComparer, System.Collections.Generic.IEqualityComparer<TValue> valueComparer) { throw null; }
+        public static bool Contains<TKey, TValue>(this System.Collections.Immutable.IImmutableDictionary<TKey, TValue> map, TKey key, TValue value) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue>.Builder CreateBuilder<TKey, TValue>() where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue>.Builder CreateBuilder<TKey, TValue>(System.Collections.Generic.IEqualityComparer<TKey>? keyComparer) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue>.Builder CreateBuilder<TKey, TValue>(System.Collections.Generic.IEqualityComparer<TKey>? keyComparer, System.Collections.Generic.IEqualityComparer<TValue>? valueComparer) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> CreateRange<TKey, TValue>(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> items) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> CreateRange<TKey, TValue>(System.Collections.Generic.IEqualityComparer<TKey>? keyComparer, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> items) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> CreateRange<TKey, TValue>(System.Collections.Generic.IEqualityComparer<TKey>? keyComparer, System.Collections.Generic.IEqualityComparer<TValue>? valueComparer, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> items) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> Create<TKey, TValue>() where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> Create<TKey, TValue>(System.Collections.Generic.IEqualityComparer<TKey>? keyComparer) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> Create<TKey, TValue>(System.Collections.Generic.IEqualityComparer<TKey>? keyComparer, System.Collections.Generic.IEqualityComparer<TValue>? valueComparer) where TKey : notnull { throw null; }
+        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
+        public static TValue GetValueOrDefault<TKey, TValue>(this System.Collections.Immutable.IImmutableDictionary<TKey, TValue> dictionary, TKey key) where TKey : notnull { throw null; }
+        public static TValue GetValueOrDefault<TKey, TValue>(this System.Collections.Immutable.IImmutableDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TKey, TValue>(this System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> source) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TKey, TValue>(this System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> source, System.Collections.Generic.IEqualityComparer<TKey>? keyComparer) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TKey, TValue>(this System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> source, System.Collections.Generic.IEqualityComparer<TKey>? keyComparer, System.Collections.Generic.IEqualityComparer<TValue>? valueComparer) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableDictionary<TKey, TSource> ToImmutableDictionary<TSource, TKey>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TKey> keySelector) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableDictionary<TKey, TSource> ToImmutableDictionary<TSource, TKey>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TKey> keySelector, System.Collections.Generic.IEqualityComparer<TKey>? keyComparer) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TKey, TValue>(this System.Collections.Immutable.ImmutableDictionary<TKey, TValue>.Builder builder) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TSource, TKey, TValue>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TKey> keySelector, System.Func<TSource, TValue> elementSelector) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TSource, TKey, TValue>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TKey> keySelector, System.Func<TSource, TValue> elementSelector, System.Collections.Generic.IEqualityComparer<TKey>? keyComparer) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TSource, TKey, TValue>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TKey> keySelector, System.Func<TSource, TValue> elementSelector, System.Collections.Generic.IEqualityComparer<TKey>? keyComparer, System.Collections.Generic.IEqualityComparer<TValue>? valueComparer) where TKey : notnull { throw null; }
     }
-    public sealed partial class ImmutableDictionary<TKey, TValue> : System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IDictionary<TKey, TValue>, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IReadOnlyCollection<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IReadOnlyDictionary<TKey, TValue>, System.Collections.ICollection, System.Collections.IDictionary, System.Collections.IEnumerable, System.Collections.Immutable.IImmutableDictionary<TKey, TValue>
+    public sealed partial class ImmutableDictionary<TKey, TValue> : System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IDictionary<TKey, TValue>, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IReadOnlyCollection<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IReadOnlyDictionary<TKey, TValue>, System.Collections.ICollection, System.Collections.IDictionary, System.Collections.IEnumerable, System.Collections.Immutable.IImmutableDictionary<TKey, TValue> where TKey : notnull
     {
         internal ImmutableDictionary() { }
         public static readonly System.Collections.Immutable.ImmutableDictionary<TKey, TValue> Empty;
@@ -298,7 +299,7 @@ namespace System.Collections.Immutable
         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 { } }
+        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.Generic.IEqualityComparer<TValue> ValueComparer { get { throw null; } }
@@ -322,7 +323,7 @@ namespace System.Collections.Immutable
         bool System.Collections.Generic.IDictionary<TKey,TValue>.Remove(TKey key) { throw null; }
         System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<TKey, TValue>> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey,TValue>>.GetEnumerator() { throw null; }
         void System.Collections.ICollection.CopyTo(System.Array array, int arrayIndex) { }
-        void System.Collections.IDictionary.Add(object key, object value) { }
+        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; }
@@ -337,9 +338,9 @@ namespace System.Collections.Immutable
         System.Collections.Immutable.IImmutableDictionary<TKey, TValue> System.Collections.Immutable.IImmutableDictionary<TKey,TValue>.SetItems(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> items) { throw null; }
         public System.Collections.Immutable.ImmutableDictionary<TKey, TValue>.Builder ToBuilder() { throw null; }
         public bool TryGetKey(TKey equalKey, out TKey actualKey) { throw null; }
-        public bool TryGetValue(TKey key, out TValue value) { throw null; }
-        public System.Collections.Immutable.ImmutableDictionary<TKey, TValue> WithComparers(System.Collections.Generic.IEqualityComparer<TKey> keyComparer) { throw null; }
-        public System.Collections.Immutable.ImmutableDictionary<TKey, TValue> WithComparers(System.Collections.Generic.IEqualityComparer<TKey> keyComparer, System.Collections.Generic.IEqualityComparer<TValue> valueComparer) { throw null; }
+        public bool TryGetValue(TKey key, [System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out TValue value) { throw null; }
+        public System.Collections.Immutable.ImmutableDictionary<TKey, TValue> WithComparers(System.Collections.Generic.IEqualityComparer<TKey>? keyComparer) { throw null; }
+        public System.Collections.Immutable.ImmutableDictionary<TKey, TValue> WithComparers(System.Collections.Generic.IEqualityComparer<TKey>? keyComparer, System.Collections.Generic.IEqualityComparer<TValue>? valueComparer) { throw null; }
         public sealed partial class Builder : System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IDictionary<TKey, TValue>, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IReadOnlyCollection<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IReadOnlyDictionary<TKey, TValue>, System.Collections.ICollection, System.Collections.IDictionary, System.Collections.IEnumerable
         {
             internal Builder() { }
@@ -354,7 +355,7 @@ namespace System.Collections.Immutable
             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 { } }
+            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.Generic.IEqualityComparer<TValue> ValueComparer { get { throw null; } set { } }
@@ -367,6 +368,7 @@ namespace System.Collections.Immutable
             public bool ContainsKey(TKey key) { throw null; }
             public bool ContainsValue(TValue value) { throw null; }
             public System.Collections.Immutable.ImmutableDictionary<TKey, TValue>.Enumerator GetEnumerator() { throw null; }
+            [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
             public TValue GetValueOrDefault(TKey key) { throw null; }
             public TValue GetValueOrDefault(TKey key, TValue defaultValue) { throw null; }
             public bool Remove(System.Collections.Generic.KeyValuePair<TKey, TValue> item) { throw null; }
@@ -375,14 +377,14 @@ namespace System.Collections.Immutable
             void System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>.CopyTo(System.Collections.Generic.KeyValuePair<TKey, TValue>[] array, int arrayIndex) { }
             System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<TKey, TValue>> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey,TValue>>.GetEnumerator() { throw null; }
             void System.Collections.ICollection.CopyTo(System.Array array, int arrayIndex) { }
-            void System.Collections.IDictionary.Add(object key, object value) { }
+            void System.Collections.IDictionary.Add(object key, object? value) { }
             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 System.Collections.Immutable.ImmutableDictionary<TKey, TValue> ToImmutable() { throw null; }
             public bool TryGetKey(TKey equalKey, out TKey actualKey) { throw null; }
-            public bool TryGetValue(TKey key, out TValue value) { throw null; }
+            public bool TryGetValue(TKey key, [System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out TValue value) { throw null; }
         }
         public partial struct Enumerator : System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.IEnumerator, System.IDisposable
         {
@@ -398,17 +400,17 @@ namespace System.Collections.Immutable
     public static partial class ImmutableHashSet
     {
         public static System.Collections.Immutable.ImmutableHashSet<T>.Builder CreateBuilder<T>() { throw null; }
-        public static System.Collections.Immutable.ImmutableHashSet<T>.Builder CreateBuilder<T>(System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+        public static System.Collections.Immutable.ImmutableHashSet<T>.Builder CreateBuilder<T>(System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
         public static System.Collections.Immutable.ImmutableHashSet<T> CreateRange<T>(System.Collections.Generic.IEnumerable<T> items) { throw null; }
-        public static System.Collections.Immutable.ImmutableHashSet<T> CreateRange<T>(System.Collections.Generic.IEqualityComparer<T> equalityComparer, System.Collections.Generic.IEnumerable<T> items) { throw null; }
+        public static System.Collections.Immutable.ImmutableHashSet<T> CreateRange<T>(System.Collections.Generic.IEqualityComparer<T>? equalityComparer, System.Collections.Generic.IEnumerable<T> items) { throw null; }
         public static System.Collections.Immutable.ImmutableHashSet<T> Create<T>() { throw null; }
-        public static System.Collections.Immutable.ImmutableHashSet<T> Create<T>(System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
-        public static System.Collections.Immutable.ImmutableHashSet<T> Create<T>(System.Collections.Generic.IEqualityComparer<T> equalityComparer, T item) { throw null; }
-        public static System.Collections.Immutable.ImmutableHashSet<T> Create<T>(System.Collections.Generic.IEqualityComparer<T> equalityComparer, params T[] items) { throw null; }
+        public static System.Collections.Immutable.ImmutableHashSet<T> Create<T>(System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
+        public static System.Collections.Immutable.ImmutableHashSet<T> Create<T>(System.Collections.Generic.IEqualityComparer<T>? equalityComparer, T item) { throw null; }
+        public static System.Collections.Immutable.ImmutableHashSet<T> Create<T>(System.Collections.Generic.IEqualityComparer<T>? equalityComparer, params T[] items) { throw null; }
         public static System.Collections.Immutable.ImmutableHashSet<T> Create<T>(T item) { throw null; }
         public static System.Collections.Immutable.ImmutableHashSet<T> Create<T>(params T[] items) { throw null; }
         public static System.Collections.Immutable.ImmutableHashSet<TSource> ToImmutableHashSet<TSource>(this System.Collections.Generic.IEnumerable<TSource> source) { throw null; }
-        public static System.Collections.Immutable.ImmutableHashSet<TSource> ToImmutableHashSet<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Collections.Generic.IEqualityComparer<TSource> equalityComparer) { throw null; }
+        public static System.Collections.Immutable.ImmutableHashSet<TSource> ToImmutableHashSet<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Collections.Generic.IEqualityComparer<TSource>? equalityComparer) { throw null; }
         public static System.Collections.Immutable.ImmutableHashSet<TSource> ToImmutableHashSet<TSource>(this System.Collections.Immutable.ImmutableHashSet<TSource>.Builder builder) { throw null; }
     }
     public sealed partial class ImmutableHashSet<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.Generic.ISet<T>, System.Collections.ICollection, System.Collections.IEnumerable, System.Collections.Immutable.IImmutableSet<T>
@@ -457,7 +459,7 @@ namespace System.Collections.Immutable
         public System.Collections.Immutable.ImmutableHashSet<T>.Builder ToBuilder() { throw null; }
         public bool TryGetValue(T equalValue, out T actualValue) { throw null; }
         public System.Collections.Immutable.ImmutableHashSet<T> Union(System.Collections.Generic.IEnumerable<T> other) { throw null; }
-        public System.Collections.Immutable.ImmutableHashSet<T> WithComparer(System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+        public System.Collections.Immutable.ImmutableHashSet<T> WithComparer(System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
         public sealed partial class Builder : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.Generic.ISet<T>, System.Collections.IEnumerable
         {
             internal Builder() { }
@@ -490,7 +492,7 @@ namespace System.Collections.Immutable
             private object _dummy;
             private int _dummyPrimitive;
             public T Current { get { throw null; } }
-            object System.Collections.IEnumerator.Current { get { throw null; } }
+            object? System.Collections.IEnumerator.Current { get { throw null; } }
             public void Dispose() { }
             public bool MoveNext() { throw null; }
             public void Reset() { }
@@ -498,21 +500,21 @@ namespace System.Collections.Immutable
     }
     public static partial class ImmutableInterlocked
     {
-        public static TValue AddOrUpdate<TKey, TValue>(ref System.Collections.Immutable.ImmutableDictionary<TKey, TValue> location, TKey key, System.Func<TKey, TValue> addValueFactory, System.Func<TKey, TValue, TValue> updateValueFactory) { throw null; }
-        public static TValue AddOrUpdate<TKey, TValue>(ref System.Collections.Immutable.ImmutableDictionary<TKey, TValue> location, TKey key, TValue addValue, System.Func<TKey, TValue, TValue> updateValueFactory) { throw null; }
+        public static TValue AddOrUpdate<TKey, TValue>(ref System.Collections.Immutable.ImmutableDictionary<TKey, TValue> location, TKey key, System.Func<TKey, TValue> addValueFactory, System.Func<TKey, TValue, TValue> updateValueFactory) where TKey : notnull { throw null; }
+        public static TValue AddOrUpdate<TKey, TValue>(ref System.Collections.Immutable.ImmutableDictionary<TKey, TValue> location, TKey key, TValue addValue, System.Func<TKey, TValue, TValue> updateValueFactory) where TKey : notnull { throw null; }
         public static void Enqueue<T>(ref System.Collections.Immutable.ImmutableQueue<T> location, T value) { }
-        public static TValue GetOrAdd<TKey, TValue>(ref System.Collections.Immutable.ImmutableDictionary<TKey, TValue> location, TKey key, System.Func<TKey, TValue> valueFactory) { throw null; }
-        public static TValue GetOrAdd<TKey, TValue>(ref System.Collections.Immutable.ImmutableDictionary<TKey, TValue> location, TKey key, TValue value) { throw null; }
-        public static TValue GetOrAdd<TKey, TValue, TArg>(ref System.Collections.Immutable.ImmutableDictionary<TKey, TValue> location, TKey key, System.Func<TKey, TArg, TValue> valueFactory, TArg factoryArgument) { throw null; }
+        public static TValue GetOrAdd<TKey, TValue>(ref System.Collections.Immutable.ImmutableDictionary<TKey, TValue> location, TKey key, System.Func<TKey, TValue> valueFactory) where TKey : notnull { throw null; }
+        public static TValue GetOrAdd<TKey, TValue>(ref System.Collections.Immutable.ImmutableDictionary<TKey, TValue> location, TKey key, TValue value) where TKey : notnull { throw null; }
+        public static TValue GetOrAdd<TKey, TValue, TArg>(ref System.Collections.Immutable.ImmutableDictionary<TKey, TValue> location, TKey key, System.Func<TKey, TArg, TValue> valueFactory, TArg factoryArgument) where TKey : notnull { throw null; }
         public static System.Collections.Immutable.ImmutableArray<T> InterlockedCompareExchange<T>(ref System.Collections.Immutable.ImmutableArray<T> location, System.Collections.Immutable.ImmutableArray<T> value, System.Collections.Immutable.ImmutableArray<T> comparand) { throw null; }
         public static System.Collections.Immutable.ImmutableArray<T> InterlockedExchange<T>(ref System.Collections.Immutable.ImmutableArray<T> location, System.Collections.Immutable.ImmutableArray<T> value) { throw null; }
         public static bool InterlockedInitialize<T>(ref System.Collections.Immutable.ImmutableArray<T> location, System.Collections.Immutable.ImmutableArray<T> value) { throw null; }
         public static void Push<T>(ref System.Collections.Immutable.ImmutableStack<T> location, T value) { }
-        public static bool TryAdd<TKey, TValue>(ref System.Collections.Immutable.ImmutableDictionary<TKey, TValue> location, TKey key, TValue value) { throw null; }
-        public static bool TryDequeue<T>(ref System.Collections.Immutable.ImmutableQueue<T> location, out T value) { throw null; }
-        public static bool TryPop<T>(ref System.Collections.Immutable.ImmutableStack<T> location, out T value) { throw null; }
-        public static bool TryRemove<TKey, TValue>(ref System.Collections.Immutable.ImmutableDictionary<TKey, TValue> location, TKey key, out TValue value) { throw null; }
-        public static bool TryUpdate<TKey, TValue>(ref System.Collections.Immutable.ImmutableDictionary<TKey, TValue> location, TKey key, TValue newValue, TValue comparisonValue) { throw null; }
+        public static bool TryAdd<TKey, TValue>(ref System.Collections.Immutable.ImmutableDictionary<TKey, TValue> location, TKey key, TValue value) where TKey : notnull { throw null; }
+        public static bool TryDequeue<T>(ref System.Collections.Immutable.ImmutableQueue<T> location, [System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out T value) { throw null; }
+        public static bool TryPop<T>(ref System.Collections.Immutable.ImmutableStack<T> location, [System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out T value) { throw null; }
+        public static bool TryRemove<TKey, TValue>(ref System.Collections.Immutable.ImmutableDictionary<TKey, TValue> location, TKey key, [System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out TValue value) where TKey : notnull { throw null; }
+        public static bool TryUpdate<TKey, TValue>(ref System.Collections.Immutable.ImmutableDictionary<TKey, TValue> location, TKey key, TValue newValue, TValue comparisonValue) where TKey : notnull { throw null; }
         public static bool Update<T>(ref T location, System.Func<T, T> transformer) where T : class { throw null; }
         public static bool Update<T, TArg>(ref T location, System.Func<T, TArg, T> transformer, TArg transformerArgument) where T : class { throw null; }
         public static bool Update<T>(ref System.Collections.Immutable.ImmutableArray<T> location, Func<System.Collections.Immutable.ImmutableArray<T>, System.Collections.Immutable.ImmutableArray<T>> transformer) { throw null; }
@@ -526,11 +528,11 @@ namespace System.Collections.Immutable
         public static System.Collections.Immutable.ImmutableList<T> Create<T>(T item) { throw null; }
         public static System.Collections.Immutable.ImmutableList<T> Create<T>(params T[] items) { throw null; }
         public static int IndexOf<T>(this System.Collections.Immutable.IImmutableList<T> list, T item) { throw null; }
-        public static int IndexOf<T>(this System.Collections.Immutable.IImmutableList<T> list, T item, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+        public static int IndexOf<T>(this System.Collections.Immutable.IImmutableList<T> list, T item, System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
         public static int IndexOf<T>(this System.Collections.Immutable.IImmutableList<T> list, T item, int startIndex) { throw null; }
         public static int IndexOf<T>(this System.Collections.Immutable.IImmutableList<T> list, T item, int startIndex, int count) { throw null; }
         public static int LastIndexOf<T>(this System.Collections.Immutable.IImmutableList<T> list, T item) { throw null; }
-        public static int LastIndexOf<T>(this System.Collections.Immutable.IImmutableList<T> list, T item, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+        public static int LastIndexOf<T>(this System.Collections.Immutable.IImmutableList<T> list, T item, System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
         public static int LastIndexOf<T>(this System.Collections.Immutable.IImmutableList<T> list, T item, int startIndex) { throw null; }
         public static int LastIndexOf<T>(this System.Collections.Immutable.IImmutableList<T> list, T item, int startIndex, int count) { throw null; }
         public static System.Collections.Immutable.IImmutableList<T> RemoveRange<T>(this System.Collections.Immutable.IImmutableList<T> list, System.Collections.Generic.IEnumerable<T> items) { throw null; }
@@ -552,12 +554,12 @@ namespace System.Collections.Immutable
         object System.Collections.ICollection.SyncRoot { get { throw null; } }
         bool System.Collections.IList.IsFixedSize { get { throw null; } }
         bool System.Collections.IList.IsReadOnly { get { throw null; } }
-        object System.Collections.IList.this[int index] { get { throw null; } set { } }
+        object? System.Collections.IList.this[int index] { get { throw null; } set { } }
         public System.Collections.Immutable.ImmutableList<T> Add(T value) { throw null; }
         public System.Collections.Immutable.ImmutableList<T> AddRange(System.Collections.Generic.IEnumerable<T> items) { throw null; }
-        public int BinarySearch(int index, int count, T item, System.Collections.Generic.IComparer<T> comparer) { throw null; }
+        public int BinarySearch(int index, int count, T item, System.Collections.Generic.IComparer<T>? comparer) { throw null; }
         public int BinarySearch(T item) { throw null; }
-        public int BinarySearch(T item, System.Collections.Generic.IComparer<T> comparer) { throw null; }
+        public int BinarySearch(T item, System.Collections.Generic.IComparer<T>? comparer) { throw null; }
         public System.Collections.Immutable.ImmutableList<T> Clear() { throw null; }
         public bool Contains(T value) { throw null; }
         public System.Collections.Immutable.ImmutableList<TOutput> ConvertAll<TOutput>(System.Func<T, TOutput> converter) { throw null; }
@@ -565,11 +567,13 @@ namespace System.Collections.Immutable
         public void CopyTo(T[] array) { }
         public void CopyTo(T[] array, int arrayIndex) { }
         public bool Exists(System.Predicate<T> match) { throw null; }
+        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
         public T Find(System.Predicate<T> match) { throw null; }
         public System.Collections.Immutable.ImmutableList<T> FindAll(System.Predicate<T> match) { throw null; }
         public int FindIndex(int startIndex, int count, System.Predicate<T> match) { throw null; }
         public int FindIndex(int startIndex, System.Predicate<T> match) { throw null; }
         public int FindIndex(System.Predicate<T> match) { throw null; }
+        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
         public T FindLast(System.Predicate<T> match) { throw null; }
         public int FindLastIndex(int startIndex, int count, System.Predicate<T> match) { throw null; }
         public int FindLastIndex(int startIndex, System.Predicate<T> match) { throw null; }
@@ -578,29 +582,29 @@ namespace System.Collections.Immutable
         public System.Collections.Immutable.ImmutableList<T>.Enumerator GetEnumerator() { throw null; }
         public System.Collections.Immutable.ImmutableList<T> GetRange(int index, int count) { throw null; }
         public int IndexOf(T value) { throw null; }
-        public int IndexOf(T item, int index, int count, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+        public int IndexOf(T item, int index, int count, System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
         public System.Collections.Immutable.ImmutableList<T> Insert(int index, T item) { throw null; }
         public System.Collections.Immutable.ImmutableList<T> InsertRange(int index, System.Collections.Generic.IEnumerable<T> items) { throw null; }
 #if !NETSTANDARD1_0
         public ref readonly T ItemRef(int index) { throw null; }
 #endif
-        public int LastIndexOf(T item, int index, int count, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+        public int LastIndexOf(T item, int index, int count, System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
         public System.Collections.Immutable.ImmutableList<T> Remove(T value) { throw null; }
-        public System.Collections.Immutable.ImmutableList<T> Remove(T value, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+        public System.Collections.Immutable.ImmutableList<T> Remove(T value, System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
         public System.Collections.Immutable.ImmutableList<T> RemoveAll(System.Predicate<T> match) { throw null; }
         public System.Collections.Immutable.ImmutableList<T> RemoveAt(int index) { throw null; }
         public System.Collections.Immutable.ImmutableList<T> RemoveRange(System.Collections.Generic.IEnumerable<T> items) { throw null; }
-        public System.Collections.Immutable.ImmutableList<T> RemoveRange(System.Collections.Generic.IEnumerable<T> items, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+        public System.Collections.Immutable.ImmutableList<T> RemoveRange(System.Collections.Generic.IEnumerable<T> items, System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
         public System.Collections.Immutable.ImmutableList<T> RemoveRange(int index, int count) { throw null; }
         public System.Collections.Immutable.ImmutableList<T> Replace(T oldValue, T newValue) { throw null; }
-        public System.Collections.Immutable.ImmutableList<T> Replace(T oldValue, T newValue, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+        public System.Collections.Immutable.ImmutableList<T> Replace(T oldValue, T newValue, System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
         public System.Collections.Immutable.ImmutableList<T> Reverse() { throw null; }
         public System.Collections.Immutable.ImmutableList<T> Reverse(int index, int count) { throw null; }
         public System.Collections.Immutable.ImmutableList<T> SetItem(int index, T value) { throw null; }
         public System.Collections.Immutable.ImmutableList<T> Sort() { throw null; }
-        public System.Collections.Immutable.ImmutableList<T> Sort(System.Collections.Generic.IComparer<T> comparer) { throw null; }
+        public System.Collections.Immutable.ImmutableList<T> Sort(System.Collections.Generic.IComparer<T>? comparer) { throw null; }
         public System.Collections.Immutable.ImmutableList<T> Sort(System.Comparison<T> comparison) { throw null; }
-        public System.Collections.Immutable.ImmutableList<T> Sort(int index, int count, System.Collections.Generic.IComparer<T> comparer) { throw null; }
+        public System.Collections.Immutable.ImmutableList<T> Sort(int index, int count, System.Collections.Generic.IComparer<T>? comparer) { throw null; }
         void System.Collections.Generic.ICollection<T>.Add(T item) { }
         void System.Collections.Generic.ICollection<T>.Clear() { }
         bool System.Collections.Generic.ICollection<T>.Remove(T item) { throw null; }
@@ -609,24 +613,24 @@ namespace System.Collections.Immutable
         void System.Collections.Generic.IList<T>.RemoveAt(int index) { }
         void System.Collections.ICollection.CopyTo(System.Array array, int arrayIndex) { }
         System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
-        int System.Collections.IList.Add(object value) { throw null; }
+        int System.Collections.IList.Add(object? value) { throw null; }
         void System.Collections.IList.Clear() { }
-        bool System.Collections.IList.Contains(object value) { throw null; }
-        int System.Collections.IList.IndexOf(object value) { throw null; }
-        void System.Collections.IList.Insert(int index, object value) { }
-        void System.Collections.IList.Remove(object value) { }
+        bool System.Collections.IList.Contains(object? value) { throw null; }
+        int System.Collections.IList.IndexOf(object? value) { throw null; }
+        void System.Collections.IList.Insert(int index, object? value) { }
+        void System.Collections.IList.Remove(object? value) { }
         void System.Collections.IList.RemoveAt(int index) { }
         System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.Add(T value) { throw null; }
         System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.AddRange(System.Collections.Generic.IEnumerable<T> items) { throw null; }
         System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.Clear() { throw null; }
         System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.Insert(int index, T item) { throw null; }
         System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.InsertRange(int index, System.Collections.Generic.IEnumerable<T> items) { throw null; }
-        System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.Remove(T value, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+        System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.Remove(T value, System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
         System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.RemoveAll(System.Predicate<T> match) { throw null; }
         System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.RemoveAt(int index) { throw null; }
-        System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.RemoveRange(System.Collections.Generic.IEnumerable<T> items, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+        System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.RemoveRange(System.Collections.Generic.IEnumerable<T> items, System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
         System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.RemoveRange(int index, int count) { throw null; }
-        System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.Replace(T oldValue, T newValue, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+        System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.Replace(T oldValue, T newValue, System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
         System.Collections.Immutable.IImmutableList<T> System.Collections.Immutable.IImmutableList<T>.SetItem(int index, T value) { throw null; }
         public System.Collections.Immutable.ImmutableList<T>.Builder ToBuilder() { throw null; }
         public bool TrueForAll(System.Predicate<T> match) { throw null; }
@@ -640,12 +644,12 @@ namespace System.Collections.Immutable
             object System.Collections.ICollection.SyncRoot { get { throw null; } }
             bool System.Collections.IList.IsFixedSize { get { throw null; } }
             bool System.Collections.IList.IsReadOnly { get { throw null; } }
-            object System.Collections.IList.this[int index] { get { throw null; } set { } }
+            object? System.Collections.IList.this[int index] { get { throw null; } set { } }
             public void Add(T item) { }
             public void AddRange(System.Collections.Generic.IEnumerable<T> items) { }
-            public int BinarySearch(int index, int count, T item, System.Collections.Generic.IComparer<T> comparer) { throw null; }
+            public int BinarySearch(int index, int count, T item, System.Collections.Generic.IComparer<T>? comparer) { throw null; }
             public int BinarySearch(T item) { throw null; }
-            public int BinarySearch(T item, System.Collections.Generic.IComparer<T> comparer) { throw null; }
+            public int BinarySearch(T item, System.Collections.Generic.IComparer<T>? comparer) { throw null; }
             public void Clear() { }
             public bool Contains(T item) { throw null; }
             public System.Collections.Immutable.ImmutableList<TOutput> ConvertAll<TOutput>(System.Func<T, TOutput> converter) { throw null; }
@@ -653,11 +657,13 @@ namespace System.Collections.Immutable
             public void CopyTo(T[] array) { }
             public void CopyTo(T[] array, int arrayIndex) { }
             public bool Exists(System.Predicate<T> match) { throw null; }
+            [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
             public T Find(System.Predicate<T> match) { throw null; }
             public System.Collections.Immutable.ImmutableList<T> FindAll(System.Predicate<T> match) { throw null; }
             public int FindIndex(int startIndex, int count, System.Predicate<T> match) { throw null; }
             public int FindIndex(int startIndex, System.Predicate<T> match) { throw null; }
             public int FindIndex(System.Predicate<T> match) { throw null; }
+            [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
             public T FindLast(System.Predicate<T> match) { throw null; }
             public int FindLastIndex(int startIndex, int count, System.Predicate<T> match) { throw null; }
             public int FindLastIndex(int startIndex, System.Predicate<T> match) { throw null; }
@@ -668,7 +674,7 @@ namespace System.Collections.Immutable
             public int IndexOf(T item) { throw null; }
             public int IndexOf(T item, int index) { throw null; }
             public int IndexOf(T item, int index, int count) { throw null; }
-            public int IndexOf(T item, int index, int count, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+            public int IndexOf(T item, int index, int count, System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
             public void Insert(int index, T item) { }
             public void InsertRange(int index, System.Collections.Generic.IEnumerable<T> items) { }
 #if !NETSTANDARD1_0
@@ -677,25 +683,25 @@ namespace System.Collections.Immutable
             public int LastIndexOf(T item) { throw null; }
             public int LastIndexOf(T item, int startIndex) { throw null; }
             public int LastIndexOf(T item, int startIndex, int count) { throw null; }
-            public int LastIndexOf(T item, int startIndex, int count, System.Collections.Generic.IEqualityComparer<T> equalityComparer) { throw null; }
+            public int LastIndexOf(T item, int startIndex, int count, System.Collections.Generic.IEqualityComparer<T>? equalityComparer) { throw null; }
             public bool Remove(T item) { throw null; }
             public int RemoveAll(System.Predicate<T> match) { throw null; }
             public void RemoveAt(int index) { }
             public void Reverse() { }
             public void Reverse(int index, int count) { }
             public void Sort() { }
-            public void Sort(System.Collections.Generic.IComparer<T> comparer) { }
+            public void Sort(System.Collections.Generic.IComparer<T>? comparer) { }
             public void Sort(System.Comparison<T> comparison) { }
-            public void Sort(int index, int count, System.Collections.Generic.IComparer<T> comparer) { }
+            public void Sort(int index, int count, System.Collections.Generic.IComparer<T>? comparer) { }
             System.Collections.Generic.IEnumerator<T> System.Collections.Generic.IEnumerable<T>.GetEnumerator() { throw null; }
             void System.Collections.ICollection.CopyTo(System.Array array, int arrayIndex) { }
             System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
             int System.Collections.IList.Add(object value) { throw null; }
             void System.Collections.IList.Clear() { }
-            bool System.Collections.IList.Contains(object value) { throw null; }
-            int System.Collections.IList.IndexOf(object value) { throw null; }
-            void System.Collections.IList.Insert(int index, object value) { }
-            void System.Collections.IList.Remove(object value) { }
+            bool System.Collections.IList.Contains(object? value) { throw null; }
+            int System.Collections.IList.IndexOf(object? value) { throw null; }
+            void System.Collections.IList.Insert(int index, object? value) { }
+            void System.Collections.IList.Remove(object? value) { }
             public System.Collections.Immutable.ImmutableList<T> ToImmutable() { throw null; }
             public bool TrueForAll(System.Predicate<T> match) { throw null; }
         }
@@ -705,7 +711,7 @@ namespace System.Collections.Immutable
             private object _dummy;
             private int _dummyPrimitive;
             public T Current { get { throw null; } }
-            object System.Collections.IEnumerator.Current { get { throw null; } }
+            object? System.Collections.IEnumerator.Current { get { throw null; } }
             public void Dispose() { }
             public bool MoveNext() { throw null; }
             public void Reset() { }
@@ -749,24 +755,24 @@ namespace System.Collections.Immutable
     }
     public static partial class ImmutableSortedDictionary
     {
-        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue>.Builder CreateBuilder<TKey, TValue>() { throw null; }
-        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue>.Builder CreateBuilder<TKey, TValue>(System.Collections.Generic.IComparer<TKey> keyComparer) { throw null; }
-        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue>.Builder CreateBuilder<TKey, TValue>(System.Collections.Generic.IComparer<TKey> keyComparer, System.Collections.Generic.IEqualityComparer<TValue> valueComparer) { throw null; }
-        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> CreateRange<TKey, TValue>(System.Collections.Generic.IComparer<TKey> keyComparer, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> items) { throw null; }
-        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> CreateRange<TKey, TValue>(System.Collections.Generic.IComparer<TKey> keyComparer, System.Collections.Generic.IEqualityComparer<TValue> valueComparer, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> items) { throw null; }
-        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> CreateRange<TKey, TValue>(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> items) { throw null; }
-        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> Create<TKey, TValue>() { throw null; }
-        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> Create<TKey, TValue>(System.Collections.Generic.IComparer<TKey> keyComparer) { throw null; }
-        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> Create<TKey, TValue>(System.Collections.Generic.IComparer<TKey> keyComparer, System.Collections.Generic.IEqualityComparer<TValue> valueComparer) { throw null; }
-        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TKey, TValue>(this System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> source) { throw null; }
-        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TKey, TValue>(this System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> source, System.Collections.Generic.IComparer<TKey> keyComparer) { throw null; }
-        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TKey, TValue>(this System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> source, System.Collections.Generic.IComparer<TKey> keyComparer, System.Collections.Generic.IEqualityComparer<TValue> valueComparer) { throw null; }
-        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TKey, TValue>(this System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue>.Builder builder) { throw null; }
-        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TSource, TKey, TValue>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TKey> keySelector, System.Func<TSource, TValue> elementSelector) { throw null; }
-        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TSource, TKey, TValue>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TKey> keySelector, System.Func<TSource, TValue> elementSelector, System.Collections.Generic.IComparer<TKey> keyComparer) { throw null; }
-        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TSource, TKey, TValue>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TKey> keySelector, System.Func<TSource, TValue> elementSelector, System.Collections.Generic.IComparer<TKey> keyComparer, System.Collections.Generic.IEqualityComparer<TValue> valueComparer) { throw null; }
+        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue>.Builder CreateBuilder<TKey, TValue>() where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue>.Builder CreateBuilder<TKey, TValue>(System.Collections.Generic.IComparer<TKey>? keyComparer) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue>.Builder CreateBuilder<TKey, TValue>(System.Collections.Generic.IComparer<TKey>? keyComparer, System.Collections.Generic.IEqualityComparer<TValue>? valueComparer) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> CreateRange<TKey, TValue>(System.Collections.Generic.IComparer<TKey>? keyComparer, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> items) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> CreateRange<TKey, TValue>(System.Collections.Generic.IComparer<TKey>? keyComparer, System.Collections.Generic.IEqualityComparer<TValue>? valueComparer, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> items) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> CreateRange<TKey, TValue>(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> items) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> Create<TKey, TValue>() where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> Create<TKey, TValue>(System.Collections.Generic.IComparer<TKey>? keyComparer) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> Create<TKey, TValue>(System.Collections.Generic.IComparer<TKey>? keyComparer, System.Collections.Generic.IEqualityComparer<TValue>? valueComparer) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TKey, TValue>(this System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> source) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TKey, TValue>(this System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> source, System.Collections.Generic.IComparer<TKey>? keyComparer) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TKey, TValue>(this System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> source, System.Collections.Generic.IComparer<TKey>? keyComparer, System.Collections.Generic.IEqualityComparer<TValue>? valueComparer) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TKey, TValue>(this System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue>.Builder builder) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TSource, TKey, TValue>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TKey> keySelector, System.Func<TSource, TValue> elementSelector) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TSource, TKey, TValue>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TKey> keySelector, System.Func<TSource, TValue> elementSelector, System.Collections.Generic.IComparer<TKey>? keyComparer) where TKey : notnull { throw null; }
+        public static System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TSource, TKey, TValue>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TKey> keySelector, System.Func<TSource, TValue> elementSelector, System.Collections.Generic.IComparer<TKey>? keyComparer, System.Collections.Generic.IEqualityComparer<TValue>? valueComparer) where TKey : notnull { throw null; }
     }
-    public sealed partial class ImmutableSortedDictionary<TKey, TValue> : System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IDictionary<TKey, TValue>, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IReadOnlyCollection<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IReadOnlyDictionary<TKey, TValue>, System.Collections.ICollection, System.Collections.IDictionary, System.Collections.IEnumerable, System.Collections.Immutable.IImmutableDictionary<TKey, TValue>
+    public sealed partial class ImmutableSortedDictionary<TKey, TValue> : System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IDictionary<TKey, TValue>, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IReadOnlyCollection<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IReadOnlyDictionary<TKey, TValue>, System.Collections.ICollection, System.Collections.IDictionary, System.Collections.IEnumerable, System.Collections.Immutable.IImmutableDictionary<TKey, TValue> where TKey : notnull
     {
         internal ImmutableSortedDictionary() { }
         public static readonly System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> Empty;
@@ -783,7 +789,7 @@ namespace System.Collections.Immutable
         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 { } }
+        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.Generic.IEqualityComparer<TValue> ValueComparer { get { throw null; } }
@@ -822,12 +828,12 @@ namespace System.Collections.Immutable
         System.Collections.Immutable.IImmutableDictionary<TKey, TValue> System.Collections.Immutable.IImmutableDictionary<TKey,TValue>.SetItems(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> items) { throw null; }
         public System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue>.Builder ToBuilder() { throw null; }
         public bool TryGetKey(TKey equalKey, out TKey actualKey) { throw null; }
-        public bool TryGetValue(TKey key, out TValue value) { throw null; }
+        public bool TryGetValue(TKey key, [System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out TValue value) { throw null; }
 #if !NETSTANDARD1_0
         public ref readonly TValue ValueRef(TKey key) { throw null; }
 #endif
-        public System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> WithComparers(System.Collections.Generic.IComparer<TKey> keyComparer) { throw null; }
-        public System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> WithComparers(System.Collections.Generic.IComparer<TKey> keyComparer, System.Collections.Generic.IEqualityComparer<TValue> valueComparer) { throw null; }
+        public System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> WithComparers(System.Collections.Generic.IComparer<TKey>? keyComparer) { throw null; }
+        public System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> WithComparers(System.Collections.Generic.IComparer<TKey>? keyComparer, System.Collections.Generic.IEqualityComparer<TValue>? valueComparer) { throw null; }
         public sealed partial class Builder : System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IDictionary<TKey, TValue>, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IReadOnlyCollection<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IReadOnlyDictionary<TKey, TValue>, System.Collections.ICollection, System.Collections.IDictionary, System.Collections.IEnumerable
         {
             internal Builder() { }
@@ -842,7 +848,7 @@ namespace System.Collections.Immutable
             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 { } }
+            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.Generic.IEqualityComparer<TValue> ValueComparer { get { throw null; } set { } }
@@ -855,6 +861,7 @@ namespace System.Collections.Immutable
             public bool ContainsKey(TKey key) { throw null; }
             public bool ContainsValue(TValue value) { throw null; }
             public System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue>.Enumerator GetEnumerator() { throw null; }
+            [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
             public TValue GetValueOrDefault(TKey key) { throw null; }
             public TValue GetValueOrDefault(TKey key, TValue defaultValue) { throw null; }
             public bool Remove(System.Collections.Generic.KeyValuePair<TKey, TValue> item) { throw null; }
@@ -863,14 +870,14 @@ namespace System.Collections.Immutable
             void System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey,TValue>>.CopyTo(System.Collections.Generic.KeyValuePair<TKey, TValue>[] array, int arrayIndex) { }
             System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<TKey, TValue>> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey,TValue>>.GetEnumerator() { 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.Add(object key, object? value) { }
             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 System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue> ToImmutable() { throw null; }
             public bool TryGetKey(TKey equalKey, out TKey actualKey) { throw null; }
-            public bool TryGetValue(TKey key, out TValue value) { throw null; }
+            public bool TryGetValue(TKey key, [System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out TValue value) { throw null; }
 #if !NETSTANDARD1_0
             public ref readonly TValue ValueRef(TKey key) { throw null; }
 #endif
@@ -890,17 +897,17 @@ namespace System.Collections.Immutable
     public static partial class ImmutableSortedSet
     {
         public static System.Collections.Immutable.ImmutableSortedSet<T>.Builder CreateBuilder<T>() { throw null; }
-        public static System.Collections.Immutable.ImmutableSortedSet<T>.Builder CreateBuilder<T>(System.Collections.Generic.IComparer<T> comparer) { throw null; }
-        public static System.Collections.Immutable.ImmutableSortedSet<T> CreateRange<T>(System.Collections.Generic.IComparer<T> comparer, System.Collections.Generic.IEnumerable<T> items) { throw null; }
+        public static System.Collections.Immutable.ImmutableSortedSet<T>.Builder CreateBuilder<T>(System.Collections.Generic.IComparer<T>? comparer) { throw null; }
+        public static System.Collections.Immutable.ImmutableSortedSet<T> CreateRange<T>(System.Collections.Generic.IComparer<T>? comparer, System.Collections.Generic.IEnumerable<T> items) { throw null; }
         public static System.Collections.Immutable.ImmutableSortedSet<T> CreateRange<T>(System.Collections.Generic.IEnumerable<T> items) { throw null; }
         public static System.Collections.Immutable.ImmutableSortedSet<T> Create<T>() { throw null; }
-        public static System.Collections.Immutable.ImmutableSortedSet<T> Create<T>(System.Collections.Generic.IComparer<T> comparer) { throw null; }
-        public static System.Collections.Immutable.ImmutableSortedSet<T> Create<T>(System.Collections.Generic.IComparer<T> comparer, T item) { throw null; }
-        public static System.Collections.Immutable.ImmutableSortedSet<T> Create<T>(System.Collections.Generic.IComparer<T> comparer, params T[] items) { throw null; }
+        public static System.Collections.Immutable.ImmutableSortedSet<T> Create<T>(System.Collections.Generic.IComparer<T>? comparer) { throw null; }
+        public static System.Collections.Immutable.ImmutableSortedSet<T> Create<T>(System.Collections.Generic.IComparer<T>? comparer, T item) { throw null; }
+        public static System.Collections.Immutable.ImmutableSortedSet<T> Create<T>(System.Collections.Generic.IComparer<T>? comparer, params T[] items) { throw null; }
         public static System.Collections.Immutable.ImmutableSortedSet<T> Create<T>(T item) { throw null; }
         public static System.Collections.Immutable.ImmutableSortedSet<T> Create<T>(params T[] items) { throw null; }
         public static System.Collections.Immutable.ImmutableSortedSet<TSource> ToImmutableSortedSet<TSource>(this System.Collections.Generic.IEnumerable<TSource> source) { throw null; }
-        public static System.Collections.Immutable.ImmutableSortedSet<TSource> ToImmutableSortedSet<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Collections.Generic.IComparer<TSource> comparer) { throw null; }
+        public static System.Collections.Immutable.ImmutableSortedSet<TSource> ToImmutableSortedSet<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Collections.Generic.IComparer<TSource>? comparer) { throw null; }
         public static System.Collections.Immutable.ImmutableSortedSet<TSource> ToImmutableSortedSet<TSource>(this System.Collections.Immutable.ImmutableSortedSet<TSource>.Builder builder) { throw null; }
     }
     public sealed partial class ImmutableSortedSet<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IList<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.Generic.IReadOnlyList<T>, System.Collections.Generic.ISet<T>, System.Collections.ICollection, System.Collections.IEnumerable, System.Collections.IList, System.Collections.Immutable.IImmutableSet<T>
@@ -911,7 +918,9 @@ namespace System.Collections.Immutable
         public bool IsEmpty { get { throw null; } }
         public T this[int index] { get { throw null; } }
         public System.Collections.Generic.IComparer<T> KeyComparer { get { throw null; } }
+        [System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
         public T Max { get { throw null; } }
+        [System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
         public T Min { get { throw null; } }
         bool System.Collections.Generic.ICollection<T>.IsReadOnly { get { throw null; } }
         T System.Collections.Generic.IList<T>.this[int index] { get { throw null; } set { } }
@@ -919,7 +928,7 @@ namespace System.Collections.Immutable
         object System.Collections.ICollection.SyncRoot { get { throw null; } }
         bool System.Collections.IList.IsFixedSize { get { throw null; } }
         bool System.Collections.IList.IsReadOnly { get { throw null; } }
-        object System.Collections.IList.this[int index] { get { throw null; } set { } }
+        object? System.Collections.IList.this[int index] { get { throw null; } set { } }
         public System.Collections.Immutable.ImmutableSortedSet<T> Add(T value) { throw null; }
         public System.Collections.Immutable.ImmutableSortedSet<T> Clear() { throw null; }
         public bool Contains(T value) { throw null; }
@@ -953,12 +962,12 @@ namespace System.Collections.Immutable
         void System.Collections.Generic.ISet<T>.UnionWith(System.Collections.Generic.IEnumerable<T> other) { }
         void System.Collections.ICollection.CopyTo(System.Array array, int index) { }
         System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
-        int System.Collections.IList.Add(object value) { throw null; }
+        int System.Collections.IList.Add(object? value) { throw null; }
         void System.Collections.IList.Clear() { }
-        bool System.Collections.IList.Contains(object value) { throw null; }
-        int System.Collections.IList.IndexOf(object value) { throw null; }
-        void System.Collections.IList.Insert(int index, object value) { }
-        void System.Collections.IList.Remove(object value) { }
+        bool System.Collections.IList.Contains(object? value) { throw null; }
+        int System.Collections.IList.IndexOf(object? value) { throw null; }
+        void System.Collections.IList.Insert(int index, object? value) { }
+        void System.Collections.IList.Remove(object? value) { }
         void System.Collections.IList.RemoveAt(int index) { }
         System.Collections.Immutable.IImmutableSet<T> System.Collections.Immutable.IImmutableSet<T>.Add(T value) { throw null; }
         System.Collections.Immutable.IImmutableSet<T> System.Collections.Immutable.IImmutableSet<T>.Clear() { throw null; }
@@ -970,14 +979,16 @@ namespace System.Collections.Immutable
         public System.Collections.Immutable.ImmutableSortedSet<T>.Builder ToBuilder() { throw null; }
         public bool TryGetValue(T equalValue, out T actualValue) { throw null; }
         public System.Collections.Immutable.ImmutableSortedSet<T> Union(System.Collections.Generic.IEnumerable<T> other) { throw null; }
-        public System.Collections.Immutable.ImmutableSortedSet<T> WithComparer(System.Collections.Generic.IComparer<T> comparer) { throw null; }
+        public System.Collections.Immutable.ImmutableSortedSet<T> WithComparer(System.Collections.Generic.IComparer<T>? comparer) { throw null; }
         public sealed partial class Builder : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.Generic.ISet<T>, System.Collections.ICollection, System.Collections.IEnumerable
         {
             internal Builder() { }
             public int Count { get { throw null; } }
             public T this[int index] { get { throw null; } }
             public System.Collections.Generic.IComparer<T> KeyComparer { get { throw null; } set { } }
+            [System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
             public T Max { get { throw null; } }
+            [System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
             public T Min { get { throw null; } }
             bool System.Collections.Generic.ICollection<T>.IsReadOnly { get { throw null; } }
             bool System.Collections.ICollection.IsSynchronized { get { throw null; } }
@@ -1014,7 +1025,7 @@ namespace System.Collections.Immutable
             private object _dummy;
             private int _dummyPrimitive;
             public T Current { get { throw null; } }
-            object System.Collections.IEnumerator.Current { get { throw null; } }
+            object? System.Collections.IEnumerator.Current { get { throw null; } }
             public void Dispose() { }
             public bool MoveNext() { throw null; }
             public void Reset() { }
@@ -1061,6 +1072,7 @@ namespace System.Linq
 {
     public static partial class ImmutableArrayExtensions
     {
+        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
         public static T Aggregate<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, T, T> func) { throw null; }
         public static TAccumulate Aggregate<TAccumulate, T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, TAccumulate seed, System.Func<TAccumulate, T, TAccumulate> func) { throw null; }
         public static TResult Aggregate<TAccumulate, TResult, T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, TAccumulate seed, System.Func<TAccumulate, T, TAccumulate> func, System.Func<TAccumulate, TResult> resultSelector) { throw null; }
@@ -1068,34 +1080,43 @@ namespace System.Linq
         public static bool Any<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray) { throw null; }
         public static bool Any<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, bool> predicate) { throw null; }
         public static bool Any<T>(this System.Collections.Immutable.ImmutableArray<T>.Builder builder) { throw null; }
+        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
         public static T ElementAtOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, int index) { throw null; }
         public static T ElementAt<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, int index) { throw null; }
+        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
         public static T FirstOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray) { throw null; }
+        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
         public static T FirstOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, bool> predicate) { throw null; }
+        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
         public static T FirstOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T>.Builder builder) { throw null; }
         public static T First<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray) { throw null; }
         public static T First<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, bool> predicate) { throw null; }
         public static T First<T>(this System.Collections.Immutable.ImmutableArray<T>.Builder builder) { throw null; }
+        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
         public static T LastOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray) { throw null; }
+        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
         public static T LastOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, bool> predicate) { throw null; }
+        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
         public static T LastOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T>.Builder builder) { throw null; }
         public static T Last<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray) { throw null; }
         public static T Last<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, bool> predicate) { throw null; }
         public static T Last<T>(this System.Collections.Immutable.ImmutableArray<T>.Builder builder) { throw null; }
         public static System.Collections.Generic.IEnumerable<TResult> SelectMany<TSource, TCollection, TResult>(this System.Collections.Immutable.ImmutableArray<TSource> immutableArray, System.Func<TSource, System.Collections.Generic.IEnumerable<TCollection>> collectionSelector, System.Func<TSource, TCollection, TResult> resultSelector) { throw null; }
         public static System.Collections.Generic.IEnumerable<TResult> Select<T, TResult>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, TResult> selector) { throw null; }
-        public static bool SequenceEqual<TDerived, TBase>(this System.Collections.Immutable.ImmutableArray<TBase> immutableArray, System.Collections.Generic.IEnumerable<TDerived> items, System.Collections.Generic.IEqualityComparer<TBase> comparer = null) where TDerived : TBase { throw null; }
-        public static bool SequenceEqual<TDerived, TBase>(this System.Collections.Immutable.ImmutableArray<TBase> immutableArray, System.Collections.Immutable.ImmutableArray<TDerived> items, System.Collections.Generic.IEqualityComparer<TBase> comparer = null) where TDerived : TBase { throw null; }
+        public static bool SequenceEqual<TDerived, TBase>(this System.Collections.Immutable.ImmutableArray<TBase> immutableArray, System.Collections.Generic.IEnumerable<TDerived> items, System.Collections.Generic.IEqualityComparer<TBase>? comparer = null) where TDerived : TBase { throw null; }
+        public static bool SequenceEqual<TDerived, TBase>(this System.Collections.Immutable.ImmutableArray<TBase> immutableArray, System.Collections.Immutable.ImmutableArray<TDerived> items, System.Collections.Generic.IEqualityComparer<TBase>? comparer = null) where TDerived : TBase { throw null; }
         public static bool SequenceEqual<TDerived, TBase>(this System.Collections.Immutable.ImmutableArray<TBase> immutableArray, System.Collections.Immutable.ImmutableArray<TDerived> items, System.Func<TBase, TBase, bool> predicate) where TDerived : TBase { throw null; }
+        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
         public static T SingleOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray) { throw null; }
+        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
         public static T SingleOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, bool> predicate) { throw null; }
         public static T Single<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray) { throw null; }
         public static T Single<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, bool> predicate) { throw null; }
         public static T[] ToArray<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray) { throw null; }
-        public static System.Collections.Generic.Dictionary<TKey, T> ToDictionary<TKey, T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, TKey> keySelector) { throw null; }
-        public static System.Collections.Generic.Dictionary<TKey, T> ToDictionary<TKey, T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, TKey> keySelector, System.Collections.Generic.IEqualityComparer<TKey> comparer) { throw null; }
-        public static System.Collections.Generic.Dictionary<TKey, TElement> ToDictionary<TKey, TElement, T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, TKey> keySelector, System.Func<T, TElement> elementSelector) { throw null; }
-        public static System.Collections.Generic.Dictionary<TKey, TElement> ToDictionary<TKey, TElement, T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, TKey> keySelector, System.Func<T, TElement> elementSelector, System.Collections.Generic.IEqualityComparer<TKey> comparer) { throw null; }
+        public static System.Collections.Generic.Dictionary<TKey, T> ToDictionary<TKey, T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, TKey> keySelector) where TKey : notnull { throw null; }
+        public static System.Collections.Generic.Dictionary<TKey, T> ToDictionary<TKey, T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, TKey> keySelector, System.Collections.Generic.IEqualityComparer<TKey>? comparer) where TKey : notnull { throw null; }
+        public static System.Collections.Generic.Dictionary<TKey, TElement> ToDictionary<TKey, TElement, T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, TKey> keySelector, System.Func<T, TElement> elementSelector) where TKey : notnull { throw null; }
+        public static System.Collections.Generic.Dictionary<TKey, TElement> ToDictionary<TKey, TElement, T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, TKey> keySelector, System.Func<T, TElement> elementSelector, System.Collections.Generic.IEqualityComparer<TKey>? comparer) where TKey : notnull { throw null; }
         public static System.Collections.Generic.IEnumerable<T> Where<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, bool> predicate) { throw null; }
     }
 }
index 18c3b30..ec1a0ad 100644 (file)
@@ -1,6 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
     <Configurations>$(NetCoreAppCurrent)-Debug;$(NetCoreAppCurrent)-Release;netstandard2.0-Debug;netstandard2.0-Release;netstandard1.0-Debug;netstandard1.0-Release;netstandard1.3-Debug;netstandard1.3-Release</Configurations>
+    <Nullable>enable</Nullable>
   </PropertyGroup>
   <ItemGroup>
     <Compile Include="System.Collections.Immutable.cs" />
index 72d1a44..41fd39c 100644 (file)
@@ -5,6 +5,7 @@
     <FileAlignment>512</FileAlignment>
     <PackageTargetFramework Condition="'$(TargetFramework)' == 'netstandard1.0'">netstandard1.0;portable-net45+win8+wp8+wpa81</PackageTargetFramework>
     <Configurations>$(NetCoreAppCurrent)-Debug;$(NetCoreAppCurrent)-Release;netstandard2.0-Debug;netstandard2.0-Release;netstandard1.0-Debug;netstandard1.0-Release;netstandard1.3-Debug;netstandard1.3-Release</Configurations>
+    <Nullable>enable</Nullable>
   </PropertyGroup>
   <ItemGroup>
     <Compile Include="Properties\InternalsVisibleTo.cs" />
index 5f32156..7d68aba 100644 (file)
@@ -3,6 +3,7 @@
 // See the LICENSE file in the project root for more information.
 
 using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
 
 namespace System.Collections.Immutable
 {
@@ -22,7 +23,7 @@ namespace System.Collections.Immutable
             }
         }
 
-        public static bool TryTake(out T item)
+        public static bool TryTake([MaybeNullWhen(false)] out T item)
         {
             Stack<RefAsValueType<T>> localStack = ThreadLocalStack;
             if (localStack != null && localStack.Count > 0)
@@ -31,7 +32,7 @@ namespace System.Collections.Immutable
                 return true;
             }
 
-            item = default(T);
+            item = default(T)!;
             return false;
         }
 
@@ -40,15 +41,14 @@ namespace System.Collections.Immutable
             get
             {
                 // Ensure the [ThreadStatic] is initialized to a dictionary
-                Dictionary<Type, object> typesToStacks = AllocFreeConcurrentStack.t_stacks;
+                Dictionary<Type, object>? typesToStacks = AllocFreeConcurrentStack.t_stacks;
                 if (typesToStacks == null)
                 {
                     AllocFreeConcurrentStack.t_stacks = typesToStacks = new Dictionary<Type, object>();
                 }
 
                 // Get the stack that corresponds to the T
-                object stackObj;
-                if (!typesToStacks.TryGetValue(s_typeOfT, out stackObj))
+                if (!typesToStacks.TryGetValue(s_typeOfT, out object? stackObj))
                 {
                     stackObj = new Stack<RefAsValueType<T>>(MaxSize);
                     typesToStacks.Add(s_typeOfT, stackObj);
@@ -71,6 +71,6 @@ namespace System.Collections.Immutable
         // When that's fixed, a [ThreadStatic] Stack should be added back to AllocFreeConcurrentStack<T>.
 
         [ThreadStatic]
-        internal static Dictionary<Type, object> t_stacks;
+        internal static Dictionary<Type, object>? t_stacks;
     }
 }
index 4ba86b3..5a5a369 100644 (file)
@@ -6,7 +6,7 @@ using System.Collections.Generic;
 
 namespace System.Collections.Immutable
 {
-    internal sealed class DictionaryEnumerator<TKey, TValue> : IDictionaryEnumerator
+    internal sealed class DictionaryEnumerator<TKey, TValue> : IDictionaryEnumerator where TKey : notnull
     {
         private readonly IEnumerator<KeyValuePair<TKey, TValue>> _inner;
 
@@ -27,7 +27,7 @@ namespace System.Collections.Immutable
             get { return _inner.Current.Key; }
         }
 
-        public object Value
+        public object? Value
         {
             get { return _inner.Current.Value; }
         }
index d2dd253..51c2368 100644 (file)
@@ -18,7 +18,7 @@ namespace System.Collections.Immutable
         /// <summary>
         /// The enumerator object to use if not null.
         /// </summary>
-        private readonly IEnumerator<T> _enumeratorObject;
+        private readonly IEnumerator<T>? _enumeratorObject;
 
         /// <summary>
         /// The enumerator struct to use if <see cref="_enumeratorObject"/> is <c>null</c>.
index 0ba2e2f..e4aecda 100644 (file)
@@ -27,12 +27,12 @@ namespace System.Collections.Immutable
         /// <summary>
         /// Gets the left branch of this node.
         /// </summary>
-        IBinaryTree Left { get; }
+        IBinaryTree? Left { get; }
 
         /// <summary>
         /// Gets the right branch of this node.
         /// </summary>
-        IBinaryTree Right { get; }
+        IBinaryTree? Right { get; }
     }
 
     /// <summary>
@@ -49,11 +49,11 @@ namespace System.Collections.Immutable
         /// <summary>
         /// Gets the left branch of this node.
         /// </summary>
-        new IBinaryTree<T> Left { get; }
+        new IBinaryTree<T>? Left { get; }
 
         /// <summary>
         /// Gets the right branch of this node.
         /// </summary>
-        new IBinaryTree<T> Right { get; }
+        new IBinaryTree<T>? Right { get; }
     }
 }
index 8e721e7..7baeb7f 100644 (file)
@@ -21,6 +21,6 @@ namespace System.Collections.Immutable
         /// <summary>
         /// Gets an untyped reference to the array.
         /// </summary>
-        Array Array { get; }
+        Array? Array { get; }
     }
 }
index 9d75cf2..b6e4297 100644 (file)
@@ -51,7 +51,7 @@ namespace System.Collections.Immutable
         /// contains count number of elements, if found; otherwise, -1.
         /// </returns>
         [Pure]
-        int IndexOf(T item, int index, int count, IEqualityComparer<T> equalityComparer);
+        int IndexOf(T item, int index, int count, IEqualityComparer<T>? equalityComparer);
 
         /// <summary>
         /// Searches for the specified object and returns the zero-based index of the
@@ -75,7 +75,7 @@ namespace System.Collections.Immutable
         /// and ends at <paramref name="index"/>, if found; otherwise, -1.
         /// </returns>
         [Pure]
-        int LastIndexOf(T item, int index, int count, IEqualityComparer<T> equalityComparer);
+        int LastIndexOf(T item, int index, int count, IEqualityComparer<T>? equalityComparer);
 
         /// <summary>
         /// Adds the specified value to this list.
@@ -121,7 +121,7 @@ namespace System.Collections.Immutable
         /// </param>
         /// <returns>A new list with the element removed, or this list if the element is not in this list.</returns>
         [Pure]
-        IImmutableList<T> Remove(T value, IEqualityComparer<T> equalityComparer);
+        IImmutableList<T> Remove(T value, IEqualityComparer<T>? equalityComparer);
 
         /// <summary>
         /// Removes all the elements that match the conditions defined by the specified
@@ -149,7 +149,7 @@ namespace System.Collections.Immutable
         /// A new list with the elements removed.
         /// </returns>
         [Pure]
-        IImmutableList<T> RemoveRange(IEnumerable<T> items, IEqualityComparer<T> equalityComparer);
+        IImmutableList<T> RemoveRange(IEnumerable<T> items, IEqualityComparer<T>? equalityComparer);
 
         /// <summary>
         /// Removes the specified values from this list.
@@ -191,6 +191,6 @@ namespace System.Collections.Immutable
         /// <returns>The new list -- even if the value being replaced is equal to the new value for that position.</returns>
         /// <exception cref="ArgumentException">Thrown when the old value does not exist in the list.</exception>
         [Pure]
-        IImmutableList<T> Replace(T oldValue, T newValue, IEqualityComparer<T> equalityComparer);
+        IImmutableList<T> Replace(T oldValue, T newValue, IEqualityComparer<T>? equalityComparer);
     }
 }
index c346077..36bcbe5 100644 (file)
@@ -296,7 +296,7 @@ namespace System.Collections.Immutable
         /// cannot find an implementation of the <see cref="IComparable{T}"/> generic interface
         /// or the <see cref="IComparable"/> interface for type <typeparamref name="T"/>.
         /// </exception>
-        int BinarySearch(T item, IComparer<T> comparer);
+        int BinarySearch(T item, IComparer<T>? comparer);
 
         /// <summary>
         /// Searches a range of elements in the sorted <see cref="IReadOnlyList{T}"/>
@@ -327,6 +327,6 @@ namespace System.Collections.Immutable
         /// cannot find an implementation of the <see cref="IComparable{T}"/> generic interface
         /// or the <see cref="IComparable"/> interface for type <typeparamref name="T"/>.
         /// </exception>
-        int BinarySearch(int index, int count, T item, IComparer<T> comparer);
+        int BinarySearch(int index, int count, T item, IComparer<T>? comparer);
     }
 }
index d112226..af69f23 100644 (file)
@@ -106,7 +106,7 @@ namespace System.Collections.Immutable
             var immutableArray = items as IImmutableArray;
             if (immutableArray != null)
             {
-                Array array = immutableArray.Array;
+                Array? array = immutableArray.Array;
                 if (array == null)
                 {
                     throw new InvalidOperationException(SR.InvalidOperationOnDefaultArray);
@@ -143,7 +143,7 @@ namespace System.Collections.Immutable
         /// <param name="items">The elements to store in the array.</param>
         /// <returns>An immutable array.</returns>
         [Pure]
-        public static ImmutableArray<T> Create<T>(params T[] items)
+        public static ImmutableArray<T> Create<T>(params T[]? items)
         {
             if (items == null)
             {
@@ -217,7 +217,7 @@ namespace System.Collections.Immutable
             }
 
             var array = new T[length];
-            Array.Copy(items.array, start, array, 0, length);
+            Array.Copy(items.array!, start, array, 0, length);
             return new ImmutableArray<T>(array);
         }
 
@@ -432,7 +432,7 @@ namespace System.Collections.Immutable
         [Pure]
         public static int BinarySearch<T>(this ImmutableArray<T> array, T value)
         {
-            return Array.BinarySearch<T>(array.array, value);
+            return Array.BinarySearch<T>(array.array!, value);
         }
 
         /// <summary>
@@ -461,9 +461,9 @@ namespace System.Collections.Immutable
         /// generic interface.
         /// </exception>
         [Pure]
-        public static int BinarySearch<T>(this ImmutableArray<T> array, T value, IComparer<T> comparer)
+        public static int BinarySearch<T>(this ImmutableArray<T> array, T value, IComparer<T>? comparer)
         {
-            return Array.BinarySearch<T>(array.array, value, comparer);
+            return Array.BinarySearch<T>(array.array!, value, comparer);
         }
 
         /// <summary>
@@ -498,7 +498,7 @@ namespace System.Collections.Immutable
         [Pure]
         public static int BinarySearch<T>(this ImmutableArray<T> array, int index, int length, T value)
         {
-            return Array.BinarySearch<T>(array.array, index, length, value);
+            return Array.BinarySearch<T>(array.array!, index, length, value);
         }
 
         /// <summary>
@@ -537,9 +537,9 @@ namespace System.Collections.Immutable
         /// <paramref name="index"/> is less than the lower bound of <paramref name="array"/>. -or- <paramref name="length"/> is less than zero.
         /// </exception>
         [Pure]
-        public static int BinarySearch<T>(this ImmutableArray<T> array, int index, int length, T value, IComparer<T> comparer)
+        public static int BinarySearch<T>(this ImmutableArray<T> array, int index, int length, T value, IComparer<T>? comparer)
         {
-            return Array.BinarySearch<T>(array.array, index, length, value, comparer);
+            return Array.BinarySearch<T>(array.array!, index, length, value, comparer);
         }
 
         /// <summary>
index db94802..ca27188 100644 (file)
@@ -75,7 +75,7 @@ namespace System.Collections.Immutable
                         }
                         else
                         {
-                            _elements = ImmutableArray<T>.Empty.array;
+                            _elements = ImmutableArray<T>.Empty.array!;
                         }
                     }
                 }
@@ -113,7 +113,7 @@ namespace System.Collections.Immutable
                         {
                             for (int i = value; i < this.Count; i++)
                             {
-                                _elements[i] = default(T);
+                                _elements[i] = default(T)!;
                             }
                         }
                     }
@@ -211,7 +211,7 @@ namespace System.Collections.Immutable
                 }
 
                 T[] temp = _elements;
-                _elements = ImmutableArray<T>.Empty.array;
+                _elements = ImmutableArray<T>.Empty.array!;
                 _count = 0;
                 return new ImmutableArray<T>(temp);
             }
@@ -433,7 +433,7 @@ namespace System.Collections.Immutable
             {
                 if (this.Count == 0)
                 {
-                    return Empty.array;
+                    return Empty.array!;
                 }
 
                 T[] result = new T[this.Count];
@@ -516,7 +516,7 @@ namespace System.Collections.Immutable
             /// </param>
             /// <returns>The 0-based index into the array where the item was found; or -1 if it could not be found.</returns>
             [Pure]
-            public int IndexOf(T item, int startIndex, int count, IEqualityComparer<T> equalityComparer)
+            public int IndexOf(T item, int startIndex, int count, IEqualityComparer<T>? equalityComparer)
             {
                 if (count == 0 && startIndex == 0)
                 {
@@ -602,7 +602,7 @@ namespace System.Collections.Immutable
             /// <param name="equalityComparer">The equality comparer to use in the search.</param>
             /// <returns>The 0-based index into the array where the item was found; or -1 if it could not be found.</returns>
             [Pure]
-            public int LastIndexOf(T item, int startIndex, int count, IEqualityComparer<T> equalityComparer)
+            public int LastIndexOf(T item, int startIndex, int count, IEqualityComparer<T>? equalityComparer)
             {
                 if (count == 0 && startIndex == 0)
                 {
@@ -691,7 +691,7 @@ namespace System.Collections.Immutable
             /// Sorts the array.
             /// </summary>
             /// <param name="comparer">The comparer to use in sorting. If <c>null</c>, the default comparer is used.</param>
-            public void Sort(IComparer<T> comparer)
+            public void Sort(IComparer<T>? comparer)
             {
                 if (Count > 1)
                 {
@@ -705,7 +705,7 @@ namespace System.Collections.Immutable
             /// <param name="index">The index of the first element to consider in the sort.</param>
             /// <param name="count">The number of elements to include in the sort.</param>
             /// <param name="comparer">The comparer to use in sorting. If <c>null</c>, the default comparer is used.</param>
-            public void Sort(int index, int count, IComparer<T> comparer)
+            public void Sort(int index, int count, IComparer<T>? comparer)
             {
                 // Don't rely on Array.Sort's argument validation since our internal array may exceed
                 // the bounds of the publicly addressable region.
index 56638d5..98ff82f 100644 (file)
@@ -75,7 +75,7 @@ namespace System.Collections.Immutable
             /// A shareable singleton for enumerating empty arrays.
             /// </summary>
             private static readonly IEnumerator<T> s_EmptyEnumerator =
-                new EnumeratorObject(ImmutableArray<T>.Empty.array);
+                new EnumeratorObject(ImmutableArray<T>.Empty.array!);
 
             /// <summary>
             /// The array being enumerated.
@@ -122,7 +122,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// Gets the currently enumerated value.
             /// </summary>
-            object IEnumerator.Current
+            object? IEnumerator.Current
             {
                 get { return this.Current; }
             }
index 4b59ffc..c134fe0 100644 (file)
@@ -50,14 +50,14 @@ namespace System.Collections.Immutable
         /// This would be private, but we make it internal so that our own extension methods can access it.
         /// </remarks>
         [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
-        internal T[] array;
+        internal T[]? array;
 
         /// <summary>
         /// Initializes a new instance of the <see cref="ImmutableArray{T}"/> struct
         /// *without making a defensive copy*.
         /// </summary>
         /// <param name="items">The array to use. May be null for "default" arrays.</param>
-        internal ImmutableArray(T[] items)
+        internal ImmutableArray(T[]? items)
         {
             this.array = items;
         }
@@ -127,7 +127,7 @@ namespace System.Collections.Immutable
                 // The reason for this is perf.
                 // Length and the indexer must be absolutely trivially implemented for the JIT optimization
                 // of removing array bounds checking to work.
-                return this.array[index];
+                return this.array![index];
             }
         }
 
@@ -144,7 +144,7 @@ namespace System.Collections.Immutable
             // The reason for this is perf.
             // Length and the indexer must be absolutely trivially implemented for the JIT optimization
             // of removing array bounds checking to work.
-            return ref this.array[index];
+            return ref this.array![index];
         }
 #endif
 
@@ -172,7 +172,7 @@ namespace System.Collections.Immutable
                 // The reason for this is perf.
                 // Length and the indexer must be absolutely trivially implemented for the JIT optimization
                 // of removing array bounds checking to work.
-                return this.array.Length;
+                return this.array!.Length;
             }
         }
 
@@ -202,7 +202,7 @@ namespace System.Collections.Immutable
         /// Gets an untyped reference to the array.
         /// </summary>
         [DebuggerBrowsable(DebuggerBrowsableState.Never)]
-        Array IImmutableArray.Array
+        Array? IImmutableArray.Array
         {
             get { return this.array; }
         }
@@ -229,7 +229,7 @@ namespace System.Collections.Immutable
         {
             var self = this;
             self.ThrowNullRefIfNotInitialized();
-            Array.Copy(self.array, 0, destination, 0, self.Length);
+            Array.Copy(self.array!, 0, destination, 0, self.Length);
         }
 
         /// <summary>
@@ -242,7 +242,7 @@ namespace System.Collections.Immutable
         {
             var self = this;
             self.ThrowNullRefIfNotInitialized();
-            Array.Copy(self.array, 0, destination, destinationIndex, self.Length);
+            Array.Copy(self.array!, 0, destination, destinationIndex, self.Length);
         }
 
         /// <summary>
@@ -257,7 +257,7 @@ namespace System.Collections.Immutable
         {
             var self = this;
             self.ThrowNullRefIfNotInitialized();
-            Array.Copy(self.array, sourceIndex, destination, destinationIndex, length);
+            Array.Copy(self.array!, sourceIndex, destination, destinationIndex, length);
         }
 
         /// <summary>
@@ -287,7 +287,7 @@ namespace System.Collections.Immutable
         {
             var self = this;
             self.ThrowNullRefIfNotInitialized();
-            return new Enumerator(self.array);
+            return new Enumerator(self.array!);
         }
 
         /// <summary>
@@ -311,15 +311,9 @@ namespace System.Collections.Immutable
         ///   <c>true</c> if the specified <see cref="object"/> is equal to this instance; otherwise, <c>false</c>.
         /// </returns>
         [Pure]
-        public override bool Equals(object obj)
+        public override bool Equals(object? obj)
         {
-            IImmutableArray other = obj as IImmutableArray;
-            if (other != null)
-            {
-                return this.array == other.Array;
-            }
-
-            return false;
+            return obj is IImmutableArray other && this.array == other.Array;
         }
 
         /// <summary>
@@ -360,7 +354,7 @@ namespace System.Collections.Immutable
         [Pure]
         public ImmutableArray<TOther> CastArray<TOther>() where TOther : class
         {
-            return new ImmutableArray<TOther>((TOther[])(object)array);
+            return new ImmutableArray<TOther>((TOther[])(object)array!);
         }
 
         /// <summary>
@@ -381,7 +375,7 @@ namespace System.Collections.Immutable
         [Pure]
         public ImmutableArray<TOther> As<TOther>() where TOther : class
         {
-            return new ImmutableArray<TOther>(this.array as TOther[]);
+            return new ImmutableArray<TOther>((this.array as TOther[])!);
         }
 
         /// <summary>
@@ -394,7 +388,7 @@ namespace System.Collections.Immutable
         {
             var self = this;
             self.ThrowInvalidOperationIfNotInitialized();
-            return EnumeratorObject.Create(self.array);
+            return EnumeratorObject.Create(self.array!);
         }
 
         /// <summary>
@@ -407,7 +401,7 @@ namespace System.Collections.Immutable
         {
             var self = this;
             self.ThrowInvalidOperationIfNotInitialized();
-            return EnumeratorObject.Create(self.array);
+            return EnumeratorObject.Create(self.array!);
         }
 
         /// <summary>
@@ -423,7 +417,7 @@ namespace System.Collections.Immutable
             // if we are going to do anything with the array, we will need Length anyways
             // so touching it, and potentially causing a cache miss, is not going to be an
             // extra expense.
-            _ = this.array.Length;
+            _ = this.array!.Length;
         }
 
         /// <summary>
index 1805f9b..81f7fe1 100644 (file)
@@ -117,7 +117,7 @@ namespace System.Collections.Immutable
         /// <param name="equalityComparer">The equality comparer to use in the search.</param>
         /// <returns>The 0-based index into the array where the item was found; or -1 if it could not be found.</returns>
         [Pure]
-        public int IndexOf(T item, int startIndex, IEqualityComparer<T> equalityComparer)
+        public int IndexOf(T item, int startIndex, IEqualityComparer<T>? equalityComparer)
         {
             var self = this;
             return self.IndexOf(item, startIndex, self.Length - startIndex, equalityComparer);
@@ -161,7 +161,7 @@ namespace System.Collections.Immutable
         /// </param>
         /// <returns>The 0-based index into the array where the item was found; or -1 if it could not be found.</returns>
         [Pure]
-        public int IndexOf(T item, int startIndex, int count, IEqualityComparer<T> equalityComparer)
+        public int IndexOf(T item, int startIndex, int count, IEqualityComparer<T>? equalityComparer)
         {
             var self = this;
             self.ThrowNullRefIfNotInitialized();
@@ -177,13 +177,13 @@ namespace System.Collections.Immutable
             equalityComparer = equalityComparer ?? EqualityComparer<T>.Default;
             if (equalityComparer == EqualityComparer<T>.Default)
             {
-                return Array.IndexOf(self.array, item, startIndex, count);
+                return Array.IndexOf(self.array!, item, startIndex, count);
             }
             else
             {
                 for (int i = startIndex; i < startIndex + count; i++)
                 {
-                    if (equalityComparer.Equals(self.array[i], item))
+                    if (equalityComparer.Equals(self.array![i], item))
                     {
                         return i;
                     }
@@ -250,7 +250,7 @@ namespace System.Collections.Immutable
         /// <param name="equalityComparer">The equality comparer to use in the search.</param>
         /// <returns>The 0-based index into the array where the item was found; or -1 if it could not be found.</returns>
         [Pure]
-        public int LastIndexOf(T item, int startIndex, int count, IEqualityComparer<T> equalityComparer)
+        public int LastIndexOf(T item, int startIndex, int count, IEqualityComparer<T>? equalityComparer)
         {
             var self = this;
             self.ThrowNullRefIfNotInitialized();
@@ -266,13 +266,13 @@ namespace System.Collections.Immutable
             equalityComparer = equalityComparer ?? EqualityComparer<T>.Default;
             if (equalityComparer == EqualityComparer<T>.Default)
             {
-                return Array.LastIndexOf(self.array, item, startIndex, count);
+                return Array.LastIndexOf(self.array!, item, startIndex, count);
             }
             else
             {
                 for (int i = startIndex; i >= startIndex - count + 1; i--)
                 {
-                    if (equalityComparer.Equals(item, self.array[i]))
+                    if (equalityComparer.Equals(item, self.array![i]))
                     {
                         return i;
                     }
@@ -316,11 +316,11 @@ namespace System.Collections.Immutable
 
             if (index != 0)
             {
-                Array.Copy(self.array, tmp, index);
+                Array.Copy(self.array!, tmp, index);
             }
             if (index != self.Length)
             {
-                Array.Copy(self.array, index, tmp, index + 1, self.Length - index);
+                Array.Copy(self.array!, index, tmp, index + 1, self.Length - index);
             }
 
             return new ImmutableArray<T>(tmp);
@@ -355,11 +355,11 @@ namespace System.Collections.Immutable
 
             if (index != 0)
             {
-                Array.Copy(self.array, tmp, index);
+                Array.Copy(self.array!, tmp, index);
             }
             if (index != self.Length)
             {
-                Array.Copy(self.array, index, tmp, index + count, self.Length - index);
+                Array.Copy(self.array!, index, tmp, index + count, self.Length - index);
             }
 
             // We want to copy over the items we need to insert.
@@ -407,14 +407,14 @@ namespace System.Collections.Immutable
 
             if (index != 0)
             {
-                Array.Copy(self.array, tmp, index);
+                Array.Copy(self.array!, tmp, index);
             }
             if (index != self.Length)
             {
-                Array.Copy(self.array, index, tmp, index + items.Length, self.Length - index);
+                Array.Copy(self.array!, index, tmp, index + items.Length, self.Length - index);
             }
 
-            Array.Copy(items.array, 0, tmp, index, items.Length);
+            Array.Copy(items.array!, 0, tmp, index, items.Length);
 
             return new ImmutableArray<T>(tmp);
         }
@@ -474,7 +474,7 @@ namespace System.Collections.Immutable
             Requires.Range(index >= 0 && index < self.Length, nameof(index));
 
             T[] tmp = new T[self.Length];
-            Array.Copy(self.array, tmp, self.Length);
+            Array.Copy(self.array!, tmp, self.Length);
             tmp[index] = item;
             return new ImmutableArray<T>(tmp);
         }
@@ -504,7 +504,7 @@ namespace System.Collections.Immutable
         /// <returns>The new list -- even if the value being replaced is equal to the new value for that position.</returns>
         /// <exception cref="ArgumentException">Thrown when the old value does not exist in the list.</exception>
         [Pure]
-        public ImmutableArray<T> Replace(T oldValue, T newValue, IEqualityComparer<T> equalityComparer)
+        public ImmutableArray<T> Replace(T oldValue, T newValue, IEqualityComparer<T>? equalityComparer)
         {
             var self = this;
             int index = self.IndexOf(oldValue, 0, self.Length, equalityComparer);
@@ -539,7 +539,7 @@ namespace System.Collections.Immutable
         /// </param>
         /// <returns>The new array.</returns>
         [Pure]
-        public ImmutableArray<T> Remove(T item, IEqualityComparer<T> equalityComparer)
+        public ImmutableArray<T> Remove(T item, IEqualityComparer<T>? equalityComparer)
         {
             var self = this;
             self.ThrowNullRefIfNotInitialized();
@@ -580,8 +580,8 @@ namespace System.Collections.Immutable
             }
 
             T[] tmp = new T[self.Length - length];
-            Array.Copy(self.array, tmp, index);
-            Array.Copy(self.array, index + length, tmp, index, self.Length - index - length);
+            Array.Copy(self.array!, tmp, index);
+            Array.Copy(self.array!, index + length, tmp, index, self.Length - index - length);
             return new ImmutableArray<T>(tmp);
         }
 
@@ -610,7 +610,7 @@ namespace System.Collections.Immutable
         /// A new list with the elements removed.
         /// </returns>
         [Pure]
-        public ImmutableArray<T> RemoveRange(IEnumerable<T> items, IEqualityComparer<T> equalityComparer)
+        public ImmutableArray<T> RemoveRange(IEnumerable<T> items, IEqualityComparer<T>? equalityComparer)
         {
             var self = this;
             self.ThrowNullRefIfNotInitialized();
@@ -654,10 +654,10 @@ namespace System.Collections.Immutable
         /// A new list with the elements removed.
         /// </returns>
         [Pure]
-        public ImmutableArray<T> RemoveRange(ImmutableArray<T> items, IEqualityComparer<T> equalityComparer)
+        public ImmutableArray<T> RemoveRange(ImmutableArray<T> items, IEqualityComparer<T>? equalityComparer)
         {
             var self = this;
-            Requires.NotNull(items.array, nameof(items));
+            Requires.NotNull(items.array!, nameof(items));
 
             if (items.IsEmpty)
             {
@@ -670,7 +670,7 @@ namespace System.Collections.Immutable
             }
             else
             {
-                return self.RemoveRange(items.array, equalityComparer);
+                return self.RemoveRange(items.array!, equalityComparer);
             }
         }
 
@@ -697,8 +697,8 @@ namespace System.Collections.Immutable
                 return self;
             }
 
-            List<int> removeIndices = null;
-            for (int i = 0; i < self.array.Length; i++)
+            List<int>? removeIndices = null;
+            for (int i = 0; i < self.array!.Length; i++)
             {
                 if (match(self.array[i]))
                 {
@@ -758,7 +758,7 @@ namespace System.Collections.Immutable
         /// </summary>
         /// <param name="comparer">The comparer to use in sorting. If <c>null</c>, the default comparer is used.</param>
         [Pure]
-        public ImmutableArray<T> Sort(IComparer<T> comparer)
+        public ImmutableArray<T> Sort(IComparer<T>? comparer)
         {
             var self = this;
             return self.Sort(0, self.Length, comparer);
@@ -771,7 +771,7 @@ namespace System.Collections.Immutable
         /// <param name="count">The number of elements to include in the sort.</param>
         /// <param name="comparer">The comparer to use in sorting. If <c>null</c>, the default comparer is used.</param>
         [Pure]
-        public ImmutableArray<T> Sort(int index, int count, IComparer<T> comparer)
+        public ImmutableArray<T> Sort(int index, int count, IComparer<T>? comparer)
         {
             var self = this;
             self.ThrowNullRefIfNotInitialized();
@@ -790,7 +790,7 @@ namespace System.Collections.Immutable
                 bool outOfOrder = false;
                 for (int i = index + 1; i < index + count; i++)
                 {
-                    if (comparer.Compare(self.array[i - 1], self.array[i]) > 0)
+                    if (comparer.Compare(self.array![i - 1], self.array[i]) > 0)
                     {
                         outOfOrder = true;
                         break;
@@ -800,7 +800,7 @@ namespace System.Collections.Immutable
                 if (outOfOrder)
                 {
                     var tmp = new T[self.Length];
-                    Array.Copy(self.array, tmp, self.Length);
+                    Array.Copy(self.array!, tmp, self.Length);
                     Array.Sort(tmp, index, count, comparer);
                     return new ImmutableArray<T>(tmp);
                 }
@@ -919,7 +919,7 @@ namespace System.Collections.Immutable
         /// See <see cref="IImmutableList{T}"/>
         /// </summary>
         [ExcludeFromCodeCoverage]
-        IImmutableList<T> IImmutableList<T>.Remove(T value, IEqualityComparer<T> equalityComparer)
+        IImmutableList<T> IImmutableList<T>.Remove(T value, IEqualityComparer<T>? equalityComparer)
         {
             var self = this;
             self.ThrowInvalidOperationIfNotInitialized();
@@ -941,7 +941,7 @@ namespace System.Collections.Immutable
         /// See <see cref="IImmutableList{T}"/>
         /// </summary>
         [ExcludeFromCodeCoverage]
-        IImmutableList<T> IImmutableList<T>.RemoveRange(IEnumerable<T> items, IEqualityComparer<T> equalityComparer)
+        IImmutableList<T> IImmutableList<T>.RemoveRange(IEnumerable<T> items, IEqualityComparer<T>? equalityComparer)
         {
             var self = this;
             self.ThrowInvalidOperationIfNotInitialized();
@@ -984,7 +984,7 @@ namespace System.Collections.Immutable
         /// <summary>
         /// See <see cref="IImmutableList{T}"/>
         /// </summary>
-        IImmutableList<T> IImmutableList<T>.Replace(T oldValue, T newValue, IEqualityComparer<T> equalityComparer)
+        IImmutableList<T> IImmutableList<T>.Replace(T oldValue, T newValue, IEqualityComparer<T>? equalityComparer)
         {
             var self = this;
             self.ThrowInvalidOperationIfNotInitialized();
@@ -1000,7 +1000,7 @@ namespace System.Collections.Immutable
         /// </returns>
         /// <exception cref="System.NotSupportedException"></exception>
         [ExcludeFromCodeCoverage]
-        int IList.Add(object value)
+        int IList.Add(object? value)
         {
             throw new NotSupportedException();
         }
@@ -1023,11 +1023,11 @@ namespace System.Collections.Immutable
         /// true if the <see cref="object"/> is found in the <see cref="IList"/>; otherwise, false.
         /// </returns>
         [ExcludeFromCodeCoverage]
-        bool IList.Contains(object value)
+        bool IList.Contains(object? value)
         {
             var self = this;
             self.ThrowInvalidOperationIfNotInitialized();
-            return self.Contains((T)value);
+            return self.Contains((T)value!);
         }
 
         /// <summary>
@@ -1038,11 +1038,11 @@ namespace System.Collections.Immutable
         /// The index of <paramref name="value"/> if found in the list; otherwise, -1.
         /// </returns>
         [ExcludeFromCodeCoverage]
-        int IList.IndexOf(object value)
+        int IList.IndexOf(object? value)
         {
             var self = this;
             self.ThrowInvalidOperationIfNotInitialized();
-            return self.IndexOf((T)value);
+            return self.IndexOf((T)value!);
         }
 
         /// <summary>
@@ -1052,7 +1052,7 @@ namespace System.Collections.Immutable
         /// <param name="value">The object to insert into the <see cref="IList"/>.</param>
         /// <exception cref="System.NotSupportedException"></exception>
         [ExcludeFromCodeCoverage]
-        void IList.Insert(int index, object value)
+        void IList.Insert(int index, object? value)
         {
             throw new NotSupportedException();
         }
@@ -1129,7 +1129,7 @@ namespace System.Collections.Immutable
         /// <param name="value">The object to remove from the <see cref="IList"/>.</param>
         /// <exception cref="System.NotSupportedException"></exception>
         [ExcludeFromCodeCoverage]
-        void IList.Remove(object value)
+        void IList.Remove(object? value)
         {
             throw new NotSupportedException();
         }
@@ -1156,7 +1156,7 @@ namespace System.Collections.Immutable
         /// <exception cref="NotSupportedException">Always thrown from the setter.</exception>
         /// <exception cref="InvalidOperationException">Thrown if the <see cref="IsDefault"/> property returns true.</exception>
         [ExcludeFromCodeCoverage]
-        object IList.this[int index]
+        object? IList.this[int index]
         {
             get
             {
@@ -1177,7 +1177,7 @@ namespace System.Collections.Immutable
         {
             var self = this;
             self.ThrowInvalidOperationIfNotInitialized();
-            Array.Copy(self.array, 0, array, index, self.Length);
+            Array.Copy(self.array!, 0, array, index, self.Length);
         }
 
         /// <summary>
@@ -1186,14 +1186,13 @@ namespace System.Collections.Immutable
         /// <param name="other">The object to compare with the current instance.</param>
         /// <param name="comparer">An object that determines whether the current instance and other are equal.</param>
         /// <returns>true if the two objects are equal; otherwise, false.</returns>
-        bool IStructuralEquatable.Equals(object other, IEqualityComparer comparer)
+        bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer)
         {
             var self = this;
-            Array otherArray = other as Array;
+            Array? otherArray = other as Array;
             if (otherArray == null)
             {
-                var theirs = other as IImmutableArray;
-                if (theirs != null)
+                if (other is IImmutableArray theirs)
                 {
                     otherArray = theirs.Array;
 
@@ -1208,7 +1207,7 @@ namespace System.Collections.Immutable
                 }
             }
 
-            IStructuralEquatable ours = self.array;
+            IStructuralEquatable ours = self.array!;
             return ours.Equals(otherArray, comparer);
         }
 
@@ -1220,7 +1219,7 @@ namespace System.Collections.Immutable
         int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
         {
             var self = this;
-            IStructuralEquatable ours = self.array;
+            IStructuralEquatable? ours = self.array;
             return ours != null ? ours.GetHashCode(comparer) : self.GetHashCode();
         }
 
@@ -1237,14 +1236,13 @@ namespace System.Collections.Immutable
         /// An integer that indicates the relationship of the current collection object
         /// to other.
         /// </returns>
-        int IStructuralComparable.CompareTo(object other, IComparer comparer)
+        int IStructuralComparable.CompareTo(object? other, IComparer comparer)
         {
             var self = this;
-            Array otherArray = other as Array;
+            Array? otherArray = other as Array;
             if (otherArray == null)
             {
-                var theirs = other as IImmutableArray;
-                if (theirs != null)
+                if (other is IImmutableArray theirs)
                 {
                     otherArray = theirs.Array;
 
@@ -1261,7 +1259,7 @@ namespace System.Collections.Immutable
 
             if (otherArray != null)
             {
-                IStructuralComparable ours = self.array;
+                IStructuralComparable? ours = self.array;
                 if (ours == null)
                 {
                     throw new ArgumentException(SR.ArrayInitializedStateNotEqual, nameof(other));
@@ -1301,13 +1299,13 @@ namespace System.Collections.Immutable
             {
                 int copyLength = lastIndexRemoved == -1 ? indexToRemove : (indexToRemove - lastIndexRemoved - 1);
                 Debug.Assert(indexToRemove > lastIndexRemoved); // We require that the input be a sorted set.
-                Array.Copy(self.array, copied + removed, newArray, copied, copyLength);
+                Array.Copy(self.array!, copied + removed, newArray, copied, copyLength);
                 removed++;
                 copied += copyLength;
                 lastIndexRemoved = indexToRemove;
             }
 
-            Array.Copy(self.array, copied + removed, newArray, copied, self.Length - (copied + removed));
+            Array.Copy(self.array!, copied + removed, newArray, copied, self.Length - (copied + removed));
 
             return new ImmutableArray<T>(newArray);
         }
index eb7f117..c6d8239 100644 (file)
@@ -22,7 +22,7 @@ namespace System.Collections.Immutable
         /// <typeparam name="TValue">The type of values stored by the dictionary.</typeparam>
         /// <returns>The immutable collection.</returns>
         [Pure]
-        public static ImmutableDictionary<TKey, TValue> Create<TKey, TValue>()
+        public static ImmutableDictionary<TKey, TValue> Create<TKey, TValue>() where TKey : notnull
         {
             return ImmutableDictionary<TKey, TValue>.Empty;
         }
@@ -37,7 +37,7 @@ namespace System.Collections.Immutable
         /// The immutable collection.
         /// </returns>
         [Pure]
-        public static ImmutableDictionary<TKey, TValue> Create<TKey, TValue>(IEqualityComparer<TKey> keyComparer)
+        public static ImmutableDictionary<TKey, TValue> Create<TKey, TValue>(IEqualityComparer<TKey>? keyComparer) where TKey : notnull
         {
             return ImmutableDictionary<TKey, TValue>.Empty.WithComparers(keyComparer);
         }
@@ -53,7 +53,7 @@ namespace System.Collections.Immutable
         /// The immutable collection.
         /// </returns>
         [Pure]
-        public static ImmutableDictionary<TKey, TValue> Create<TKey, TValue>(IEqualityComparer<TKey> keyComparer, IEqualityComparer<TValue> valueComparer)
+        public static ImmutableDictionary<TKey, TValue> Create<TKey, TValue>(IEqualityComparer<TKey>? keyComparer, IEqualityComparer<TValue>? valueComparer) where TKey : notnull
         {
             return ImmutableDictionary<TKey, TValue>.Empty.WithComparers(keyComparer, valueComparer);
         }
@@ -67,7 +67,7 @@ namespace System.Collections.Immutable
         /// <returns>The new immutable collection.</returns>
         [Pure]
         [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
-        public static ImmutableDictionary<TKey, TValue> CreateRange<TKey, TValue>(IEnumerable<KeyValuePair<TKey, TValue>> items)
+        public static ImmutableDictionary<TKey, TValue> CreateRange<TKey, TValue>(IEnumerable<KeyValuePair<TKey, TValue>> items) where TKey : notnull
         {
             return ImmutableDictionary<TKey, TValue>.Empty.AddRange(items);
         }
@@ -82,7 +82,7 @@ namespace System.Collections.Immutable
         /// <returns>The new immutable collection.</returns>
         [Pure]
         [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
-        public static ImmutableDictionary<TKey, TValue> CreateRange<TKey, TValue>(IEqualityComparer<TKey> keyComparer, IEnumerable<KeyValuePair<TKey, TValue>> items)
+        public static ImmutableDictionary<TKey, TValue> CreateRange<TKey, TValue>(IEqualityComparer<TKey>? keyComparer, IEnumerable<KeyValuePair<TKey, TValue>> items) where TKey : notnull
         {
             return ImmutableDictionary<TKey, TValue>.Empty.WithComparers(keyComparer).AddRange(items);
         }
@@ -98,7 +98,7 @@ namespace System.Collections.Immutable
         /// <returns>The new immutable collection.</returns>
         [Pure]
         [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
-        public static ImmutableDictionary<TKey, TValue> CreateRange<TKey, TValue>(IEqualityComparer<TKey> keyComparer, IEqualityComparer<TValue> valueComparer, IEnumerable<KeyValuePair<TKey, TValue>> items)
+        public static ImmutableDictionary<TKey, TValue> CreateRange<TKey, TValue>(IEqualityComparer<TKey>? keyComparer, IEqualityComparer<TValue>? valueComparer, IEnumerable<KeyValuePair<TKey, TValue>> items) where TKey : notnull
         {
             return ImmutableDictionary<TKey, TValue>.Empty.WithComparers(keyComparer, valueComparer).AddRange(items);
         }
@@ -110,7 +110,7 @@ namespace System.Collections.Immutable
         /// <typeparam name="TValue">The type of values stored by the dictionary.</typeparam>
         /// <returns>The new builder.</returns>
         [Pure]
-        public static ImmutableDictionary<TKey, TValue>.Builder CreateBuilder<TKey, TValue>()
+        public static ImmutableDictionary<TKey, TValue>.Builder CreateBuilder<TKey, TValue>() where TKey : notnull
         {
             return Create<TKey, TValue>().ToBuilder();
         }
@@ -123,7 +123,7 @@ namespace System.Collections.Immutable
         /// <param name="keyComparer">The key comparer.</param>
         /// <returns>The new builder.</returns>
         [Pure]
-        public static ImmutableDictionary<TKey, TValue>.Builder CreateBuilder<TKey, TValue>(IEqualityComparer<TKey> keyComparer)
+        public static ImmutableDictionary<TKey, TValue>.Builder CreateBuilder<TKey, TValue>(IEqualityComparer<TKey>? keyComparer) where TKey : notnull
         {
             return Create<TKey, TValue>(keyComparer).ToBuilder();
         }
@@ -137,7 +137,7 @@ namespace System.Collections.Immutable
         /// <param name="valueComparer">The value comparer.</param>
         /// <returns>The new builder.</returns>
         [Pure]
-        public static ImmutableDictionary<TKey, TValue>.Builder CreateBuilder<TKey, TValue>(IEqualityComparer<TKey> keyComparer, IEqualityComparer<TValue> valueComparer)
+        public static ImmutableDictionary<TKey, TValue>.Builder CreateBuilder<TKey, TValue>(IEqualityComparer<TKey>? keyComparer, IEqualityComparer<TValue>? valueComparer) where TKey : notnull
         {
             return Create<TKey, TValue>(keyComparer, valueComparer).ToBuilder();
         }
@@ -155,7 +155,7 @@ namespace System.Collections.Immutable
         /// <param name="valueComparer">The value comparer to use for the map.</param>
         /// <returns>The immutable map.</returns>
         [Pure]
-        public static ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TSource, TKey, TValue>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TValue> elementSelector, IEqualityComparer<TKey> keyComparer, IEqualityComparer<TValue> valueComparer)
+        public static ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TSource, TKey, TValue>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TValue> elementSelector, IEqualityComparer<TKey>? keyComparer, IEqualityComparer<TValue>? valueComparer) where TKey : notnull
         {
             Requires.NotNull(source, nameof(source));
             Requires.NotNull(keySelector, nameof(keySelector));
@@ -171,7 +171,7 @@ namespace System.Collections.Immutable
         /// <param name="builder">The builder to create the immutable dictionary from.</param>
         /// <returns>An immutable dictionary.</returns>
         [Pure]
-        public static ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TKey, TValue>(this ImmutableDictionary<TKey, TValue>.Builder builder)
+        public static ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TKey, TValue>(this ImmutableDictionary<TKey, TValue>.Builder builder) where TKey : notnull
         {
             Requires.NotNull(builder, nameof(builder));
 
@@ -190,7 +190,7 @@ namespace System.Collections.Immutable
         /// <param name="keyComparer">The key comparer to use for the map.</param>
         /// <returns>The immutable map.</returns>
         [Pure]
-        public static ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TSource, TKey, TValue>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TValue> elementSelector, IEqualityComparer<TKey> keyComparer)
+        public static ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TSource, TKey, TValue>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TValue> elementSelector, IEqualityComparer<TKey>? keyComparer) where TKey : notnull
         {
             return ToImmutableDictionary(source, keySelector, elementSelector, keyComparer, null);
         }
@@ -204,7 +204,7 @@ namespace System.Collections.Immutable
         /// <param name="keySelector">The function that will produce the key for the map from each sequence element.</param>
         /// <returns>The immutable map.</returns>
         [Pure]
-        public static ImmutableDictionary<TKey, TSource> ToImmutableDictionary<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
+        public static ImmutableDictionary<TKey, TSource> ToImmutableDictionary<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) where TKey : notnull
         {
             return ToImmutableDictionary(source, keySelector, v => v, null, null);
         }
@@ -219,7 +219,7 @@ namespace System.Collections.Immutable
         /// <param name="keyComparer">The key comparer to use for the map.</param>
         /// <returns>The immutable map.</returns>
         [Pure]
-        public static ImmutableDictionary<TKey, TSource> ToImmutableDictionary<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> keyComparer)
+        public static ImmutableDictionary<TKey, TSource> ToImmutableDictionary<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? keyComparer) where TKey : notnull
         {
             return ToImmutableDictionary(source, keySelector, v => v, keyComparer, null);
         }
@@ -235,7 +235,7 @@ namespace System.Collections.Immutable
         /// <param name="elementSelector">The function that will produce the value for the map from each sequence element.</param>
         /// <returns>The immutable map.</returns>
         [Pure]
-        public static ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TSource, TKey, TValue>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TValue> elementSelector)
+        public static ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TSource, TKey, TValue>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TValue> elementSelector) where TKey : notnull
         {
             return ToImmutableDictionary(source, keySelector, elementSelector, null, null);
         }
@@ -251,7 +251,7 @@ namespace System.Collections.Immutable
         /// <returns>An immutable map.</returns>
         [Pure]
         [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
-        public static ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source, IEqualityComparer<TKey> keyComparer, IEqualityComparer<TValue> valueComparer)
+        public static ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source, IEqualityComparer<TKey>? keyComparer, IEqualityComparer<TValue>? valueComparer) where TKey : notnull
         {
             Requires.NotNull(source, nameof(source));
 
@@ -274,7 +274,7 @@ namespace System.Collections.Immutable
         /// <returns>An immutable map.</returns>
         [Pure]
         [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
-        public static ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source, IEqualityComparer<TKey> keyComparer)
+        public static ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source, IEqualityComparer<TKey>? keyComparer) where TKey : notnull
         {
             return ToImmutableDictionary(source, keyComparer, null);
         }
@@ -288,7 +288,7 @@ namespace System.Collections.Immutable
         /// <returns>An immutable map.</returns>
         [Pure]
         [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
-        public static ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source)
+        public static ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source) where TKey : notnull
         {
             return ToImmutableDictionary(source, null, null);
         }
@@ -305,7 +305,7 @@ namespace System.Collections.Immutable
         ///   <c>true</c> if this map contains the key-value pair; otherwise, <c>false</c>.
         /// </returns>
         [Pure]
-        public static bool Contains<TKey, TValue>(this IImmutableDictionary<TKey, TValue> map, TKey key, TValue value)
+        public static bool Contains<TKey, TValue>(this IImmutableDictionary<TKey, TValue> map, TKey key, TValue value) where TKey : notnull
         {
             Requires.NotNull(map, nameof(map));
             Requires.NotNullAllowStructs(key, nameof(key));
@@ -319,9 +319,10 @@ namespace System.Collections.Immutable
         /// <param name="key">The key to search for.</param>
         /// <returns>The value for the key, or the default value of type <typeparamref name="TValue"/> if no matching key was found.</returns>
         [Pure]
-        public static TValue GetValueOrDefault<TKey, TValue>(this IImmutableDictionary<TKey, TValue> dictionary, TKey key)
+        [return: MaybeNull]
+        public static TValue GetValueOrDefault<TKey, TValue>(this IImmutableDictionary<TKey, TValue> dictionary, TKey key) where TKey : notnull
         {
-            return GetValueOrDefault(dictionary, key, default(TValue));
+            return GetValueOrDefault(dictionary, key, default(TValue)!);
         }
 
         /// <summary>
@@ -336,13 +337,13 @@ namespace System.Collections.Immutable
         /// The value for the key, or <paramref name="defaultValue"/> if no matching key was found.
         /// </returns>
         [Pure]
-        public static TValue GetValueOrDefault<TKey, TValue>(this IImmutableDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue)
+        public static TValue GetValueOrDefault<TKey, TValue>(this IImmutableDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue) where TKey : notnull
         {
             Requires.NotNull(dictionary, nameof(dictionary));
             Requires.NotNullAllowStructs(key, nameof(key));
 
             TValue value;
-            if (dictionary.TryGetValue(key, out value))
+            if (dictionary.TryGetValue(key, out value!))
             {
                 return value;
             }
index 8bdbde1..11717ea 100644 (file)
@@ -54,7 +54,7 @@ namespace System.Collections.Immutable
             /// Caches an immutable instance that represents the current state of the collection.
             /// </summary>
             /// <value>Null if no immutable view has been created for the current version.</value>
-            private ImmutableDictionary<TKey, TValue> _immutable;
+            private ImmutableDictionary<TKey, TValue>? _immutable;
 
             /// <summary>
             /// A number that increments every time the builder changes its contents.
@@ -64,7 +64,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// The object callers may use to synchronize access to this collection.
             /// </summary>
-            private object _syncRoot;
+            private object? _syncRoot;
 
             /// <summary>
             /// Initializes a new instance of the <see cref="ImmutableDictionary{TKey, TValue}.Builder"/> class.
@@ -262,7 +262,7 @@ namespace System.Collections.Immutable
                 {
                     if (_syncRoot == null)
                     {
-                        Threading.Interlocked.CompareExchange<object>(ref _syncRoot, new object(), null);
+                        Threading.Interlocked.CompareExchange<object?>(ref _syncRoot, new object(), null);
                     }
 
                     return _syncRoot;
@@ -288,9 +288,9 @@ namespace System.Collections.Immutable
             /// </summary>
             /// <param name="key">The <see cref="object"/> to use as the key of the element to add.</param>
             /// <param name="value">The <see cref="object"/> to use as the value of the element to add.</param>
-            void IDictionary.Add(object key, object value)
+            void IDictionary.Add(object key, object? value)
             {
-                this.Add((TKey)key, (TValue)value);
+                this.Add((TKey)key, (TValue)value!);
             }
 
             /// <summary>
@@ -330,10 +330,10 @@ namespace System.Collections.Immutable
             /// </summary>
             /// <param name="key">The key.</param>
             /// <returns></returns>
-            object IDictionary.this[object key]
+            object? IDictionary.this[object key]
             {
                 get { return this[(TKey)key]; }
-                set { this[(TKey)key] = (TValue)value; }
+                set { this[(TKey)key] = (TValue)value!; }
             }
 
             #endregion
@@ -414,7 +414,7 @@ namespace System.Collections.Immutable
                 get
                 {
                     TValue value;
-                    if (this.TryGetValue(key, out value))
+                    if (this.TryGetValue(key, out value!))
                     {
                         return value;
                     }
@@ -473,9 +473,10 @@ namespace System.Collections.Immutable
             /// <param name="key">The key to search for.</param>
             /// <returns>The value for the key, or the default value of type <typeparamref name="TValue"/> if no matching key was found.</returns>
             [Pure]
+            [return: MaybeNull]
             public TValue GetValueOrDefault(TKey key)
             {
-                return this.GetValueOrDefault(key, default(TValue));
+                return this.GetValueOrDefault(key, default(TValue)!);
             }
 
             /// <summary>
@@ -492,7 +493,7 @@ namespace System.Collections.Immutable
                 Requires.NotNullAllowStructs(key, nameof(key));
 
                 TValue value;
-                if (this.TryGetValue(key, out value))
+                if (this.TryGetValue(key, out value!))
                 {
                     return value;
                 }
@@ -602,9 +603,9 @@ namespace System.Collections.Immutable
             /// true if the object that implements <see cref="IDictionary{TKey, TValue}"/> contains an element with the specified key; otherwise, false.
             /// </returns>
             /// <exception cref="ArgumentNullException"><paramref name="key"/> is null.</exception>
-            public bool TryGetValue(TKey key, out TValue value)
+            public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
             {
-                return ImmutableDictionary<TKey, TValue>.TryGetValue(key, this.Origin, out value);
+                return ImmutableDictionary<TKey, TValue>.TryGetValue(key, this.Origin, out value!);
             }
 
             /// <summary>
@@ -727,7 +728,7 @@ namespace System.Collections.Immutable
     /// <summary>
     /// A simple view of the immutable collection that the debugger can show to the developer.
     /// </summary>
-    internal class ImmutableDictionaryBuilderDebuggerProxy<TKey, TValue>
+    internal class ImmutableDictionaryBuilderDebuggerProxy<TKey, TValue> where TKey : notnull
     {
         /// <summary>
         /// The collection to be enumerated.
@@ -737,7 +738,7 @@ namespace System.Collections.Immutable
         /// <summary>
         /// The simple view of the collection.
         /// </summary>
-        private KeyValuePair<TKey, TValue>[] _contents;
+        private KeyValuePair<TKey, TValue>[]? _contents;
 
         /// <summary>
         /// Initializes a new instance of the <see cref="ImmutableDictionaryBuilderDebuggerProxy{TKey, TValue}"/> class.
index 8ebdcbc..b73d2a8 100644 (file)
@@ -19,7 +19,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// The builder being enumerated, if applicable.
             /// </summary>
-            private readonly Builder _builder;
+            private readonly Builder? _builder;
 
             /// <summary>
             /// The enumerator over the sorted dictionary whose keys are hash values.
@@ -41,7 +41,7 @@ namespace System.Collections.Immutable
             /// </summary>
             /// <param name="root">The root.</param>
             /// <param name="builder">The builder, if applicable.</param>
-            internal Enumerator(SortedInt32KeyNode<HashBucket> root, Builder builder = null)
+            internal Enumerator(SortedInt32KeyNode<HashBucket> root, Builder? builder = null)
             {
                 _builder = builder;
                 _mapEnumerator = new SortedInt32KeyNode<HashBucket>.Enumerator(root);
index e5603ec..9e7a1dc 100644 (file)
@@ -3,6 +3,7 @@
 // See the LICENSE file in the project root for more information.
 
 using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
 using System.Globalization;
 
 namespace System.Collections.Immutable
@@ -36,7 +37,7 @@ namespace System.Collections.Immutable
             /// </summary>
             /// <param name="firstElement">The first element.</param>
             /// <param name="additionalElements">The additional elements.</param>
-            private HashBucket(KeyValuePair<TKey, TValue> firstElement, ImmutableList<KeyValuePair<TKey, TValue>>.Node additionalElements = null)
+            private HashBucket(KeyValuePair<TKey, TValue> firstElement, ImmutableList<KeyValuePair<TKey, TValue>>.Node? additionalElements = null)
             {
                 _firstValue = firstElement;
                 _additionalElements = additionalElements ?? ImmutableList<KeyValuePair<TKey, TValue>>.Node.EmptyNode;
@@ -110,7 +111,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// Throws an exception to catch any errors in comparing <see cref="HashBucket"/> instances.
             /// </summary>
-            public override bool Equals(object obj)
+            public override bool Equals(object? obj)
             {
                 // This should never be called, as hash buckets don't know how to equate themselves.
                 throw new NotSupportedException();
@@ -221,7 +222,7 @@ namespace System.Collections.Immutable
                     return this;
                 }
 
-                var kv = new KeyValuePair<TKey, TValue>(key, default(TValue));
+                var kv = new KeyValuePair<TKey, TValue>(key, default(TValue)!);
                 if (keyOnlyComparer.Equals(_firstValue, kv))
                 {
                     if (_additionalElements.IsEmpty)
@@ -233,7 +234,7 @@ namespace System.Collections.Immutable
                     {
                         // We can promote any element from the list into the first position, but it's most efficient
                         // to remove the root node in the binary tree that implements the list.
-                        int indexOfRootNode = _additionalElements.Left.Count;
+                        int indexOfRootNode = _additionalElements.Left!.Count;
                         result = OperationResult.SizeChanged;
                         return new HashBucket(_additionalElements.Key, _additionalElements.RemoveAt(indexOfRootNode));
                     }
@@ -259,11 +260,11 @@ namespace System.Collections.Immutable
             /// <param name="comparers">The comparers.</param>
             /// <param name="value">The value for the given key.</param>
             /// <returns>A value indicating whether the key was found.</returns>
-            internal bool TryGetValue(TKey key, Comparers comparers, out TValue value)
+            internal bool TryGetValue(TKey key, Comparers comparers, [MaybeNullWhen(false)] out TValue value)
             {
                 if (this.IsEmpty)
                 {
-                    value = default(TValue);
+                    value = default(TValue)!;
                     return false;
                 }
 
@@ -273,11 +274,11 @@ namespace System.Collections.Immutable
                     return true;
                 }
 
-                var kv = new KeyValuePair<TKey, TValue>(key, default(TValue));
+                var kv = new KeyValuePair<TKey, TValue>(key, default(TValue)!);
                 var index = _additionalElements.IndexOf(kv, comparers.KeyOnlyComparer);
                 if (index < 0)
                 {
-                    value = default(TValue);
+                    value = default(TValue)!;
                     return false;
                 }
 
@@ -316,7 +317,7 @@ namespace System.Collections.Immutable
                     return true;
                 }
 
-                var kv = new KeyValuePair<TKey, TValue>(equalKey, default(TValue));
+                var kv = new KeyValuePair<TKey, TValue>(equalKey, default(TValue)!);
                 var index = _additionalElements.IndexOf(kv, comparers.KeyOnlyComparer);
                 if (index < 0)
                 {
index 4432350..d921380 100644 (file)
@@ -17,7 +17,7 @@ namespace System.Collections.Immutable
     /// <typeparam name="TValue">The type of the value.</typeparam>
     [DebuggerDisplay("Count = {Count}")]
     [DebuggerTypeProxy(typeof(ImmutableDictionaryDebuggerProxy<,>))]
-    public sealed partial class ImmutableDictionary<TKey, TValue> : IImmutableDictionary<TKey, TValue>, IImmutableDictionaryInternal<TKey, TValue>, IHashKeyCollection<TKey>, IDictionary<TKey, TValue>, IDictionary
+    public sealed partial class ImmutableDictionary<TKey, TValue> : IImmutableDictionary<TKey, TValue>, IImmutableDictionaryInternal<TKey, TValue>, IHashKeyCollection<TKey>, IDictionary<TKey, TValue>, IDictionary where TKey: notnull
     {
         /// <summary>
         /// An empty immutable dictionary with default equality comparers.
@@ -65,7 +65,7 @@ namespace System.Collections.Immutable
         /// Initializes a new instance of the <see cref="ImmutableDictionary{TKey, TValue}"/> class.
         /// </summary>
         /// <param name="comparers">The comparers.</param>
-        private ImmutableDictionary(Comparers comparers = null)
+        private ImmutableDictionary(Comparers? comparers = null)
         {
             _comparers = comparers ?? Comparers.Get(EqualityComparer<TKey>.Default, EqualityComparer<TValue>.Default);
             _root = SortedInt32KeyNode<HashBucket>.EmptyNode;
@@ -250,7 +250,7 @@ namespace System.Collections.Immutable
                 Requires.NotNullAllowStructs(key, nameof(key));
 
                 TValue value;
-                if (this.TryGetValue(key, out value))
+                if (this.TryGetValue(key, out value!))
                 {
                     return value;
                 }
@@ -417,10 +417,10 @@ namespace System.Collections.Immutable
         /// <summary>
         /// See the <see cref="IImmutableDictionary{TKey, TValue}"/> interface.
         /// </summary>
-        public bool TryGetValue(TKey key, out TValue value)
+        public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
         {
             Requires.NotNullAllowStructs(key, nameof(key));
-            return TryGetValue(key, this.Origin, out value);
+            return TryGetValue(key, this.Origin, out value!);
         }
 
         /// <summary>
@@ -436,7 +436,7 @@ namespace System.Collections.Immutable
         /// See the <see cref="IImmutableDictionary{TKey, TValue}"/> interface.
         /// </summary>
         [Pure]
-        public ImmutableDictionary<TKey, TValue> WithComparers(IEqualityComparer<TKey> keyComparer, IEqualityComparer<TValue> valueComparer)
+        public ImmutableDictionary<TKey, TValue> WithComparers(IEqualityComparer<TKey>? keyComparer, IEqualityComparer<TValue>? valueComparer)
         {
             if (keyComparer == null)
             {
@@ -476,7 +476,7 @@ namespace System.Collections.Immutable
         /// See the <see cref="IImmutableDictionary{TKey, TValue}"/> interface.
         /// </summary>
         [Pure]
-        public ImmutableDictionary<TKey, TValue> WithComparers(IEqualityComparer<TKey> keyComparer)
+        public ImmutableDictionary<TKey, TValue> WithComparers(IEqualityComparer<TKey>? keyComparer)
         {
             return this.WithComparers(keyComparer, _comparers.ValueComparer);
         }
@@ -708,7 +708,7 @@ namespace System.Collections.Immutable
         /// </summary>
         /// <param name="key">The <see cref="object"/> to use as the key of the element to add.</param>
         /// <param name="value">The <see cref="object"/> to use as the value of the element to add.</param>
-        void IDictionary.Add(object key, object value)
+        void IDictionary.Add(object key, object? value)
         {
             throw new NotSupportedException();
         }
@@ -750,7 +750,7 @@ namespace System.Collections.Immutable
         /// </summary>
         /// <param name="key">The key.</param>
         /// <returns></returns>
-        object IDictionary.this[object key]
+        object? IDictionary.this[object key]
         {
             get { return this[(TKey)key]; }
             set { throw new NotSupportedException(); }
@@ -871,7 +871,7 @@ namespace System.Collections.Immutable
         /// <param name="sequence">The sequence that may have come from an immutable map.</param>
         /// <param name="other">Receives the concrete <see cref="ImmutableDictionary{TKey, TValue}"/> typed value if one can be found.</param>
         /// <returns><c>true</c> if the cast was successful; <c>false</c> otherwise.</returns>
-        private static bool TryCastToImmutableMap(IEnumerable<KeyValuePair<TKey, TValue>> sequence, out ImmutableDictionary<TKey, TValue> other)
+        private static bool TryCastToImmutableMap(IEnumerable<KeyValuePair<TKey, TValue>> sequence, [NotNullWhen(true)] out ImmutableDictionary<TKey, TValue>? other)
         {
             other = sequence as ImmutableDictionary<TKey, TValue>;
             if (other != null)
@@ -879,8 +879,7 @@ namespace System.Collections.Immutable
                 return true;
             }
 
-            var builder = sequence as Builder;
-            if (builder != null)
+            if (sequence is Builder builder)
             {
                 other = builder.ToImmutable();
                 return true;
@@ -901,7 +900,7 @@ namespace System.Collections.Immutable
             if (origin.Root.TryGetValue(hashCode, out bucket))
             {
                 TValue value;
-                return bucket.TryGetValue(key, origin.Comparers, out value);
+                return bucket.TryGetValue(key, origin.Comparers, out value!);
             }
 
             return false;
@@ -917,7 +916,7 @@ namespace System.Collections.Immutable
             if (origin.Root.TryGetValue(hashCode, out bucket))
             {
                 TValue value;
-                return bucket.TryGetValue(keyValuePair.Key, origin.Comparers, out value)
+                return bucket.TryGetValue(keyValuePair.Key, origin.Comparers, out value!)
                     && origin.ValueComparer.Equals(value, keyValuePair.Value);
             }
 
@@ -927,16 +926,16 @@ namespace System.Collections.Immutable
         /// <summary>
         /// Performs the operation on a given data structure.
         /// </summary>
-        private static bool TryGetValue(TKey key, MutationInput origin, out TValue value)
+        private static bool TryGetValue(TKey key, MutationInput origin, [MaybeNullWhen(false)] out TValue value)
         {
             int hashCode = origin.KeyComparer.GetHashCode(key);
             HashBucket bucket;
             if (origin.Root.TryGetValue(hashCode, out bucket))
             {
-                return bucket.TryGetValue(key, origin.Comparers, out value);
+                return bucket.TryGetValue(key, origin.Comparers, out value!);
             }
 
-            value = default(TValue);
+            value = default(TValue)!;
             return false;
         }
 
@@ -1060,7 +1059,7 @@ namespace System.Collections.Immutable
         /// <param name="root">The root of the data structure.</param>
         /// <param name="adjustedCountIfDifferentRoot">The adjusted count if the root has changed.</param>
         /// <returns>The immutable collection.</returns>
-        private ImmutableDictionary<TKey, TValue> Wrap(SortedInt32KeyNode<HashBucket> root, int adjustedCountIfDifferentRoot)
+        private ImmutableDictionary<TKey, TValue> Wrap(SortedInt32KeyNode<HashBucket>? root, int adjustedCountIfDifferentRoot)
         {
             if (root == null)
             {
@@ -1090,8 +1089,7 @@ namespace System.Collections.Immutable
             {
                 // If the items being added actually come from an ImmutableDictionary<TKey, TValue>
                 // then there is no value in reconstructing it.
-                ImmutableDictionary<TKey, TValue> other;
-                if (TryCastToImmutableMap(pairs, out other))
+                if (TryCastToImmutableMap(pairs, out ImmutableDictionary<TKey, TValue>? other))
                 {
                     return other.WithComparers(this.KeyComparer, this.ValueComparer);
                 }
index ccfccde..a1eaa52 100644 (file)
@@ -13,7 +13,7 @@ namespace System.Collections.Immutable
     /// </summary>
     /// <typeparam name="TKey">The type of the dictionary's keys.</typeparam>
     /// <typeparam name="TValue">The type of the dictionary's values.</typeparam>
-    internal class ImmutableDictionaryDebuggerProxy<TKey, TValue> : ImmutableEnumerableDebuggerProxy<KeyValuePair<TKey, TValue>>
+    internal class ImmutableDictionaryDebuggerProxy<TKey, TValue> : ImmutableEnumerableDebuggerProxy<KeyValuePair<TKey, TValue>> where TKey : notnull
     {
         /// <summary>
         /// Initializes a new instance of the <see cref="ImmutableDictionaryDebuggerProxy{TKey, TValue}"/> class.
@@ -43,7 +43,7 @@ namespace System.Collections.Immutable
         /// <summary>
         /// The contents of the enumerable, cached into an array.
         /// </summary>
-        private T[] _cachedContents;
+        private T[]? _cachedContents;
 
         /// <summary>
         /// Initializes a new instance of the <see cref="ImmutableEnumerableDebuggerProxy{T}"/> class.
index e20d413..94fbc30 100644 (file)
@@ -33,22 +33,19 @@ namespace System.Collections.Immutable
         /// <returns><c>true</c> if the count could be determined; <c>false</c> otherwise.</returns>
         internal static bool TryGetCount<T>(this IEnumerable sequence, out int count)
         {
-            var collection = sequence as ICollection;
-            if (collection != null)
+            if (sequence is ICollection collection)
             {
                 count = collection.Count;
                 return true;
             }
 
-            var collectionOfT = sequence as ICollection<T>;
-            if (collectionOfT != null)
+            if (sequence is ICollection<T> collectionOfT)
             {
                 count = collectionOfT.Count;
                 return true;
             }
 
-            var readOnlyCollection = sequence as IReadOnlyCollection<T>;
-            if (readOnlyCollection != null)
+            if (sequence is IReadOnlyCollection<T> readOnlyCollection)
             {
                 count = readOnlyCollection.Count;
                 return true;
@@ -107,11 +104,9 @@ namespace System.Collections.Immutable
             Debug.Assert(arrayIndex >= 0 && arrayIndex <= array.Length);
 
             // IList is the GCD of what the following types implement.
-            var listInterface = sequence as IList<T>;
-            if (listInterface != null)
+            if (sequence is IList<T> listInterface)
             {
-                var list = sequence as List<T>;
-                if (list != null)
+                if (sequence is List<T> list)
                 {
                     list.CopyTo(array, arrayIndex);
                     return true;
@@ -127,10 +122,9 @@ namespace System.Collections.Immutable
                     return true;
                 }
 
-                if (sequence is ImmutableArray<T>)
+                if (sequence is ImmutableArray<T> immutable)
                 {
-                    var immutable = (ImmutableArray<T>)sequence;
-                    Array.Copy(immutable.array, 0, array, arrayIndex, immutable.Length);
+                    Array.Copy(immutable.array!, 0, array, arrayIndex, immutable.Length);
                     return true;
                 }
             }
@@ -157,7 +151,7 @@ namespace System.Collections.Immutable
 
             if (count == 0)
             {
-                return ImmutableArray<T>.Empty.array;
+                return ImmutableArray<T>.Empty.array!;
             }
 
             T[] array = new T[count];
index f448161..c5b0439 100644 (file)
@@ -17,7 +17,7 @@ namespace System.Collections.Immutable
     {
         internal static bool IsValueType<T>()
         {
-            if (default(T) != null)
+            if (default(T)! != null)
             {
                 return true;
             }
@@ -300,7 +300,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// The list-ified sequence.
             /// </summary>
-            private IList<T> _collection;
+            private IList<T>? _collection;
 
             /// <summary>
             /// Initializes a new instance of the <see cref="FallbackWrapper{T}"/> class.
index b8ab82d..565e665 100644 (file)
@@ -32,7 +32,7 @@ namespace System.Collections.Immutable
         /// The immutable collection.
         /// </returns>
         [Pure]
-        public static ImmutableHashSet<T> Create<T>(IEqualityComparer<T> equalityComparer)
+        public static ImmutableHashSet<T> Create<T>(IEqualityComparer<T>? equalityComparer)
         {
             return ImmutableHashSet<T>.Empty.WithComparer(equalityComparer);
         }
@@ -57,7 +57,7 @@ namespace System.Collections.Immutable
         /// <param name="item">The item to prepopulate.</param>
         /// <returns>The new immutable collection.</returns>
         [Pure]
-        public static ImmutableHashSet<T> Create<T>(IEqualityComparer<T> equalityComparer, T item)
+        public static ImmutableHashSet<T> Create<T>(IEqualityComparer<T>? equalityComparer, T item)
         {
             return ImmutableHashSet<T>.Empty.WithComparer(equalityComparer).Add(item);
         }
@@ -82,7 +82,7 @@ namespace System.Collections.Immutable
         /// <param name="items">The items to prepopulate.</param>
         /// <returns>The new immutable collection.</returns>
         [Pure]
-        public static ImmutableHashSet<T> CreateRange<T>(IEqualityComparer<T> equalityComparer, IEnumerable<T> items)
+        public static ImmutableHashSet<T> CreateRange<T>(IEqualityComparer<T>? equalityComparer, IEnumerable<T> items)
         {
             return ImmutableHashSet<T>.Empty.WithComparer(equalityComparer).Union(items);
         }
@@ -107,7 +107,7 @@ namespace System.Collections.Immutable
         /// <param name="items">The items to prepopulate.</param>
         /// <returns>The new immutable collection.</returns>
         [Pure]
-        public static ImmutableHashSet<T> Create<T>(IEqualityComparer<T> equalityComparer, params T[] items)
+        public static ImmutableHashSet<T> Create<T>(IEqualityComparer<T>? equalityComparer, params T[] items)
         {
             return ImmutableHashSet<T>.Empty.WithComparer(equalityComparer).Union(items);
         }
@@ -132,7 +132,7 @@ namespace System.Collections.Immutable
         /// The immutable collection.
         /// </returns>
         [Pure]
-        public static ImmutableHashSet<T>.Builder CreateBuilder<T>(IEqualityComparer<T> equalityComparer)
+        public static ImmutableHashSet<T>.Builder CreateBuilder<T>(IEqualityComparer<T>? equalityComparer)
         {
             return Create<T>(equalityComparer).ToBuilder();
         }
@@ -145,10 +145,9 @@ namespace System.Collections.Immutable
         /// <param name="equalityComparer">The equality comparer to use for initializing and adding members to the hash set.</param>
         /// <returns>An immutable set.</returns>
         [Pure]
-        public static ImmutableHashSet<TSource> ToImmutableHashSet<TSource>(this IEnumerable<TSource> source, IEqualityComparer<TSource> equalityComparer)
+        public static ImmutableHashSet<TSource> ToImmutableHashSet<TSource>(this IEnumerable<TSource> source, IEqualityComparer<TSource>? equalityComparer)
         {
-            var existingSet = source as ImmutableHashSet<TSource>;
-            if (existingSet != null)
+            if (source is ImmutableHashSet<TSource> existingSet)
             {
                 return existingSet.WithComparer(equalityComparer);
             }
index 7e73f47..589a3e0 100644 (file)
@@ -57,7 +57,7 @@ namespace System.Collections.Immutable
             /// Caches an immutable instance that represents the current state of the collection.
             /// </summary>
             /// <value>Null if no immutable view has been created for the current version.</value>
-            private ImmutableHashSet<T> _immutable;
+            private ImmutableHashSet<T>? _immutable;
 
             /// <summary>
             /// A number that increments every time the builder changes its contents.
index 255048b..ecc47ef 100644 (file)
@@ -19,7 +19,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// The builder being enumerated, if applicable.
             /// </summary>
-            private readonly Builder _builder;
+            private readonly Builder? _builder;
 
             /// <summary>
             /// The enumerator over the sorted dictionary whose keys are hash values.
@@ -41,7 +41,7 @@ namespace System.Collections.Immutable
             /// </summary>
             /// <param name="root">The root.</param>
             /// <param name="builder">The builder, if applicable.</param>
-            internal Enumerator(SortedInt32KeyNode<HashBucket> root, Builder builder = null)
+            internal Enumerator(SortedInt32KeyNode<HashBucket> root, Builder? builder = null)
             {
                 _builder = builder;
                 _mapEnumerator = new SortedInt32KeyNode<HashBucket>.Enumerator(root);
@@ -64,7 +64,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// Gets the current element.
             /// </summary>
-            object IEnumerator.Current
+            object? IEnumerator.Current
             {
                 get { return this.Current; }
             }
index d4dd830..4c94ed2 100644 (file)
@@ -52,7 +52,7 @@ namespace System.Collections.Immutable
             /// </summary>
             /// <param name="firstElement">The first element.</param>
             /// <param name="additionalElements">The additional elements.</param>
-            private HashBucket(T firstElement, ImmutableList<T>.Node additionalElements = null)
+            private HashBucket(T firstElement, ImmutableList<T>.Node? additionalElements = null)
             {
                 _firstValue = firstElement;
                 _additionalElements = additionalElements ?? ImmutableList<T>.Node.EmptyNode;
@@ -80,7 +80,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// Throws an exception to catch any errors in comparing <see cref="HashBucket"/> instances.
             /// </summary>
-            public override bool Equals(object obj)
+            public override bool Equals(object? obj)
             {
                 // This should never be called, as hash buckets don't know how to equate themselves.
                 throw new NotSupportedException();
@@ -221,7 +221,7 @@ namespace System.Collections.Immutable
                     {
                         // We can promote any element from the list into the first position, but it's most efficient
                         // to remove the root node in the binary tree that implements the list.
-                        int indexOfRootNode = _additionalElements.Left.Count;
+                        int indexOfRootNode = _additionalElements.Left!.Count;
                         result = OperationResult.SizeChanged;
                         return new HashBucket(_additionalElements.Key, _additionalElements.RemoveAt(indexOfRootNode));
                     }
@@ -317,7 +317,7 @@ namespace System.Collections.Immutable
                 /// <summary>
                 /// Gets the current element.
                 /// </summary>
-                object IEnumerator.Current
+                object? IEnumerator.Current
                 {
                     get { return this.Current; }
                 }
index 2668068..8fc536a 100644 (file)
@@ -435,7 +435,7 @@ namespace System.Collections.Immutable
         /// See the <see cref="IImmutableSet{T}"/> interface.
         /// </summary>
         [Pure]
-        public ImmutableHashSet<T> WithComparer(IEqualityComparer<T> equalityComparer)
+        public ImmutableHashSet<T> WithComparer(IEqualityComparer<T>? equalityComparer)
         {
             if (equalityComparer == null)
             {
index d668b29..3697c56 100644 (file)
@@ -3,6 +3,7 @@
 // See the LICENSE file in the project root for more information.
 
 using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
 using System.Threading;
 
 namespace System.Collections.Immutable
@@ -121,7 +122,7 @@ namespace System.Collections.Immutable
             Requires.NotNull(transformer, nameof(transformer));
 
             bool successful;
-            T[] oldArray = Volatile.Read(ref location.array);
+            T[]? oldArray = Volatile.Read(ref location.array);
             do
             {
                 ImmutableArray<T> newImmutableArray = transformer(new ImmutableArray<T>(oldArray));
@@ -131,7 +132,7 @@ namespace System.Collections.Immutable
                     return false;
                 }
 
-                T[] interlockedResult = Interlocked.CompareExchange(ref location.array, newImmutableArray.array, oldArray);
+                T[]? interlockedResult = Interlocked.CompareExchange(ref location.array, newImmutableArray.array, oldArray);
                 successful = ReferenceEquals(oldArray, interlockedResult);
                 oldArray = interlockedResult; // we already have a volatile read that we can reuse for the next loop
             }
@@ -165,7 +166,7 @@ namespace System.Collections.Immutable
             Requires.NotNull(transformer, nameof(transformer));
 
             bool successful;
-            T[] oldArray = Volatile.Read(ref location.array);
+            T[]? oldArray = Volatile.Read(ref location.array);
             do
             {
                 ImmutableArray<T> newImmutableArray = transformer(new ImmutableArray<T>(oldArray), transformerArgument);
@@ -175,7 +176,7 @@ namespace System.Collections.Immutable
                     return false;
                 }
 
-                T[] interlockedResult = Interlocked.CompareExchange(ref location.array, newImmutableArray.array, oldArray);
+                T[]? interlockedResult = Interlocked.CompareExchange(ref location.array, newImmutableArray.array, oldArray);
                 successful = ReferenceEquals(oldArray, interlockedResult);
                 oldArray = interlockedResult; // we already have a volatile read that we can reuse for the next loop
             }
@@ -240,7 +241,7 @@ namespace System.Collections.Immutable
         /// <param name="valueFactory">The function to execute to obtain the value to insert into the dictionary if the key is not found.</param>
         /// <param name="factoryArgument">The argument to pass to the value factory.</param>
         /// <returns>The value obtained from the dictionary or <paramref name="valueFactory"/> if it was not present.</returns>
-        public static TValue GetOrAdd<TKey, TValue, TArg>(ref ImmutableDictionary<TKey, TValue> location, TKey key, Func<TKey, TArg, TValue> valueFactory, TArg factoryArgument)
+        public static TValue GetOrAdd<TKey, TValue, TArg>(ref ImmutableDictionary<TKey, TValue> location, TKey key, Func<TKey, TArg, TValue> valueFactory, TArg factoryArgument) where TKey : notnull
         {
             Requires.NotNull(valueFactory, nameof(valueFactory));
 
@@ -248,7 +249,7 @@ namespace System.Collections.Immutable
             Requires.NotNull(map, nameof(location));
 
             TValue value;
-            if (map.TryGetValue(key, out value))
+            if (map.TryGetValue(key, out value!))
             {
                 return value;
             }
@@ -269,7 +270,7 @@ namespace System.Collections.Immutable
         /// This delegate will not be invoked more than once.
         /// </param>
         /// <returns>The value obtained from the dictionary or <paramref name="valueFactory"/> if it was not present.</returns>
-        public static TValue GetOrAdd<TKey, TValue>(ref ImmutableDictionary<TKey, TValue> location, TKey key, Func<TKey, TValue> valueFactory)
+        public static TValue GetOrAdd<TKey, TValue>(ref ImmutableDictionary<TKey, TValue> location, TKey key, Func<TKey, TValue> valueFactory) where TKey : notnull
         {
             Requires.NotNull(valueFactory, nameof(valueFactory));
 
@@ -277,7 +278,7 @@ namespace System.Collections.Immutable
             Requires.NotNull(map, nameof(location));
 
             TValue value;
-            if (map.TryGetValue(key, out value))
+            if (map.TryGetValue(key, out value!))
             {
                 return value;
             }
@@ -295,7 +296,7 @@ namespace System.Collections.Immutable
         /// <param name="key">The key for the value to retrieve or add.</param>
         /// <param name="value">The value to add to the dictionary if one is not already present.</param>
         /// <returns>The value obtained from the dictionary or <paramref name="value"/> if it was not present.</returns>
-        public static TValue GetOrAdd<TKey, TValue>(ref ImmutableDictionary<TKey, TValue> location, TKey key, TValue value)
+        public static TValue GetOrAdd<TKey, TValue>(ref ImmutableDictionary<TKey, TValue> location, TKey key, TValue value) where TKey : notnull
         {
             var priorCollection = Volatile.Read(ref location);
             bool successful;
@@ -303,7 +304,7 @@ namespace System.Collections.Immutable
             {
                 Requires.NotNull(priorCollection, nameof(location));
                 TValue oldValue;
-                if (priorCollection.TryGetValue(key, out oldValue))
+                if (priorCollection.TryGetValue(key, out oldValue!))
                 {
                     return oldValue;
                 }
@@ -330,7 +331,7 @@ namespace System.Collections.Immutable
         /// <param name="addValueFactory">The function that receives the key and returns a new value to add to the dictionary when no value previously exists.</param>
         /// <param name="updateValueFactory">The function that receives the key and prior value and returns the new value with which to update the dictionary.</param>
         /// <returns>The added or updated value.</returns>
-        public static TValue AddOrUpdate<TKey, TValue>(ref ImmutableDictionary<TKey, TValue> location, TKey key, Func<TKey, TValue> addValueFactory, Func<TKey, TValue, TValue> updateValueFactory)
+        public static TValue AddOrUpdate<TKey, TValue>(ref ImmutableDictionary<TKey, TValue> location, TKey key, Func<TKey, TValue> addValueFactory, Func<TKey, TValue, TValue> updateValueFactory) where TKey : notnull
         {
             Requires.NotNull(addValueFactory, nameof(addValueFactory));
             Requires.NotNull(updateValueFactory, nameof(updateValueFactory));
@@ -343,7 +344,7 @@ namespace System.Collections.Immutable
                 Requires.NotNull(priorCollection, nameof(location));
 
                 TValue oldValue;
-                if (priorCollection.TryGetValue(key, out oldValue))
+                if (priorCollection.TryGetValue(key, out oldValue!))
                 {
                     newValue = updateValueFactory(key, oldValue);
                 }
@@ -374,7 +375,7 @@ namespace System.Collections.Immutable
         /// <param name="addValue">The value to use if no previous value exists.</param>
         /// <param name="updateValueFactory">The function that receives the key and prior value and returns the new value with which to update the dictionary.</param>
         /// <returns>The added or updated value.</returns>
-        public static TValue AddOrUpdate<TKey, TValue>(ref ImmutableDictionary<TKey, TValue> location, TKey key, TValue addValue, Func<TKey, TValue, TValue> updateValueFactory)
+        public static TValue AddOrUpdate<TKey, TValue>(ref ImmutableDictionary<TKey, TValue> location, TKey key, TValue addValue, Func<TKey, TValue, TValue> updateValueFactory) where TKey : notnull
         {
             Requires.NotNull(updateValueFactory, nameof(updateValueFactory));
 
@@ -386,7 +387,7 @@ namespace System.Collections.Immutable
                 Requires.NotNull(priorCollection, nameof(location));
 
                 TValue oldValue;
-                if (priorCollection.TryGetValue(key, out oldValue))
+                if (priorCollection.TryGetValue(key, out oldValue!))
                 {
                     newValue = updateValueFactory(key, oldValue);
                 }
@@ -416,7 +417,7 @@ namespace System.Collections.Immutable
         /// <param name="key">The key to add, if is not already defined in the dictionary.</param>
         /// <param name="value">The value to add.</param>
         /// <returns><c>true</c> if the key was not previously set in the dictionary and the value was set; <c>false</c> otherwise.</returns>
-        public static bool TryAdd<TKey, TValue>(ref ImmutableDictionary<TKey, TValue> location, TKey key, TValue value)
+        public static bool TryAdd<TKey, TValue>(ref ImmutableDictionary<TKey, TValue> location, TKey key, TValue value) where TKey : notnull
         {
             var priorCollection = Volatile.Read(ref location);
             bool successful;
@@ -448,7 +449,7 @@ namespace System.Collections.Immutable
         /// <param name="newValue">The new value to set.</param>
         /// <param name="comparisonValue">The value that must already be set in the dictionary in order for the update to succeed.</param>
         /// <returns><c>true</c> if the key and comparison value were present in the dictionary and the update was made; <c>false</c> otherwise.</returns>
-        public static bool TryUpdate<TKey, TValue>(ref ImmutableDictionary<TKey, TValue> location, TKey key, TValue newValue, TValue comparisonValue)
+        public static bool TryUpdate<TKey, TValue>(ref ImmutableDictionary<TKey, TValue> location, TKey key, TValue newValue, TValue comparisonValue) where TKey : notnull
         {
             var valueComparer = EqualityComparer<TValue>.Default;
             var priorCollection = Volatile.Read(ref location);
@@ -458,7 +459,7 @@ namespace System.Collections.Immutable
                 Requires.NotNull(priorCollection, nameof(location));
 
                 TValue priorValue;
-                if (!priorCollection.TryGetValue(key, out priorValue) || !valueComparer.Equals(priorValue, comparisonValue))
+                if (!priorCollection.TryGetValue(key, out priorValue!) || !valueComparer.Equals(priorValue, comparisonValue))
                 {
                     // The key isn't in the dictionary, or its current value doesn't match what the caller expected.
                     return false;
@@ -482,7 +483,7 @@ namespace System.Collections.Immutable
         /// <param name="key">The key to remove.</param>
         /// <param name="value">Receives the value from the pre-existing entry, if one exists.</param>
         /// <returns><c>true</c> if the key was found and removed; <c>false</c> otherwise.</returns>
-        public static bool TryRemove<TKey, TValue>(ref ImmutableDictionary<TKey, TValue> location, TKey key, out TValue value)
+        public static bool TryRemove<TKey, TValue>(ref ImmutableDictionary<TKey, TValue> location, TKey key, [MaybeNullWhen(false)] out TValue value) where TKey : notnull
         {
             var priorCollection = Volatile.Read(ref location);
             bool successful;
@@ -490,7 +491,7 @@ namespace System.Collections.Immutable
             {
                 Requires.NotNull(priorCollection, nameof(location));
 
-                if (!priorCollection.TryGetValue(key, out value))
+                if (!priorCollection.TryGetValue(key, out value!))
                 {
                     return false;
                 }
@@ -515,7 +516,7 @@ namespace System.Collections.Immutable
         /// <param name="location">The variable or field to atomically update.</param>
         /// <param name="value">The value popped from the stack, if it was non-empty.</param>
         /// <returns><c>true</c> if an element was removed from the stack; <c>false</c> otherwise.</returns>
-        public static bool TryPop<T>(ref ImmutableStack<T> location, out T value)
+        public static bool TryPop<T>(ref ImmutableStack<T> location, [MaybeNullWhen(false)] out T value)
         {
             var priorCollection = Volatile.Read(ref location);
             bool successful;
@@ -525,7 +526,7 @@ namespace System.Collections.Immutable
 
                 if (priorCollection.IsEmpty)
                 {
-                    value = default(T);
+                    value = default(T)!;
                     return false;
                 }
 
@@ -570,7 +571,7 @@ namespace System.Collections.Immutable
         /// <param name="location">The variable or field to atomically update.</param>
         /// <param name="value">Receives the value from the head of the queue, if the queue is non-empty.</param>
         /// <returns><c>true</c> if the queue was not empty and the head element was removed; <c>false</c> otherwise.</returns>
-        public static bool TryDequeue<T>(ref ImmutableQueue<T> location, out T value)
+        public static bool TryDequeue<T>(ref ImmutableQueue<T> location, [MaybeNullWhen(false)] out T value)
         {
             var priorCollection = Volatile.Read(ref location);
             bool successful;
@@ -580,7 +581,7 @@ namespace System.Collections.Immutable
 
                 if (priorCollection.IsEmpty)
                 {
-                    value = default(T);
+                    value = default(T)!;
                     return false;
                 }
 
index 32dfa71..1025f47 100644 (file)
@@ -166,7 +166,7 @@ namespace System.Collections.Immutable
         /// to the last element, if found; otherwise, -1.
         /// </returns>
         [Pure]
-        public static int IndexOf<T>(this IImmutableList<T> list, T item, IEqualityComparer<T> equalityComparer)
+        public static int IndexOf<T>(this IImmutableList<T> list, T item, IEqualityComparer<T>? equalityComparer)
         {
             Requires.NotNull(list, nameof(list));
             return list.IndexOf(item, 0, list.Count, equalityComparer);
@@ -269,7 +269,7 @@ namespace System.Collections.Immutable
         /// <see cref="IImmutableList{T}"/>, if found; otherwise, -1.
         /// </returns>
         [Pure]
-        public static int LastIndexOf<T>(this IImmutableList<T> list, T item, IEqualityComparer<T> equalityComparer)
+        public static int LastIndexOf<T>(this IImmutableList<T> list, T item, IEqualityComparer<T>? equalityComparer)
         {
             Requires.NotNull(list, nameof(list));
 
index 460fc0a..bc64eb2 100644 (file)
@@ -44,7 +44,7 @@ namespace System.Collections.Immutable
             /// Caches an immutable instance that represents the current state of the collection.
             /// </summary>
             /// <value>Null if no immutable view has been created for the current version.</value>
-            private ImmutableList<T> _immutable;
+            private ImmutableList<T>? _immutable;
 
             /// <summary>
             /// A number that increments every time the builder changes its contents.
@@ -54,7 +54,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// The object callers may use to synchronize access to this collection.
             /// </summary>
-            private object _syncRoot;
+            private object? _syncRoot;
 
             /// <summary>
             /// Initializes a new instance of the <see cref="Builder"/> class.
@@ -401,6 +401,7 @@ namespace System.Collections.Immutable
             /// The first element that matches the conditions defined by the specified predicate,
             /// if found; otherwise, the default value for type T.
             /// </returns>
+            [return: MaybeNull]
             public T Find(Predicate<T> match) => _root.Find(match);
 
             /// <summary>
@@ -474,6 +475,7 @@ namespace System.Collections.Immutable
             /// The last element that matches the conditions defined by the specified predicate,
             /// if found; otherwise, the default value for type T.
             /// </returns>
+            [return: MaybeNull]
             public T FindLast(Predicate<T> match) => _root.FindLast(match);
 
             /// <summary>
@@ -597,7 +599,7 @@ namespace System.Collections.Immutable
             /// contains count number of elements, if found; otherwise, -1.
             /// </returns>
             [Pure]
-            public int IndexOf(T item, int index, int count, IEqualityComparer<T> equalityComparer) =>
+            public int IndexOf(T item, int index, int count, IEqualityComparer<T>? equalityComparer) =>
                 _root.IndexOf(item, index, count, equalityComparer);
 
             /// <summary>
@@ -693,7 +695,7 @@ namespace System.Collections.Immutable
             /// and ends at index, if found; otherwise, -1.
             /// </returns>
             [Pure]
-            public int LastIndexOf(T item, int startIndex, int count, IEqualityComparer<T> equalityComparer) =>
+            public int LastIndexOf(T item, int startIndex, int count, IEqualityComparer<T>? equalityComparer) =>
                 _root.LastIndexOf(item, startIndex, count, equalityComparer);
 
             /// <summary>
@@ -823,7 +825,7 @@ namespace System.Collections.Immutable
             /// The <see cref="IComparer{T}"/> implementation to use when comparing
             /// elements, or null to use <see cref="Comparer{T}.Default"/>.
             /// </param>
-            public void Sort(IComparer<T> comparer)
+            public void Sort(IComparer<T>? comparer)
             {
                 this.Root = this.Root.Sort(comparer);
             }
@@ -842,7 +844,7 @@ namespace System.Collections.Immutable
             /// The <see cref="IComparer{T}"/> implementation to use when comparing
             /// elements, or null to use <see cref="Comparer{T}.Default"/>.
             /// </param>
-            public void Sort(int index, int count, IComparer<T> comparer)
+            public void Sort(int index, int count, IComparer<T>? comparer)
             {
                 Requires.Range(index >= 0, nameof(index));
                 Requires.Range(count >= 0, nameof(count));
@@ -891,7 +893,7 @@ namespace System.Collections.Immutable
             /// cannot find an implementation of the System.IComparable&lt;T&gt; generic interface
             /// or the System.IComparable interface for type T.
             /// </exception>
-            public int BinarySearch(T item, IComparer<T> comparer)
+            public int BinarySearch(T item, IComparer<T>? comparer)
             {
                 return this.BinarySearch(0, this.Count, item, comparer);
             }
@@ -925,7 +927,7 @@ namespace System.Collections.Immutable
             /// cannot find an implementation of the System.IComparable&lt;T&gt; generic interface
             /// or the System.IComparable interface for type T.
             /// </exception>
-            public int BinarySearch(int index, int count, T item, IComparer<T> comparer)
+            public int BinarySearch(int index, int count, T item, IComparer<T>? comparer)
             {
                 return this.Root.BinarySearch(index, count, item, comparer);
             }
@@ -962,9 +964,9 @@ namespace System.Collections.Immutable
             /// <returns>
             /// The position into which the new element was inserted, or -1 to indicate that the item was not inserted into the collection,
             /// </returns>
-            int IList.Add(object value)
+            int IList.Add(object? value)
             {
-                this.Add((T)value);
+                this.Add((T)value!);
                 return this.Count - 1;
             }
 
@@ -983,11 +985,11 @@ namespace System.Collections.Immutable
             /// <returns>
             /// true if the <see cref="object"/> is found in the <see cref="IList"/>; otherwise, false.
             /// </returns>
-            bool IList.Contains(object value)
+            bool IList.Contains(object? value)
             {
                 if (IsCompatibleObject(value))
                 {
-                    return this.Contains((T)value);
+                    return this.Contains((T)value!);
                 }
 
                 return false;
@@ -1000,11 +1002,11 @@ namespace System.Collections.Immutable
             /// <returns>
             /// The index of <paramref name="value"/> if found in the list; otherwise, -1.
             /// </returns>
-            int IList.IndexOf(object value)
+            int IList.IndexOf(object? value)
             {
                 if (IsCompatibleObject(value))
                 {
-                    return this.IndexOf((T)value);
+                    return this.IndexOf((T)value!);
                 }
 
                 return -1;
@@ -1015,9 +1017,9 @@ namespace System.Collections.Immutable
             /// </summary>
             /// <param name="index">The zero-based index at which <paramref name="value"/> should be inserted.</param>
             /// <param name="value">The object to insert into the <see cref="IList"/>.</param>
-            void IList.Insert(int index, object value)
+            void IList.Insert(int index, object? value)
             {
-                this.Insert(index, (T)value);
+                this.Insert(index, (T)value!);
             }
 
             /// <summary>
@@ -1043,11 +1045,11 @@ namespace System.Collections.Immutable
             /// Removes the first occurrence of a specific object from the <see cref="IList"/>.
             /// </summary>
             /// <param name="value">The object to remove from the <see cref="IList"/>.</param>
-            void IList.Remove(object value)
+            void IList.Remove(object? value)
             {
                 if (IsCompatibleObject(value))
                 {
-                    this.Remove((T)value);
+                    this.Remove((T)value!);
                 }
             }
 
@@ -1059,10 +1061,10 @@ namespace System.Collections.Immutable
             /// </value>
             /// <param name="index">The index.</param>
             /// <returns></returns>
-            object IList.this[int index]
+            object? IList.this[int index]
             {
                 get { return this[index]; }
-                set { this[index] = (T)value; }
+                set { this[index] = (T)value!; }
             }
 
             #endregion
@@ -1100,7 +1102,7 @@ namespace System.Collections.Immutable
                 {
                     if (_syncRoot == null)
                     {
-                        System.Threading.Interlocked.CompareExchange<object>(ref _syncRoot, new object(), null);
+                        System.Threading.Interlocked.CompareExchange<object?>(ref _syncRoot, new object(), null);
                     }
 
                     return _syncRoot;
@@ -1123,7 +1125,7 @@ namespace System.Collections.Immutable
         /// <summary>
         /// The simple view of the collection.
         /// </summary>
-        private T[] _cachedContents;
+        private T[]? _cachedContents;
 
         /// <summary>
         /// Initializes a new instance of the <see cref="ImmutableListBuilderDebuggerProxy{T}"/> class.
index 7c817bd..9a24ef1 100755 (executable)
@@ -4,6 +4,7 @@
 
 using System.Collections.Generic;
 using System.ComponentModel;
+using System.Diagnostics;
 
 namespace System.Collections.Immutable
 {
@@ -37,7 +38,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// The builder being enumerated, if applicable.
             /// </summary>
-            private readonly Builder _builder;
+            private readonly Builder? _builder;
 
             /// <summary>
             /// A unique ID for this instance of this enumerator.
@@ -73,12 +74,12 @@ namespace System.Collections.Immutable
             /// <summary>
             /// The stack to use for enumerating the binary tree.
             /// </summary>
-            private SecurePooledObject<Stack<RefAsValueType<Node>>> _stack;
+            private SecurePooledObject<Stack<RefAsValueType<Node>>>? _stack;
 
             /// <summary>
             /// The node currently selected.
             /// </summary>
-            private Node _current;
+            private Node? _current;
 
             /// <summary>
             /// The version of the builder (when applicable) that is being enumerated.
@@ -93,7 +94,7 @@ namespace System.Collections.Immutable
             /// <param name="startIndex">The index of the first element to enumerate.</param>
             /// <param name="count">The number of elements in this collection.</param>
             /// <param name="reversed"><c>true</c> if the list should be enumerated in reverse order.</param>
-            internal Enumerator(Node root, Builder builder = null, int startIndex = -1, int count = -1, bool reversed = false)
+            internal Enumerator(Node root, Builder? builder = null, int startIndex = -1, int count = -1, bool reversed = false)
             {
                 Requires.NotNull(root, nameof(root));
                 Requires.Range(startIndex >= -1, nameof(startIndex));
@@ -145,20 +146,19 @@ namespace System.Collections.Immutable
             /// <summary>
             /// The current element.
             /// </summary>
-            object System.Collections.IEnumerator.Current => this.Current;
+            object? System.Collections.IEnumerator.Current => this.Current;
 
             /// <summary>
             /// Disposes of this enumerator and returns the stack reference to the resource pool.
             /// </summary>
             public void Dispose()
             {
-                _root = null;
+                _root = null!;
                 _current = null;
-                Stack<RefAsValueType<Node>> stack;
-                if (_stack != null && _stack.TryUse(ref this, out stack))
+                if (_stack != null && _stack.TryUse(ref this, out Stack<RefAsValueType<Node>>? stack))
                 {
                     stack.ClearFastWhenEmpty();
-                    s_EnumeratingStacks.TryAdd(this, _stack);
+                    s_EnumeratingStacks.TryAdd(this, _stack!);
                 }
 
                 _stack = null;
@@ -180,7 +180,7 @@ namespace System.Collections.Immutable
                     {
                         Node n = stack.Pop().Value;
                         _current = n;
-                        this.PushNext(this.NextBranch(n));
+                        this.PushNext(this.NextBranch(n)!);
                         _remainingCount--;
                         return true;
                     }
@@ -208,22 +208,23 @@ namespace System.Collections.Immutable
             /// <summary>Resets the stack used for enumeration.</summary>
             private void ResetStack()
             {
+                Debug.Assert(_stack != null);
                 var stack = _stack.Use(ref this);
                 stack.ClearFastWhenEmpty();
 
                 var node = _root;
                 var skipNodes = _reversed ? _root.Count - _startIndex - 1 : _startIndex;
-                while (!node.IsEmpty && skipNodes != this.PreviousBranch(node).Count)
+                while (!node.IsEmpty && skipNodes != this.PreviousBranch(node)!.Count)
                 {
-                    if (skipNodes < this.PreviousBranch(node).Count)
+                    if (skipNodes < this.PreviousBranch(node)!.Count)
                     {
                         stack.Push(new RefAsValueType<Node>(node));
-                        node = this.PreviousBranch(node);
+                        node = this.PreviousBranch(node)!;
                     }
                     else
                     {
-                        skipNodes -= this.PreviousBranch(node).Count + 1;
-                        node = this.NextBranch(node);
+                        skipNodes -= this.PreviousBranch(node)!.Count + 1;
+                        node = this.NextBranch(node)!;
                     }
                 }
 
@@ -236,12 +237,12 @@ namespace System.Collections.Immutable
             /// <summary>
             /// Obtains the right branch of the given node (or the left, if walking in reverse).
             /// </summary>
-            private Node NextBranch(Node node) => _reversed ? node.Left : node.Right;
+            private Node? NextBranch(Node node) => _reversed ? node.Left : node.Right;
 
             /// <summary>
             /// Obtains the left branch of the given node (or the right, if walking in reverse).
             /// </summary>
-            private Node PreviousBranch(Node node) => _reversed ? node.Right : node.Left;
+            private Node? PreviousBranch(Node node) => _reversed ? node.Right : node.Left;
 
             /// <summary>
             /// Throws an <see cref="ObjectDisposedException"/> if this enumerator has been disposed.
@@ -281,11 +282,12 @@ namespace System.Collections.Immutable
                 Requires.NotNull(node, nameof(node));
                 if (!node.IsEmpty)
                 {
+                    Debug.Assert(_stack != null);
                     var stack = _stack.Use(ref this);
                     while (!node.IsEmpty)
                     {
                         stack.Push(new RefAsValueType<Node>(node));
-                        node = this.PreviousBranch(node);
+                        node = this.PreviousBranch(node)!;
                     }
                 }
             }
index cfde501..211d166 100644 (file)
@@ -26,7 +26,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// The key associated with this node.
             /// </summary>
-            private T _key;
+            private T _key = default!; // Defaulting for EmptyNode, shouldn't be null for non empty nodes so didn't annotated with [MaybeNull]
 
             /// <summary>
             /// A value indicating whether this node has been frozen (made immutable).
@@ -56,12 +56,12 @@ namespace System.Collections.Immutable
             /// <summary>
             /// The left tree.
             /// </summary>
-            private Node _left;
+            private Node? _left;
 
             /// <summary>
             /// The right tree.
             /// </summary>
-            private Node _right;
+            private Node? _right;
 
             /// <summary>
             /// Initializes a new instance of the <see cref="ImmutableList{T}.Node"/> class
@@ -120,32 +120,32 @@ namespace System.Collections.Immutable
             /// <summary>
             /// Gets the left branch of this node.
             /// </summary>
-            public Node Left => _left;
+            public Node? Left => _left;
 
             /// <summary>
             /// Gets the left branch of this node.
             /// </summary>
-            IBinaryTree IBinaryTree.Left => _left;
+            IBinaryTree? IBinaryTree.Left => _left;
 
             /// <summary>
             /// Gets the right branch of this node.
             /// </summary>
-            public Node Right => _right;
+            public Node? Right => _right;
 
             /// <summary>
             /// Gets the right branch of this node.
             /// </summary>
-            IBinaryTree IBinaryTree.Right => _right;
+            IBinaryTree? IBinaryTree.Right => _right;
 
             /// <summary>
             /// Gets the left branch of this node.
             /// </summary>
-            IBinaryTree<T> IBinaryTree<T>.Left => _left;
+            IBinaryTree<T>? IBinaryTree<T>.Left => _left;
 
             /// <summary>
             /// Gets the right branch of this node.
             /// </summary>
-            IBinaryTree<T> IBinaryTree<T>.Right => _right;
+            IBinaryTree<T>? IBinaryTree<T>.Right => _right;
 
             /// <summary>
             /// Gets the value represented by the current node.
@@ -172,6 +172,7 @@ namespace System.Collections.Immutable
                 get
                 {
                     Requires.Range(index >= 0 && index < this.Count, nameof(index));
+                    Debug.Assert(_left != null && _right != null);
 
                     if (index < _left._count)
                     {
@@ -197,6 +198,7 @@ namespace System.Collections.Immutable
             {
                 Requires.Range(index >= 0 && index < this.Count, nameof(index));
 
+                Debug.Assert(_left != null && _right != null);
                 if (index < _left._count)
                 {
                     return ref _left.ItemRef(index);
@@ -288,7 +290,7 @@ namespace System.Collections.Immutable
                     return CreateLeaf(key);
                 }
 
-                Node newRight = _right.Add(key);
+                Node newRight = _right!.Add(key);
                 Node result = this.MutateRight(newRight);
                 return result.IsBalanced ? result : result.BalanceRight();
             }
@@ -308,7 +310,7 @@ namespace System.Collections.Immutable
                     return CreateLeaf(key);
                 }
 
-                if (index <= _left._count)
+                if (index <= _left!._count)
                 {
                     Node newLeft = _left.Insert(index, key);
                     Node result = this.MutateLeft(newLeft);
@@ -316,7 +318,7 @@ namespace System.Collections.Immutable
                 }
                 else
                 {
-                    Node newRight = _right.Insert(index - _left._count - 1, key);
+                    Node newRight = _right!.Insert(index - _left._count - 1, key);
                     Node result = this.MutateRight(newRight);
                     return result.IsBalanced ? result : result.BalanceRight();
                 }
@@ -336,7 +338,7 @@ namespace System.Collections.Immutable
                     return CreateRange(keys);
                 }
 
-                Node newRight = _right.AddRange(keys);
+                Node newRight = _right!.AddRange(keys);
                 Node result = this.MutateRight(newRight);
                 return result.BalanceMany();
             }
@@ -358,14 +360,14 @@ namespace System.Collections.Immutable
                 }
 
                 Node result;
-                if (index <= _left._count)
+                if (index <= _left!._count)
                 {
                     Node newLeft = _left.InsertRange(index, keys);
                     result = this.MutateLeft(newLeft);
                 }
                 else
                 {
-                    Node newRight = _right.InsertRange(index - _left._count - 1, keys);
+                    Node newRight = _right!.InsertRange(index - _left._count - 1, keys);
                     result = this.MutateRight(newRight);
                 }
 
@@ -380,6 +382,7 @@ namespace System.Collections.Immutable
             internal Node RemoveAt(int index)
             {
                 Requires.Range(index >= 0 && index < this.Count, nameof(index));
+                Debug.Assert(_left != null && _right != null);
 
                 Node result = this;
                 if (index == _left._count)
@@ -404,7 +407,7 @@ namespace System.Collections.Immutable
                         // We have two children. Remove the next-highest node and replace
                         // this node with it.
                         var successor = _right;
-                        while (!successor._left.IsEmpty)
+                        while (!successor._left!.IsEmpty)
                         {
                             successor = successor._left;
                         }
@@ -482,7 +485,7 @@ namespace System.Collections.Immutable
                 Debug.Assert(!this.IsEmpty);
 
                 Node result = this;
-                if (index == _left._count)
+                if (index == _left!._count)
                 {
                     // We have a match.
                     result = this.MutateKey(value);
@@ -494,7 +497,7 @@ namespace System.Collections.Immutable
                 }
                 else
                 {
-                    var newRight = _right.ReplaceAt(index - _left._count - 1, value);
+                    var newRight = _right!.ReplaceAt(index - _left._count - 1, value);
                     result = this.MutateRight(newRight);
                 }
 
@@ -575,7 +578,7 @@ namespace System.Collections.Immutable
             /// elements, or null to use the default comparer <see cref="Comparer{T}.Default"/>.
             /// </param>
             /// <returns>The sorted list.</returns>
-            internal Node Sort(IComparer<T> comparer) => this.Sort(0, this.Count, comparer);
+            internal Node Sort(IComparer<T>? comparer) => this.Sort(0, this.Count, comparer);
 
             /// <summary>
             /// Sorts the elements in a range of elements in <see cref="ImmutableList{T}"/>
@@ -592,7 +595,7 @@ namespace System.Collections.Immutable
             /// elements, or null to use the default comparer <see cref="Comparer{T}.Default"/>.
             /// </param>
             /// <returns>The sorted list.</returns>
-            internal Node Sort(int index, int count, IComparer<T> comparer)
+            internal Node Sort(int index, int count, IComparer<T>? comparer)
             {
                 Requires.Range(index >= 0, nameof(index));
                 Requires.Range(count >= 0, nameof(count));
@@ -634,7 +637,7 @@ namespace System.Collections.Immutable
             /// cannot find an implementation of the <see cref="IComparable{T}"/> generic interface
             /// or the <see cref="IComparable"/> interface for type <typeparamref name="T"/>.
             /// </exception>
-            internal int BinarySearch(int index, int count, T item, IComparer<T> comparer)
+            internal int BinarySearch(int index, int count, T item, IComparer<T>? comparer)
             {
                 Requires.Range(index >= 0, nameof(index));
                 Requires.Range(count >= 0, nameof(count));
@@ -646,14 +649,14 @@ namespace System.Collections.Immutable
                 }
 
                 // If this node is not within range, defer to either branch as appropriate.
-                int thisNodeIndex = _left.Count; // this is only the index within the AVL tree, treating this node as root rather than a member of a larger tree.
+                int thisNodeIndex = _left!.Count; // this is only the index within the AVL tree, treating this node as root rather than a member of a larger tree.
                 if (index + count <= thisNodeIndex)
                 {
                     return _left.BinarySearch(index, count, item, comparer);
                 }
                 else if (index > thisNodeIndex)
                 {
-                    int result = _right.BinarySearch(index - thisNodeIndex - 1, count, item, comparer);
+                    int result = _right!.BinarySearch(index - thisNodeIndex - 1, count, item, comparer);
                     int offset = thisNodeIndex + 1;
                     return result < 0 ? result - offset : result + offset;
                 }
@@ -670,7 +673,7 @@ namespace System.Collections.Immutable
                 else if (compare > 0)
                 {
                     int adjustedCount = count - (thisNodeIndex - index) - 1;
-                    int result = adjustedCount < 0 ? -1 : _right.BinarySearch(0, adjustedCount, item, comparer);
+                    int result = adjustedCount < 0 ? -1 : _right!.BinarySearch(0, adjustedCount, item, comparer);
                     int offset = thisNodeIndex + 1;
                     return result < 0 ? result - offset : result + offset;
                 }
@@ -702,7 +705,7 @@ namespace System.Collections.Immutable
             /// <see cref="ImmutableList{T}"/>, if found; otherwise, -1.
             /// </returns>
             [Pure]
-            internal int IndexOf(T item, IEqualityComparer<T> equalityComparer) => this.IndexOf(item, 0, this.Count, equalityComparer);
+            internal int IndexOf(T item, IEqualityComparer<T>? equalityComparer) => this.IndexOf(item, 0, this.Count, equalityComparer);
 
             /// <summary>
             /// Searches for the specified object and returns <c>true</c> if it is found, <c>false</c> otherwise.
@@ -746,7 +749,7 @@ namespace System.Collections.Immutable
             /// contains <paramref name="count"/> number of elements, if found; otherwise, -1.
             /// </returns>
             [Pure]
-            internal int IndexOf(T item, int index, int count, IEqualityComparer<T> equalityComparer)
+            internal int IndexOf(T item, int index, int count, IEqualityComparer<T>? equalityComparer)
             {
                 Requires.Range(index >= 0, nameof(index));
                 Requires.Range(count >= 0, nameof(count));
@@ -789,7 +792,7 @@ namespace System.Collections.Immutable
             /// and ends at <paramref name="index"/>, if found; otherwise, -1.
             /// </returns>
             [Pure]
-            internal int LastIndexOf(T item, int index, int count, IEqualityComparer<T> equalityComparer)
+            internal int LastIndexOf(T item, int index, int count, IEqualityComparer<T>? equalityComparer)
             {
                 Requires.Range(index >= 0, nameof(index));
                 Requires.Range(count >= 0 && count <= this.Count, nameof(count));
@@ -1002,6 +1005,7 @@ namespace System.Collections.Immutable
             /// The first element that matches the conditions defined by the specified predicate,
             /// if found; otherwise, the default value for type <typeparamref name="T"/>.
             /// </returns>
+            [return: MaybeNull]
             internal T Find(Predicate<T> match)
             {
                 Requires.NotNull(match, nameof(match));
@@ -1014,7 +1018,7 @@ namespace System.Collections.Immutable
                     }
                 }
 
-                return default(T);
+                return default(T)!;
             }
 
             /// <summary>
@@ -1039,7 +1043,7 @@ namespace System.Collections.Immutable
                     return ImmutableList<T>.Empty;
                 }
 
-                List<T> list = null;
+                List<T>? list = null;
                 foreach (var item in this)
                 {
                     if (match(item))
@@ -1147,6 +1151,7 @@ namespace System.Collections.Immutable
             /// The last element that matches the conditions defined by the specified predicate,
             /// if found; otherwise, the default value for type <typeparamref name="T"/>.
             /// </returns>
+            [return: MaybeNull]
             internal T FindLast(Predicate<T> match)
             {
                 Requires.NotNull(match, nameof(match));
@@ -1162,7 +1167,7 @@ namespace System.Collections.Immutable
                     }
                 }
 
-                return default(T);
+                return default(T)!;
             }
 
             /// <summary>
@@ -1255,8 +1260,8 @@ namespace System.Collections.Immutable
                 // If this node is frozen, all its descendants must already be frozen.
                 if (!_frozen)
                 {
-                    _left.Freeze();
-                    _right.Freeze();
+                    _left!.Freeze();
+                    _right!.Freeze();
                     _frozen = true;
                 }
             }
@@ -1270,9 +1275,9 @@ namespace System.Collections.Immutable
             private Node RotateLeft()
             {
                 Debug.Assert(!this.IsEmpty);
-                Debug.Assert(!_right.IsEmpty);
+                Debug.Assert(!_right!.IsEmpty);
 
-                return _right.MutateLeft(this.MutateRight(_right._left));
+                return _right.MutateLeft(this.MutateRight(_right._left!));
             }
 
             /// <summary>
@@ -1282,9 +1287,9 @@ namespace System.Collections.Immutable
             private Node RotateRight()
             {
                 Debug.Assert(!this.IsEmpty);
-                Debug.Assert(!_left.IsEmpty);
+                Debug.Assert(!_left!.IsEmpty);
 
-                return _left.MutateRight(this.MutateLeft(_left._right));
+                return _left.MutateRight(this.MutateLeft(_left._right!));
             }
 
             /// <summary>
@@ -1294,15 +1299,15 @@ namespace System.Collections.Immutable
             private Node DoubleLeft()
             {
                 Debug.Assert(!this.IsEmpty);
-                Debug.Assert(!_right.IsEmpty);
-                Debug.Assert(!_right._left.IsEmpty);
+                Debug.Assert(!_right!.IsEmpty);
+                Debug.Assert(!_right!._left!.IsEmpty);
 
                 // The following is an optimized version of rotating the right child right, then rotating the parent left.
                 Node right = _right;
                 Node rightLeft = right._left;
                 return rightLeft.MutateBoth(
-                    left: this.MutateRight(rightLeft._left),
-                    right: right.MutateLeft(rightLeft._right));
+                    left: this.MutateRight(rightLeft._left!),
+                    right: right.MutateLeft(rightLeft._right!));
             }
 
             /// <summary>
@@ -1312,15 +1317,15 @@ namespace System.Collections.Immutable
             private Node DoubleRight()
             {
                 Debug.Assert(!this.IsEmpty);
-                Debug.Assert(!_left.IsEmpty);
-                Debug.Assert(!_left._right.IsEmpty);
+                Debug.Assert(!_left!.IsEmpty);
+                Debug.Assert(!_left._right!.IsEmpty);
 
                 // The following is an optimized version of rotating the left child left, then rotating the parent right.
                 Node left = _left;
                 Node leftRight = left._right;
                 return leftRight.MutateBoth(
-                    left: left.MutateRight(leftRight._left),
-                    right: this.MutateLeft(leftRight._right));
+                    left: left.MutateRight(leftRight._left!),
+                    right: this.MutateLeft(leftRight._right!));
             }
 
             /// <summary>
@@ -1334,7 +1339,7 @@ namespace System.Collections.Immutable
                 get
                 {
                     Debug.Assert(!this.IsEmpty);
-                    return _right._height - _left._height;
+                    return _right!._height - _left!._height;
                 }
             }
 
@@ -1377,7 +1382,7 @@ namespace System.Collections.Immutable
                 Debug.Assert(!this.IsEmpty);
                 Debug.Assert(this.IsLeftHeavy);
 
-                return _left.BalanceFactor > 0 ? this.DoubleRight() : this.RotateRight();
+                return _left!.BalanceFactor > 0 ? this.DoubleRight() : this.RotateRight();
             }
 
             /// <summary>
@@ -1389,7 +1394,7 @@ namespace System.Collections.Immutable
                 Debug.Assert(!this.IsEmpty);
                 Debug.Assert(this.IsRightHeavy);
 
-                return _right.BalanceFactor < 0 ? this.DoubleLeft() : this.RotateLeft();
+                return _right!.BalanceFactor < 0 ? this.DoubleLeft() : this.RotateLeft();
             }
 
             /// <summary>
@@ -1403,16 +1408,19 @@ namespace System.Collections.Immutable
             private Node BalanceMany()
             {
                 Node tree = this;
+                Debug.Assert(tree._left != null && tree._right != null);
                 while (!tree.IsBalanced)
                 {
                     if (tree.IsRightHeavy)
                     {
                         tree = tree.BalanceRight();
+                        Debug.Assert(tree._left != null);
                         tree.MutateLeft(tree._left.BalanceMany());
                     }
                     else
                     {
                         tree = tree.BalanceLeft();
+                        Debug.Assert(tree._right != null);
                         tree.MutateRight(tree._right.BalanceMany());
                     }
                 }
@@ -1462,13 +1470,13 @@ namespace System.Collections.Immutable
 
                 if (_frozen)
                 {
-                    return new Node(_key, left, _right);
+                    return new Node(_key, left, _right!);
                 }
                 else
                 {
                     _left = left;
-                    _height = ParentHeight(left, _right);
-                    _count = ParentCount(left, _right);
+                    _height = ParentHeight(left, _right!);
+                    _count = ParentCount(left, _right!);
                     return this;
                 }
             }
@@ -1486,13 +1494,13 @@ namespace System.Collections.Immutable
 
                 if (_frozen)
                 {
-                    return new Node(_key, _left, right);
+                    return new Node(_key, _left!, right);
                 }
                 else
                 {
                     _right = right;
-                    _height = ParentHeight(_left, right);
-                    _count = ParentCount(_left, right);
+                    _height = ParentHeight(_left!, right);
+                    _count = ParentCount(_left!, right);
                     return this;
                 }
             }
@@ -1526,7 +1534,7 @@ namespace System.Collections.Immutable
 
                 if (_frozen)
                 {
-                    return new Node(key, _left, _right);
+                    return new Node(key, _left!, _right!);
                 }
                 else
                 {
@@ -1542,7 +1550,7 @@ namespace System.Collections.Immutable
             /// <returns>The root of the created node tree.</returns>
             private static Node CreateRange(IEnumerable<T> keys)
             {
-                ImmutableList<T> other;
+                ImmutableList<T>? other;
                 if (TryCastToImmutableList(keys, out other))
                 {
                     return other._root;
@@ -1573,7 +1581,7 @@ namespace System.Collections.Immutable
             /// The equality comparer to use for testing the node and value.
             /// </param>
             /// <returns></returns>
-            private static bool Contains(Node node, T value, IEqualityComparer<T> equalityComparer) => !node.IsEmpty && (equalityComparer.Equals(value, node._key) || Contains(node._left, value, equalityComparer) || Contains(node._right, value, equalityComparer));
+            private static bool Contains(Node node, T value, IEqualityComparer<T> equalityComparer) => !node.IsEmpty && (equalityComparer.Equals(value, node._key) || Contains(node._left!, value, equalityComparer) || Contains(node._right!, value, equalityComparer));
         }
     }
 }
index 7ed9ce2..2b4fb31 100644 (file)
@@ -89,7 +89,7 @@ namespace System.Collections.Immutable
         /// cannot find an implementation of the <see cref="IComparable{T}"/> generic interface
         /// or the <see cref="IComparable"/> interface for type <typeparamref name="T"/>.
         /// </exception>
-        public int BinarySearch(T item, IComparer<T> comparer) => this.BinarySearch(0, this.Count, item, comparer);
+        public int BinarySearch(T item, IComparer<T>? comparer) => this.BinarySearch(0, this.Count, item, comparer);
 
         /// <summary>
         /// Searches a range of elements in the sorted <see cref="ImmutableList{T}"/>
@@ -120,7 +120,7 @@ namespace System.Collections.Immutable
         /// cannot find an implementation of the <see cref="IComparable{T}"/> generic interface
         /// or the <see cref="IComparable"/> interface for type <typeparamref name="T"/>.
         /// </exception>
-        public int BinarySearch(int index, int count, T item, IComparer<T> comparer) => _root.BinarySearch(index, count, item, comparer);
+        public int BinarySearch(int index, int count, T item, IComparer<T>? comparer) => _root.BinarySearch(index, count, item, comparer);
 
         #region IImmutableList<T> Properties
 
@@ -279,7 +279,7 @@ namespace System.Collections.Immutable
         /// See the <see cref="IImmutableList{T}"/> interface.
         /// </summary>
         [Pure]
-        public ImmutableList<T> Remove(T value, IEqualityComparer<T> equalityComparer)
+        public ImmutableList<T> Remove(T value, IEqualityComparer<T>? equalityComparer)
         {
             int index = this.IndexOf(value, equalityComparer);
             return index < 0 ? this : this.RemoveAt(index);
@@ -329,7 +329,7 @@ namespace System.Collections.Immutable
         /// A new list with the elements removed.
         /// </returns>
         [Pure]
-        public ImmutableList<T> RemoveRange(IEnumerable<T> items, IEqualityComparer<T> equalityComparer)
+        public ImmutableList<T> RemoveRange(IEnumerable<T> items, IEqualityComparer<T>? equalityComparer)
         {
             Requires.NotNull(items, nameof(items));
 
@@ -400,7 +400,7 @@ namespace System.Collections.Immutable
         /// See the <see cref="IImmutableList{T}"/> interface.
         /// </summary>
         [Pure]
-        public ImmutableList<T> Replace(T oldValue, T newValue, IEqualityComparer<T> equalityComparer)
+        public ImmutableList<T> Replace(T oldValue, T newValue, IEqualityComparer<T>? equalityComparer)
         {
             int index = this.IndexOf(oldValue, equalityComparer);
             if (index < 0)
@@ -460,7 +460,7 @@ namespace System.Collections.Immutable
         /// </param>
         /// <returns>The sorted list.</returns>
         [Pure]
-        public ImmutableList<T> Sort(IComparer<T> comparer) => this.Wrap(_root.Sort(comparer));
+        public ImmutableList<T> Sort(IComparer<T>? comparer) => this.Wrap(_root.Sort(comparer));
 
         /// <summary>
         /// Sorts the elements in a range of elements in <see cref="ImmutableList{T}"/>
@@ -478,7 +478,7 @@ namespace System.Collections.Immutable
         /// </param>
         /// <returns>The sorted list.</returns>
         [Pure]
-        public ImmutableList<T> Sort(int index, int count, IComparer<T> comparer)
+        public ImmutableList<T> Sort(int index, int count, IComparer<T>? comparer)
         {
             Requires.Range(index >= 0, nameof(index));
             Requires.Range(count >= 0, nameof(count));
@@ -617,6 +617,7 @@ namespace System.Collections.Immutable
         /// The first element that matches the conditions defined by the specified predicate,
         /// if found; otherwise, the default value for type <typeparamref name="T"/>.
         /// </returns>
+        [return: MaybeNull]
         public T Find(Predicate<T> match) => _root.Find(match);
 
         /// <summary>
@@ -690,6 +691,7 @@ namespace System.Collections.Immutable
         /// The last element that matches the conditions defined by the specified predicate,
         /// if found; otherwise, the default value for type <typeparamref name="T"/>.
         /// </returns>
+        [return: MaybeNull]
         public T FindLast(Predicate<T> match) => _root.FindLast(match);
 
         /// <summary>
@@ -765,7 +767,7 @@ namespace System.Collections.Immutable
         /// contains <paramref name="count"/> number of elements, if found; otherwise, -1.
         /// </returns>
         [Pure]
-        public int IndexOf(T item, int index, int count, IEqualityComparer<T> equalityComparer) => _root.IndexOf(item, index, count, equalityComparer);
+        public int IndexOf(T item, int index, int count, IEqualityComparer<T>? equalityComparer) => _root.IndexOf(item, index, count, equalityComparer);
 
         /// <summary>
         /// Searches for the specified object and returns the zero-based index of the
@@ -788,7 +790,7 @@ namespace System.Collections.Immutable
         /// and ends at <paramref name="index"/>, if found; otherwise, -1.
         /// </returns>
         [Pure]
-        public int LastIndexOf(T item, int index, int count, IEqualityComparer<T> equalityComparer) => _root.LastIndexOf(item, index, count, equalityComparer);
+        public int LastIndexOf(T item, int index, int count, IEqualityComparer<T>? equalityComparer) => _root.LastIndexOf(item, index, count, equalityComparer);
 
         /// <summary>
         /// Determines whether every element in the <see cref="ImmutableList{T}"/>
@@ -856,7 +858,7 @@ namespace System.Collections.Immutable
         /// See the <see cref="IImmutableList{T}"/> interface.
         /// </summary>
         [ExcludeFromCodeCoverage]
-        IImmutableList<T> IImmutableList<T>.Remove(T value, IEqualityComparer<T> equalityComparer) => this.Remove(value, equalityComparer);
+        IImmutableList<T> IImmutableList<T>.Remove(T value, IEqualityComparer<T>? equalityComparer) => this.Remove(value, equalityComparer);
 
         /// <summary>
         /// See the <see cref="IImmutableList{T}"/> interface.
@@ -868,7 +870,7 @@ namespace System.Collections.Immutable
         /// See the <see cref="IImmutableList{T}"/> interface.
         /// </summary>
         [ExcludeFromCodeCoverage]
-        IImmutableList<T> IImmutableList<T>.RemoveRange(IEnumerable<T> items, IEqualityComparer<T> equalityComparer) => this.RemoveRange(items, equalityComparer);
+        IImmutableList<T> IImmutableList<T>.RemoveRange(IEnumerable<T> items, IEqualityComparer<T>? equalityComparer) => this.RemoveRange(items, equalityComparer);
 
         /// <summary>
         /// See the <see cref="IImmutableList{T}"/> interface.
@@ -904,7 +906,7 @@ namespace System.Collections.Immutable
         /// </param>
         /// <returns>The new list.</returns>
         /// <exception cref="ArgumentException">Thrown when the old value does not exist in the list.</exception>
-        IImmutableList<T> IImmutableList<T>.Replace(T oldValue, T newValue, IEqualityComparer<T> equalityComparer) => this.Replace(oldValue, newValue, equalityComparer);
+        IImmutableList<T> IImmutableList<T>.Replace(T oldValue, T newValue, IEqualityComparer<T>? equalityComparer) => this.Replace(oldValue, newValue, equalityComparer);
 
         #endregion
 
@@ -1018,7 +1020,7 @@ namespace System.Collections.Immutable
         /// Nothing. An exception is always thrown.
         /// </returns>
         /// <exception cref="NotSupportedException">Always thrown.</exception>
-        int IList.Add(object value) => throw new NotSupportedException();
+        int IList.Add(object? value) => throw new NotSupportedException();
 
         /// <summary>
         /// Removes the <see cref="IList"/> item at the specified index.
@@ -1040,7 +1042,7 @@ namespace System.Collections.Immutable
         /// <returns>
         /// true if the <see cref="object"/> is found in the <see cref="IList"/>; otherwise, false.
         /// </returns>
-        bool IList.Contains(object value) => IsCompatibleObject(value) && this.Contains((T)value);
+        bool IList.Contains(object? value) => IsCompatibleObject(value) && this.Contains((T)value!);
 
         /// <summary>
         /// Determines the index of a specific item in the <see cref="IList"/>.
@@ -1049,7 +1051,7 @@ namespace System.Collections.Immutable
         /// <returns>
         /// The index of <paramref name="value"/> if found in the list; otherwise, -1.
         /// </returns>
-        int IList.IndexOf(object value) => IsCompatibleObject(value) ? this.IndexOf((T)value) : -1;
+        int IList.IndexOf(object? value) => IsCompatibleObject(value) ? this.IndexOf((T)value!) : -1;
 
         /// <summary>
         /// Inserts an item to the <see cref="IList"/> at the specified index.
@@ -1057,7 +1059,7 @@ namespace System.Collections.Immutable
         /// <param name="index">The zero-based index at which <paramref name="value"/> should be inserted.</param>
         /// <param name="value">The object to insert into the <see cref="IList"/>.</param>
         /// <exception cref="NotSupportedException">Always thrown.</exception>
-        void IList.Insert(int index, object value) => throw new NotSupportedException();
+        void IList.Insert(int index, object? value) => throw new NotSupportedException();
 
         /// <summary>
         /// Gets a value indicating whether the <see cref="IList"/> has a fixed size.
@@ -1077,7 +1079,7 @@ namespace System.Collections.Immutable
         /// </summary>
         /// <param name="value">The object to remove from the <see cref="IList"/>.</param>
         /// <exception cref="NotSupportedException">Always thrown.</exception>
-        void IList.Remove(object value) => throw new NotSupportedException();
+        void IList.Remove(object? value) => throw new NotSupportedException();
 
         /// <summary>
         /// Gets or sets the <see cref="object"/> at the specified index.
@@ -1089,7 +1091,7 @@ namespace System.Collections.Immutable
         /// <returns>The value at the specified index.</returns>
         /// <exception cref="IndexOutOfRangeException">Thrown from getter when <paramref name="index"/> is negative or not less than <see cref="Count"/>.</exception>
         /// <exception cref="NotSupportedException">Always thrown from the setter.</exception>
-        object IList.this[int index]
+        object? IList.this[int index]
         {
             get => this[index];
             set => throw new NotSupportedException();
@@ -1137,7 +1139,7 @@ namespace System.Collections.Immutable
         /// <param name="sequence">The sequence that may have come from an immutable list.</param>
         /// <param name="other">Receives the concrete <see cref="ImmutableList{T}"/> typed value if one can be found.</param>
         /// <returns><c>true</c> if the cast was successful; <c>false</c> otherwise.</returns>
-        private static bool TryCastToImmutableList(IEnumerable<T> sequence, out ImmutableList<T> other)
+        private static bool TryCastToImmutableList(IEnumerable<T> sequence, [NotNullWhen(true)] out ImmutableList<T>? other)
         {
             other = sequence as ImmutableList<T>;
             if (other != null)
@@ -1163,11 +1165,11 @@ namespace System.Collections.Immutable
         /// <devremarks>
         /// This implementation comes from <see cref="List{T}"/>.
         /// </devremarks>
-        private static bool IsCompatibleObject(object value)
+        private static bool IsCompatibleObject(object? value)
         {
             // Non-null values are fine.  Only accept nulls if T is a class or Nullable<U>.
             // Note that default(T) is not equal to null for value types except when T is Nullable<U>.
-            return ((value is T) || (value == null && default(T) == null));
+            return ((value is T) || (value == null && default(T)! == null));
         }
 
         /// <summary>
@@ -1197,7 +1199,7 @@ namespace System.Collections.Immutable
         {
             // If the items being added actually come from an ImmutableList<T>
             // then there is no value in reconstructing it.
-            if (TryCastToImmutableList(items, out ImmutableList<T> other))
+            if (TryCastToImmutableList(items, out ImmutableList<T>? other))
             {
                 return other;
             }
index 1c17181..f0545f2 100644 (file)
@@ -23,13 +23,13 @@ namespace System.Collections.Immutable
             /// <summary>
             /// The remaining forwards stack of the queue being enumerated.
             /// </summary>
-            private ImmutableStack<T> _remainingForwardsStack;
+            private ImmutableStack<T>? _remainingForwardsStack;
 
             /// <summary>
             /// The remaining backwards stack of the queue being enumerated.
             /// Its order is reversed when the field is first initialized.
             /// </summary>
-            private ImmutableStack<T> _remainingBackwardsStack;
+            private ImmutableStack<T>? _remainingBackwardsStack;
 
             /// <summary>
             /// Initializes a new instance of the <see cref="Enumerator"/> struct.
@@ -61,7 +61,7 @@ namespace System.Collections.Immutable
                     {
                         return _remainingForwardsStack.Peek();
                     }
-                    else if (!_remainingBackwardsStack.IsEmpty)
+                    else if (!_remainingBackwardsStack!.IsEmpty)
                     {
                         return _remainingBackwardsStack.Peek();
                     }
@@ -90,12 +90,12 @@ namespace System.Collections.Immutable
                 {
                     _remainingForwardsStack = _remainingForwardsStack.Pop();
                 }
-                else if (!_remainingBackwardsStack.IsEmpty)
+                else if (!_remainingBackwardsStack!.IsEmpty)
                 {
                     _remainingBackwardsStack = _remainingBackwardsStack.Pop();
                 }
 
-                return !_remainingForwardsStack.IsEmpty || !_remainingBackwardsStack.IsEmpty;
+                return !_remainingForwardsStack.IsEmpty || !_remainingBackwardsStack!.IsEmpty;
             }
         }
 
@@ -112,13 +112,13 @@ namespace System.Collections.Immutable
             /// <summary>
             /// The remaining forwards stack of the queue being enumerated.
             /// </summary>
-            private ImmutableStack<T> _remainingForwardsStack;
+            private ImmutableStack<T>? _remainingForwardsStack;
 
             /// <summary>
             /// The remaining backwards stack of the queue being enumerated.
             /// Its order is reversed when the field is first initialized.
             /// </summary>
-            private ImmutableStack<T> _remainingBackwardsStack;
+            private ImmutableStack<T>? _remainingBackwardsStack;
 
             /// <summary>
             /// A value indicating whether this enumerator has been disposed.
@@ -152,7 +152,7 @@ namespace System.Collections.Immutable
                     {
                         return _remainingForwardsStack.Peek();
                     }
-                    else if (!_remainingBackwardsStack.IsEmpty)
+                    else if (!_remainingBackwardsStack!.IsEmpty)
                     {
                         return _remainingBackwardsStack.Peek();
                     }
@@ -169,7 +169,7 @@ namespace System.Collections.Immutable
             /// </summary>
             object IEnumerator.Current
             {
-                get { return this.Current; }
+                get { return this.Current!; }
             }
 
             /// <summary>
@@ -190,12 +190,12 @@ namespace System.Collections.Immutable
                 {
                     _remainingForwardsStack = _remainingForwardsStack.Pop();
                 }
-                else if (!_remainingBackwardsStack.IsEmpty)
+                else if (!_remainingBackwardsStack!.IsEmpty)
                 {
                     _remainingBackwardsStack = _remainingBackwardsStack.Pop();
                 }
 
-                return !_remainingForwardsStack.IsEmpty || !_remainingBackwardsStack.IsEmpty;
+                return !_remainingForwardsStack.IsEmpty || !_remainingBackwardsStack!.IsEmpty;
             }
 
             /// <summary>
index 92eb566..2a894af 100644 (file)
@@ -42,7 +42,7 @@ namespace System.Collections.Immutable
         /// <summary>
         /// Backing field for the <see cref="BackwardsReversed"/> property.
         /// </summary>
-        private ImmutableStack<T> _backwardsReversed;
+        private ImmutableStack<T>? _backwardsReversed;
 
         /// <summary>
         /// Initializes a new instance of the <see cref="ImmutableQueue{T}"/> class.
index 6303b91..e5881df 100644 (file)
@@ -22,7 +22,7 @@ namespace System.Collections.Immutable
         /// <typeparam name="TValue">The type of values stored by the dictionary.</typeparam>
         /// <returns>The immutable collection.</returns>
         [Pure]
-        public static ImmutableSortedDictionary<TKey, TValue> Create<TKey, TValue>()
+        public static ImmutableSortedDictionary<TKey, TValue> Create<TKey, TValue>() where TKey : notnull
         {
             return ImmutableSortedDictionary<TKey, TValue>.Empty;
         }
@@ -35,7 +35,7 @@ namespace System.Collections.Immutable
         /// <param name="keyComparer">The key comparer.</param>
         /// <returns>The immutable collection.</returns>
         [Pure]
-        public static ImmutableSortedDictionary<TKey, TValue> Create<TKey, TValue>(IComparer<TKey> keyComparer)
+        public static ImmutableSortedDictionary<TKey, TValue> Create<TKey, TValue>(IComparer<TKey>? keyComparer) where TKey : notnull
         {
             return ImmutableSortedDictionary<TKey, TValue>.Empty.WithComparers(keyComparer);
         }
@@ -49,7 +49,7 @@ namespace System.Collections.Immutable
         /// <param name="valueComparer">The value comparer.</param>
         /// <returns>The immutable collection.</returns>
         [Pure]
-        public static ImmutableSortedDictionary<TKey, TValue> Create<TKey, TValue>(IComparer<TKey> keyComparer, IEqualityComparer<TValue> valueComparer)
+        public static ImmutableSortedDictionary<TKey, TValue> Create<TKey, TValue>(IComparer<TKey>? keyComparer, IEqualityComparer<TValue>? valueComparer) where TKey : notnull
         {
             return ImmutableSortedDictionary<TKey, TValue>.Empty.WithComparers(keyComparer, valueComparer);
         }
@@ -63,7 +63,7 @@ namespace System.Collections.Immutable
         /// <returns>The new immutable collection.</returns>
         [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
         [Pure]
-        public static ImmutableSortedDictionary<TKey, TValue> CreateRange<TKey, TValue>(IEnumerable<KeyValuePair<TKey, TValue>> items)
+        public static ImmutableSortedDictionary<TKey, TValue> CreateRange<TKey, TValue>(IEnumerable<KeyValuePair<TKey, TValue>> items) where TKey : notnull
         {
             return ImmutableSortedDictionary<TKey, TValue>.Empty.AddRange(items);
         }
@@ -78,7 +78,7 @@ namespace System.Collections.Immutable
         /// <returns>The new immutable collection.</returns>
         [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
         [Pure]
-        public static ImmutableSortedDictionary<TKey, TValue> CreateRange<TKey, TValue>(IComparer<TKey> keyComparer, IEnumerable<KeyValuePair<TKey, TValue>> items)
+        public static ImmutableSortedDictionary<TKey, TValue> CreateRange<TKey, TValue>(IComparer<TKey>? keyComparer, IEnumerable<KeyValuePair<TKey, TValue>> items) where TKey : notnull
         {
             return ImmutableSortedDictionary<TKey, TValue>.Empty.WithComparers(keyComparer).AddRange(items);
         }
@@ -94,7 +94,7 @@ namespace System.Collections.Immutable
         /// <returns>The new immutable collection.</returns>
         [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
         [Pure]
-        public static ImmutableSortedDictionary<TKey, TValue> CreateRange<TKey, TValue>(IComparer<TKey> keyComparer, IEqualityComparer<TValue> valueComparer, IEnumerable<KeyValuePair<TKey, TValue>> items)
+        public static ImmutableSortedDictionary<TKey, TValue> CreateRange<TKey, TValue>(IComparer<TKey>? keyComparer, IEqualityComparer<TValue>? valueComparer, IEnumerable<KeyValuePair<TKey, TValue>> items) where TKey : notnull
         {
             return ImmutableSortedDictionary<TKey, TValue>.Empty.WithComparers(keyComparer, valueComparer).AddRange(items);
         }
@@ -106,7 +106,7 @@ namespace System.Collections.Immutable
         /// <typeparam name="TValue">The type of values stored by the dictionary.</typeparam>
         /// <returns>The immutable collection builder.</returns>
         [Pure]
-        public static ImmutableSortedDictionary<TKey, TValue>.Builder CreateBuilder<TKey, TValue>()
+        public static ImmutableSortedDictionary<TKey, TValue>.Builder CreateBuilder<TKey, TValue>() where TKey : notnull
         {
             return Create<TKey, TValue>().ToBuilder();
         }
@@ -119,7 +119,7 @@ namespace System.Collections.Immutable
         /// <param name="keyComparer">The key comparer.</param>
         /// <returns>The immutable collection builder.</returns>
         [Pure]
-        public static ImmutableSortedDictionary<TKey, TValue>.Builder CreateBuilder<TKey, TValue>(IComparer<TKey> keyComparer)
+        public static ImmutableSortedDictionary<TKey, TValue>.Builder CreateBuilder<TKey, TValue>(IComparer<TKey>? keyComparer) where TKey : notnull
         {
             return Create<TKey, TValue>(keyComparer).ToBuilder();
         }
@@ -133,7 +133,7 @@ namespace System.Collections.Immutable
         /// <param name="valueComparer">The value comparer.</param>
         /// <returns>The immutable collection builder.</returns>
         [Pure]
-        public static ImmutableSortedDictionary<TKey, TValue>.Builder CreateBuilder<TKey, TValue>(IComparer<TKey> keyComparer, IEqualityComparer<TValue> valueComparer)
+        public static ImmutableSortedDictionary<TKey, TValue>.Builder CreateBuilder<TKey, TValue>(IComparer<TKey>? keyComparer, IEqualityComparer<TValue>? valueComparer) where TKey : notnull
         {
             return Create<TKey, TValue>(keyComparer, valueComparer).ToBuilder();
         }
@@ -151,7 +151,7 @@ namespace System.Collections.Immutable
         /// <param name="valueComparer">The value comparer to use for the map.</param>
         /// <returns>The immutable map.</returns>
         [Pure]
-        public static ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TSource, TKey, TValue>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TValue> elementSelector, IComparer<TKey> keyComparer, IEqualityComparer<TValue> valueComparer)
+        public static ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TSource, TKey, TValue>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TValue> elementSelector, IComparer<TKey>? keyComparer, IEqualityComparer<TValue>? valueComparer) where TKey : notnull
         {
             Requires.NotNull(source, nameof(source));
             Requires.NotNull(keySelector, nameof(keySelector));
@@ -167,7 +167,7 @@ namespace System.Collections.Immutable
         /// <param name="builder">The builder to create the immutable map from.</param>
         /// <returns>An immutable map.</returns>
         [Pure]
-        public static ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TKey, TValue>(this ImmutableSortedDictionary<TKey, TValue>.Builder builder)
+        public static ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TKey, TValue>(this ImmutableSortedDictionary<TKey, TValue>.Builder builder) where TKey : notnull
         {
             Requires.NotNull(builder, nameof(builder));
 
@@ -186,7 +186,7 @@ namespace System.Collections.Immutable
         /// <param name="keyComparer">The key comparer to use for the map.</param>
         /// <returns>The immutable map.</returns>
         [Pure]
-        public static ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TSource, TKey, TValue>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TValue> elementSelector, IComparer<TKey> keyComparer)
+        public static ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TSource, TKey, TValue>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TValue> elementSelector, IComparer<TKey>? keyComparer) where TKey : notnull
         {
             return ToImmutableSortedDictionary(source, keySelector, elementSelector, keyComparer, null);
         }
@@ -202,7 +202,7 @@ namespace System.Collections.Immutable
         /// <param name="elementSelector">The function that will produce the value for the map from each sequence element.</param>
         /// <returns>The immutable map.</returns>
         [Pure]
-        public static ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TSource, TKey, TValue>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TValue> elementSelector)
+        public static ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TSource, TKey, TValue>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TValue> elementSelector) where TKey : notnull
         {
             return ToImmutableSortedDictionary(source, keySelector, elementSelector, null, null);
         }
@@ -218,7 +218,7 @@ namespace System.Collections.Immutable
         /// <returns>An immutable map.</returns>
         [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
         [Pure]
-        public static ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source, IComparer<TKey> keyComparer, IEqualityComparer<TValue> valueComparer)
+        public static ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source, IComparer<TKey>? keyComparer, IEqualityComparer<TValue>? valueComparer) where TKey : notnull
         {
             Requires.NotNull(source, nameof(source));
 
@@ -241,7 +241,7 @@ namespace System.Collections.Immutable
         /// <returns>An immutable map.</returns>
         [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
         [Pure]
-        public static ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source, IComparer<TKey> keyComparer)
+        public static ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source, IComparer<TKey>? keyComparer) where TKey : notnull
         {
             return ToImmutableSortedDictionary(source, keyComparer, null);
         }
@@ -255,7 +255,7 @@ namespace System.Collections.Immutable
         /// <returns>An immutable map.</returns>
         [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
         [Pure]
-        public static ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source)
+        public static ImmutableSortedDictionary<TKey, TValue> ToImmutableSortedDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source) where TKey : notnull
         {
             return ToImmutableSortedDictionary(source, null, null);
         }
index a91ff61..eee40ac 100644 (file)
@@ -13,7 +13,7 @@ namespace System.Collections.Immutable
     /// Contains the inner <see cref="ImmutableSortedDictionary{TKey, TValue}.Builder"/> class.
     /// </content>
     [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix", Justification = "Ignored")]
-    public sealed partial class ImmutableSortedDictionary<TKey, TValue>
+    public sealed partial class ImmutableSortedDictionary<TKey, TValue> where TKey : notnull
     {
         /// <summary>
         /// A sorted dictionary that mutates with little or no memory allocations,
@@ -57,7 +57,7 @@ namespace System.Collections.Immutable
             /// Caches an immutable instance that represents the current state of the collection.
             /// </summary>
             /// <value>Null if no immutable view has been created for the current version.</value>
-            private ImmutableSortedDictionary<TKey, TValue> _immutable;
+            private ImmutableSortedDictionary<TKey, TValue>? _immutable;
 
             /// <summary>
             /// A number that increments every time the builder changes its contents.
@@ -67,7 +67,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// The object callers may use to synchronize access to this collection.
             /// </summary>
-            private object _syncRoot;
+            private object? _syncRoot;
 
             /// <summary>
             /// Initializes a new instance of the <see cref="Builder"/> class.
@@ -183,7 +183,7 @@ namespace System.Collections.Immutable
                 get
                 {
                     TValue value;
-                    if (this.TryGetValue(key, out value))
+                    if (this.TryGetValue(key, out value!))
                     {
                         return value;
                     }
@@ -275,7 +275,7 @@ namespace System.Collections.Immutable
                 {
                     if (_syncRoot == null)
                     {
-                        Threading.Interlocked.CompareExchange<object>(ref _syncRoot, new object(), null);
+                        Threading.Interlocked.CompareExchange<object?>(ref _syncRoot, new object(), null);
                     }
 
                     return _syncRoot;
@@ -365,9 +365,9 @@ namespace System.Collections.Immutable
             /// </summary>
             /// <param name="key">The <see cref="object"/> to use as the key of the element to add.</param>
             /// <param name="value">The <see cref="object"/> to use as the value of the element to add.</param>
-            void IDictionary.Add(object key, object value)
+            void IDictionary.Add(object key, object? value)
             {
-                this.Add((TKey)key, (TValue)value);
+                this.Add((TKey)key, (TValue)value!);
             }
 
             /// <summary>
@@ -407,10 +407,10 @@ namespace System.Collections.Immutable
             /// </summary>
             /// <param name="key">The key.</param>
             /// <returns></returns>
-            object IDictionary.this[object key]
+            object? IDictionary.this[object key]
             {
                 get { return this[(TKey)key]; }
-                set { this[(TKey)key] = (TValue)value; }
+                set { this[(TKey)key] = (TValue)value!; }
             }
 
             #endregion
@@ -470,9 +470,9 @@ namespace System.Collections.Immutable
             /// <summary>
             /// See <see cref="IDictionary{TKey, TValue}"/>
             /// </summary>
-            public bool TryGetValue(TKey key, out TValue value)
+            public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
             {
-                return this.Root.TryGetValue(key, _keyComparer, out value);
+                return this.Root.TryGetValue(key, _keyComparer, out value!);
             }
 
             /// <summary>
@@ -611,9 +611,10 @@ namespace System.Collections.Immutable
             /// <param name="key">The key to search for.</param>
             /// <returns>The value for the key, or the default value for type <typeparamref name="TValue"/> if no matching key was found.</returns>
             [Pure]
+            [return: MaybeNull]
             public TValue GetValueOrDefault(TKey key)
             {
-                return this.GetValueOrDefault(key, default(TValue));
+                return this.GetValueOrDefault(key, default(TValue)!);
             }
 
             /// <summary>
@@ -630,7 +631,7 @@ namespace System.Collections.Immutable
                 Requires.NotNullAllowStructs(key, nameof(key));
 
                 TValue value;
-                if (this.TryGetValue(key, out value))
+                if (this.TryGetValue(key, out value!))
                 {
                     return value;
                 }
@@ -664,7 +665,7 @@ namespace System.Collections.Immutable
     /// <summary>
     /// A simple view of the immutable collection that the debugger can show to the developer.
     /// </summary>
-    internal class ImmutableSortedDictionaryBuilderDebuggerProxy<TKey, TValue>
+    internal class ImmutableSortedDictionaryBuilderDebuggerProxy<TKey, TValue> where TKey : notnull
     {
         /// <summary>
         /// The collection to be enumerated.
@@ -674,7 +675,7 @@ namespace System.Collections.Immutable
         /// <summary>
         /// The simple view of the collection.
         /// </summary>
-        private KeyValuePair<TKey, TValue>[] _contents;
+        private KeyValuePair<TKey, TValue>[]? _contents;
 
         /// <summary>
         /// Initializes a new instance of the <see cref="ImmutableSortedDictionaryBuilderDebuggerProxy{TKey, TValue}"/> class.
index 5b9f7f0..4a46a18 100644 (file)
@@ -4,6 +4,7 @@
 
 using System.Collections.Generic;
 using System.ComponentModel;
+using System.Diagnostics;
 
 namespace System.Collections.Immutable
 {
@@ -37,7 +38,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// The builder being enumerated, if applicable.
             /// </summary>
-            private readonly Builder _builder;
+            private readonly Builder? _builder;
 
             /// <summary>
             /// A unique ID for this instance of this enumerator.
@@ -53,12 +54,12 @@ namespace System.Collections.Immutable
             /// <summary>
             /// The stack to use for enumerating the binary tree.
             /// </summary>
-            private SecurePooledObject<Stack<RefAsValueType<Node>>> _stack;
+            private SecurePooledObject<Stack<RefAsValueType<Node>>>? _stack;
 
             /// <summary>
             /// The node currently selected.
             /// </summary>
-            private Node _current;
+            private Node? _current;
 
             /// <summary>
             /// The version of the builder (when applicable) that is being enumerated.
@@ -70,7 +71,7 @@ namespace System.Collections.Immutable
             /// </summary>
             /// <param name="root">The root of the set to be enumerated.</param>
             /// <param name="builder">The builder, if applicable.</param>
-            internal Enumerator(Node root, Builder builder = null)
+            internal Enumerator(Node root, Builder? builder = null)
             {
                 Requires.NotNull(root, nameof(root));
 
@@ -127,13 +128,12 @@ namespace System.Collections.Immutable
             /// </summary>
             public void Dispose()
             {
-                _root = null;
+                _root = null!;
                 _current = null;
-                Stack<RefAsValueType<Node>> stack;
-                if (_stack != null && _stack.TryUse(ref this, out stack))
+                if (_stack != null && _stack.TryUse(ref this, out Stack<RefAsValueType<Node>>? stack))
                 {
                     stack.ClearFastWhenEmpty();
-                    s_enumeratingStacks.TryAdd(this, _stack);
+                    s_enumeratingStacks.TryAdd(this, _stack!);
                 }
 
                 _stack = null;
@@ -155,7 +155,7 @@ namespace System.Collections.Immutable
                     {
                         Node n = stack.Pop().Value;
                         _current = n;
-                        this.PushLeft(n.Right);
+                        this.PushLeft(n.Right!);
                         return true;
                     }
                 }
@@ -217,11 +217,12 @@ namespace System.Collections.Immutable
             private void PushLeft(Node node)
             {
                 Requires.NotNull(node, nameof(node));
+                Debug.Assert(_stack != null);
                 var stack = _stack.Use(ref this);
                 while (!node.IsEmpty)
                 {
                     stack.Push(new RefAsValueType<Node>(node));
-                    node = node.Left;
+                    node = node.Left!;
                 }
             }
         }
index b4e4349..4872384 100644 (file)
@@ -4,6 +4,7 @@
 
 using System.Collections.Generic;
 using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
 using System.Diagnostics.Contracts;
 using System.Globalization;
 
@@ -25,12 +26,12 @@ namespace System.Collections.Immutable
             /// <summary>
             /// The key associated with this node.
             /// </summary>
-            private readonly TKey _key;
+            private readonly TKey _key = default!;
 
             /// <summary>
             /// The value associated with this node.
             /// </summary>
-            private readonly TValue _value;
+            private readonly TValue _value = default!;
 
             /// <summary>
             /// A value indicating whether this node has been frozen (made immutable).
@@ -49,12 +50,12 @@ namespace System.Collections.Immutable
             /// <summary>
             /// The left tree.
             /// </summary>
-            private Node _left;
+            private Node? _left;
 
             /// <summary>
             /// The right tree.
             /// </summary>
-            private Node _right;
+            private Node? _right;
 
             /// <summary>
             /// Initializes a new instance of the <see cref="ImmutableSortedDictionary{TKey, TValue}.Node"/> class
@@ -109,7 +110,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// Gets the left branch of this node.
             /// </summary>
-            IBinaryTree<KeyValuePair<TKey, TValue>> IBinaryTree<KeyValuePair<TKey, TValue>>.Left
+            IBinaryTree<KeyValuePair<TKey, TValue>>? IBinaryTree<KeyValuePair<TKey, TValue>>.Left
             {
                 get { return _left; }
             }
@@ -117,7 +118,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// Gets the right branch of this node.
             /// </summary>
-            IBinaryTree<KeyValuePair<TKey, TValue>> IBinaryTree<KeyValuePair<TKey, TValue>>.Right
+            IBinaryTree<KeyValuePair<TKey, TValue>>? IBinaryTree<KeyValuePair<TKey, TValue>>.Right
             {
                 get { return _right; }
             }
@@ -130,12 +131,12 @@ namespace System.Collections.Immutable
             /// <summary>
             /// Gets the left branch of this node.
             /// </summary>
-            public Node Left { get { return _left; } }
+            public Node? Left { get { return _left; } }
 
             /// <summary>
             /// Gets the left branch of this node.
             /// </summary>
-            IBinaryTree IBinaryTree.Left
+            IBinaryTree? IBinaryTree.Left
             {
                 get { return _left; }
             }
@@ -143,12 +144,12 @@ namespace System.Collections.Immutable
             /// <summary>
             /// Gets the right branch of this node.
             /// </summary>
-            public Node Right { get { return _right; } }
+            public Node? Right { get { return _right; } }
 
             /// <summary>
             /// Gets the right branch of this node.
             /// </summary>
-            IBinaryTree IBinaryTree.Right
+            IBinaryTree? IBinaryTree.Right
             {
                 get { return _right; }
             }
@@ -358,7 +359,7 @@ namespace System.Collections.Immutable
             /// <param name="value">The value.</param>
             /// <returns>True if the key was found.</returns>
             [Pure]
-            internal bool TryGetValue(TKey key, IComparer<TKey> keyComparer, out TValue value)
+            internal bool TryGetValue(TKey key, IComparer<TKey> keyComparer, [MaybeNullWhen(false)] out TValue value)
             {
                 Requires.NotNullAllowStructs(key, nameof(key));
                 Requires.NotNull(keyComparer, nameof(keyComparer));
@@ -366,7 +367,7 @@ namespace System.Collections.Immutable
                 var match = this.Search(key, keyComparer);
                 if (match.IsEmpty)
                 {
-                    value = default(TValue);
+                    value = default(TValue)!;
                     return false;
                 }
                 else
@@ -484,8 +485,8 @@ namespace System.Collections.Immutable
                 // If this node is frozen, all its descendants must already be frozen.
                 if (!_frozen)
                 {
-                    _left.Freeze();
-                    _right.Freeze();
+                    _left!.Freeze();
+                    _right!.Freeze();
                     _frozen = true;
                 }
             }
@@ -502,7 +503,7 @@ namespace System.Collections.Immutable
                 Requires.NotNull(tree, nameof(tree));
                 Debug.Assert(!tree.IsEmpty);
 
-                if (tree._right.IsEmpty)
+                if (tree._right!.IsEmpty)
                 {
                     return tree;
                 }
@@ -521,7 +522,7 @@ namespace System.Collections.Immutable
                 Requires.NotNull(tree, nameof(tree));
                 Debug.Assert(!tree.IsEmpty);
 
-                if (tree._left.IsEmpty)
+                if (tree._left!.IsEmpty)
                 {
                     return tree;
                 }
@@ -540,7 +541,7 @@ namespace System.Collections.Immutable
                 Requires.NotNull(tree, nameof(tree));
                 Debug.Assert(!tree.IsEmpty);
 
-                if (tree._right.IsEmpty)
+                if (tree._right!.IsEmpty)
                 {
                     return tree;
                 }
@@ -559,7 +560,7 @@ namespace System.Collections.Immutable
                 Requires.NotNull(tree, nameof(tree));
                 Debug.Assert(!tree.IsEmpty);
 
-                if (tree._left.IsEmpty)
+                if (tree._left!.IsEmpty)
                 {
                     return tree;
                 }
@@ -579,7 +580,7 @@ namespace System.Collections.Immutable
                 Requires.NotNull(tree, nameof(tree));
                 Debug.Assert(!tree.IsEmpty);
 
-                return tree._right._height - tree._left._height;
+                return tree._right!._height - tree._left!._height;
             }
 
             /// <summary>
@@ -621,12 +622,12 @@ namespace System.Collections.Immutable
 
                 if (IsRightHeavy(tree))
                 {
-                    return Balance(tree._right) < 0 ? DoubleLeft(tree) : RotateLeft(tree);
+                    return Balance(tree._right!) < 0 ? DoubleLeft(tree) : RotateLeft(tree);
                 }
 
                 if (IsLeftHeavy(tree))
                 {
-                    return Balance(tree._left) > 0 ? DoubleRight(tree) : RotateRight(tree);
+                    return Balance(tree._left!) > 0 ? DoubleRight(tree) : RotateRight(tree);
                 }
 
                 return tree;
@@ -689,7 +690,7 @@ namespace System.Collections.Immutable
                     int compareResult = keyComparer.Compare(key, _key);
                     if (compareResult > 0)
                     {
-                        var newRight = _right.SetOrAdd(key, value, keyComparer, valueComparer, overwriteExistingValue, out replacedExistingValue, out mutated);
+                        var newRight = _right!.SetOrAdd(key, value, keyComparer, valueComparer, overwriteExistingValue, out replacedExistingValue, out mutated);
                         if (mutated)
                         {
                             result = this.Mutate(right: newRight);
@@ -697,7 +698,7 @@ namespace System.Collections.Immutable
                     }
                     else if (compareResult < 0)
                     {
-                        var newLeft = _left.SetOrAdd(key, value, keyComparer, valueComparer, overwriteExistingValue, out replacedExistingValue, out mutated);
+                        var newLeft = _left!.SetOrAdd(key, value, keyComparer, valueComparer, overwriteExistingValue, out replacedExistingValue, out mutated);
                         if (mutated)
                         {
                             result = this.Mutate(left: newLeft);
@@ -714,7 +715,7 @@ namespace System.Collections.Immutable
                         {
                             mutated = true;
                             replacedExistingValue = true;
-                            result = new Node(key, value, _left, _right);
+                            result = new Node(key, value, _left!, _right!);
                         }
                         else
                         {
@@ -743,6 +744,7 @@ namespace System.Collections.Immutable
                 }
                 else
                 {
+                    Debug.Assert(_right != null && _left != null);
                     Node result = this;
                     int compare = keyComparer.Compare(key, _key);
                     if (compare == 0)
@@ -770,7 +772,7 @@ namespace System.Collections.Immutable
                             // We have two children. Remove the next-highest node and replace
                             // this node with it.
                             var successor = _right;
-                            while (!successor._left.IsEmpty)
+                            while (!successor._left!.IsEmpty)
                             {
                                 successor = successor._left;
                             }
@@ -808,8 +810,9 @@ namespace System.Collections.Immutable
             /// <param name="left">The left branch of the mutated node.</param>
             /// <param name="right">The right branch of the mutated node.</param>
             /// <returns>The mutated (or created) node.</returns>
-            private Node Mutate(Node left = null, Node right = null)
+            private Node Mutate(Node? left = null, Node? right = null)
             {
+                Debug.Assert(_left != null && _right != null);
                 if (_frozen)
                 {
                     return new Node(_key, _value, left ?? _left, right ?? _right);
@@ -854,11 +857,11 @@ namespace System.Collections.Immutable
                     }
                     else if (compare > 0)
                     {
-                        return _right.Search(key, keyComparer);
+                        return _right!.Search(key, keyComparer);
                     }
                     else
                     {
-                        return _left.Search(key, keyComparer);
+                        return _left!.Search(key, keyComparer);
                     }
                 }
             }
index f87a5f8..af7c482 100644 (file)
@@ -51,7 +51,7 @@ namespace System.Collections.Immutable
         /// </summary>
         /// <param name="keyComparer">The key comparer.</param>
         /// <param name="valueComparer">The value comparer.</param>
-        internal ImmutableSortedDictionary(IComparer<TKey> keyComparer = null, IEqualityComparer<TValue> valueComparer = null)
+        internal ImmutableSortedDictionary(IComparer<TKey>? keyComparer = null, IEqualityComparer<TValue>? valueComparer = null)
         {
             _keyComparer = keyComparer ?? Comparer<TKey>.Default;
             _valueComparer = valueComparer ?? EqualityComparer<TValue>.Default;
@@ -343,7 +343,7 @@ namespace System.Collections.Immutable
         /// See the <see cref="IImmutableDictionary{TKey, TValue}"/> interface.
         /// </summary>
         [Pure]
-        public ImmutableSortedDictionary<TKey, TValue> WithComparers(IComparer<TKey> keyComparer, IEqualityComparer<TValue> valueComparer)
+        public ImmutableSortedDictionary<TKey, TValue> WithComparers(IComparer<TKey>? keyComparer, IEqualityComparer<TValue>? valueComparer)
         {
             if (keyComparer == null)
             {
@@ -382,7 +382,7 @@ namespace System.Collections.Immutable
         /// See the <see cref="IImmutableDictionary{TKey, TValue}"/> interface.
         /// </summary>
         [Pure]
-        public ImmutableSortedDictionary<TKey, TValue> WithComparers(IComparer<TKey> keyComparer)
+        public ImmutableSortedDictionary<TKey, TValue> WithComparers(IComparer<TKey>? keyComparer)
         {
             return this.WithComparers(keyComparer, _valueComparer);
         }
@@ -484,10 +484,10 @@ namespace System.Collections.Immutable
         /// <summary>
         /// See the <see cref="IImmutableDictionary{TKey, TValue}"/> interface.
         /// </summary>
-        public bool TryGetValue(TKey key, out TValue value)
+        public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
         {
             Requires.NotNullAllowStructs(key, nameof(key));
-            return _root.TryGetValue(key, _keyComparer, out value);
+            return _root.TryGetValue(key, _keyComparer, out value!);
         }
 
         /// <summary>
@@ -623,7 +623,7 @@ namespace System.Collections.Immutable
         /// </summary>
         /// <param name="key">The <see cref="object"/> to use as the key of the element to add.</param>
         /// <param name="value">The <see cref="object"/> to use as the value of the element to add.</param>
-        void IDictionary.Add(object key, object value)
+        void IDictionary.Add(object key, object? value)
         {
             throw new NotSupportedException();
         }
@@ -665,7 +665,7 @@ namespace System.Collections.Immutable
         /// </summary>
         /// <param name="key">The key.</param>
         /// <returns></returns>
-        object IDictionary.this[object key]
+        object? IDictionary.this[object key]
         {
             get { return this[(TKey)key]; }
             set { throw new NotSupportedException(); }
@@ -792,7 +792,7 @@ namespace System.Collections.Immutable
         /// <param name="sequence">The sequence that may have come from an immutable map.</param>
         /// <param name="other">Receives the concrete <see cref="ImmutableSortedDictionary{TKey, TValue}"/> typed value if one can be found.</param>
         /// <returns><c>true</c> if the cast was successful; <c>false</c> otherwise.</returns>
-        private static bool TryCastToImmutableMap(IEnumerable<KeyValuePair<TKey, TValue>> sequence, out ImmutableSortedDictionary<TKey, TValue> other)
+        private static bool TryCastToImmutableMap(IEnumerable<KeyValuePair<TKey, TValue>> sequence, [NotNullWhen(true)] out ImmutableSortedDictionary<TKey, TValue>? other)
         {
             other = sequence as ImmutableSortedDictionary<TKey, TValue>;
             if (other != null)
@@ -800,8 +800,7 @@ namespace System.Collections.Immutable
                 return true;
             }
 
-            var builder = sequence as Builder;
-            if (builder != null)
+            if (sequence is Builder builder)
             {
                 other = builder.ToImmutable();
                 return true;
@@ -881,15 +880,14 @@ namespace System.Collections.Immutable
 
             // If the items being added actually come from an ImmutableSortedSet<T>,
             // and the sort order is equivalent, then there is no value in reconstructing it.
-            ImmutableSortedDictionary<TKey, TValue> other;
+            ImmutableSortedDictionary<TKey, TValue>? other;
             if (TryCastToImmutableMap(items, out other))
             {
                 return other.WithComparers(this.KeyComparer, this.ValueComparer);
             }
 
-            var itemsAsDictionary = items as IDictionary<TKey, TValue>;
             SortedDictionary<TKey, TValue> dictionary;
-            if (itemsAsDictionary != null)
+            if (items is IDictionary<TKey, TValue> itemsAsDictionary)
             {
                 dictionary = new SortedDictionary<TKey, TValue>(itemsAsDictionary, this.KeyComparer);
             }
@@ -905,7 +903,7 @@ namespace System.Collections.Immutable
                     else
                     {
                         TValue value;
-                        if (dictionary.TryGetValue(item.Key, out value))
+                        if (dictionary.TryGetValue(item.Key, out value!))
                         {
                             if (!_valueComparer.Equals(value, item.Value))
                             {
index 000e1ee..7bf8d4f 100644 (file)
@@ -32,7 +32,7 @@ namespace System.Collections.Immutable
         /// The immutable collection.
         /// </returns>
         [Pure]
-        public static ImmutableSortedSet<T> Create<T>(IComparer<T> comparer)
+        public static ImmutableSortedSet<T> Create<T>(IComparer<T>? comparer)
         {
             return ImmutableSortedSet<T>.Empty.WithComparer(comparer);
         }
@@ -57,7 +57,7 @@ namespace System.Collections.Immutable
         /// <param name="item">The item to prepopulate.</param>
         /// <returns>The new immutable collection.</returns>
         [Pure]
-        public static ImmutableSortedSet<T> Create<T>(IComparer<T> comparer, T item)
+        public static ImmutableSortedSet<T> Create<T>(IComparer<T>? comparer, T item)
         {
             return ImmutableSortedSet<T>.Empty.WithComparer(comparer).Add(item);
         }
@@ -82,7 +82,7 @@ namespace System.Collections.Immutable
         /// <param name="items">The items to prepopulate.</param>
         /// <returns>The new immutable collection.</returns>
         [Pure]
-        public static ImmutableSortedSet<T> CreateRange<T>(IComparer<T> comparer, IEnumerable<T> items)
+        public static ImmutableSortedSet<T> CreateRange<T>(IComparer<T>? comparer, IEnumerable<T> items)
         {
             return ImmutableSortedSet<T>.Empty.WithComparer(comparer).Union(items);
         }
@@ -107,7 +107,7 @@ namespace System.Collections.Immutable
         /// <param name="items">The items to prepopulate.</param>
         /// <returns>The new immutable collection.</returns>
         [Pure]
-        public static ImmutableSortedSet<T> Create<T>(IComparer<T> comparer, params T[] items)
+        public static ImmutableSortedSet<T> Create<T>(IComparer<T>? comparer, params T[] items)
         {
             return ImmutableSortedSet<T>.Empty.WithComparer(comparer).Union(items);
         }
@@ -132,7 +132,7 @@ namespace System.Collections.Immutable
         /// The immutable collection.
         /// </returns>
         [Pure]
-        public static ImmutableSortedSet<T>.Builder CreateBuilder<T>(IComparer<T> comparer)
+        public static ImmutableSortedSet<T>.Builder CreateBuilder<T>(IComparer<T>? comparer)
         {
             return Create<T>(comparer).ToBuilder();
         }
@@ -145,10 +145,9 @@ namespace System.Collections.Immutable
         /// <param name="comparer">The comparer to use for initializing and adding members to the sorted set.</param>
         /// <returns>An immutable set.</returns>
         [Pure]
-        public static ImmutableSortedSet<TSource> ToImmutableSortedSet<TSource>(this IEnumerable<TSource> source, IComparer<TSource> comparer)
+        public static ImmutableSortedSet<TSource> ToImmutableSortedSet<TSource>(this IEnumerable<TSource> source, IComparer<TSource>? comparer)
         {
-            var existingSet = source as ImmutableSortedSet<TSource>;
-            if (existingSet != null)
+            if (source is ImmutableSortedSet<TSource> existingSet)
             {
                 return existingSet.WithComparer(comparer);
             }
index f392be6..a31de70 100644 (file)
@@ -49,7 +49,7 @@ namespace System.Collections.Immutable
             /// Caches an immutable instance that represents the current state of the collection.
             /// </summary>
             /// <value>Null if no immutable view has been created for the current version.</value>
-            private ImmutableSortedSet<T> _immutable;
+            private ImmutableSortedSet<T>? _immutable;
 
             /// <summary>
             /// A number that increments every time the builder changes its contents.
@@ -59,7 +59,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// The object callers may use to synchronize access to this collection.
             /// </summary>
-            private object _syncRoot;
+            private object? _syncRoot;
 
             /// <summary>
             /// Initializes a new instance of the <see cref="Builder"/> class.
@@ -128,6 +128,7 @@ namespace System.Collections.Immutable
             /// Gets the maximum value in the collection, as defined by the comparer.
             /// </summary>
             /// <value>The maximum value in the set.</value>
+            [MaybeNull]
             public T Max
             {
                 get { return _root.Max; }
@@ -137,6 +138,7 @@ namespace System.Collections.Immutable
             /// Gets the minimum value in the collection, as defined by the comparer.
             /// </summary>
             /// <value>The minimum value in the set.</value>
+            [MaybeNull]
             public T Min
             {
                 get { return _root.Min; }
@@ -492,7 +494,7 @@ namespace System.Collections.Immutable
                 {
                     if (_syncRoot == null)
                     {
-                        Threading.Interlocked.CompareExchange<object>(ref _syncRoot, new object(), null);
+                        Threading.Interlocked.CompareExchange<object?>(ref _syncRoot, new object(), null);
                     }
 
                     return _syncRoot;
index eced4fe..ae73b59 100644 (file)
@@ -37,7 +37,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// The builder being enumerated, if applicable.
             /// </summary>
-            private readonly Builder _builder;
+            private readonly Builder? _builder;
 
             /// <summary>
             /// A unique ID for this instance of this enumerator.
@@ -66,12 +66,12 @@ namespace System.Collections.Immutable
             ///   clr!ArrayStoreCheck
             ///     clr!ObjIsInstanceOf
             /// </remarks>
-            private SecurePooledObject<Stack<RefAsValueType<Node>>> _stack;
+            private SecurePooledObject<Stack<RefAsValueType<Node>>>? _stack;
 
             /// <summary>
             /// The node currently selected.
             /// </summary>
-            private Node _current;
+            private Node? _current;
 
             /// <summary>
             /// The version of the builder (when applicable) that is being enumerated.
@@ -84,7 +84,7 @@ namespace System.Collections.Immutable
             /// <param name="root">The root of the set to be enumerated.</param>
             /// <param name="builder">The builder, if applicable.</param>
             /// <param name="reverse"><c>true</c> to enumerate the collection in reverse.</param>
-            internal Enumerator(Node root, Builder builder = null, bool reverse = false)
+            internal Enumerator(Node root, Builder? builder = null, bool reverse = false)
             {
                 Requires.NotNull(root, nameof(root));
 
@@ -129,7 +129,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// The current element.
             /// </summary>
-            object System.Collections.IEnumerator.Current
+            object? System.Collections.IEnumerator.Current
             {
                 get { return this.Current; }
             }
@@ -139,13 +139,12 @@ namespace System.Collections.Immutable
             /// </summary>
             public void Dispose()
             {
-                _root = null;
+                _root = null!;
                 _current = null;
-                Stack<RefAsValueType<Node>> stack;
-                if (_stack != null && _stack.TryUse(ref this, out stack))
+                if (_stack != null && _stack.TryUse(ref this, out Stack<RefAsValueType<Node>>? stack))
                 {
                     stack.ClearFastWhenEmpty();
-                    s_enumeratingStacks.TryAdd(this, _stack);
+                    s_enumeratingStacks.TryAdd(this, _stack!);
                     _stack = null;
                 }
             }
@@ -159,12 +158,12 @@ namespace System.Collections.Immutable
                 this.ThrowIfDisposed();
                 this.ThrowIfChanged();
 
-                var stack = _stack.Use(ref this);
+                var stack = _stack!.Use(ref this);
                 if (stack.Count > 0)
                 {
                     Node n = stack.Pop().Value;
                     _current = n;
-                    this.PushNext(_reverse ? n.Left : n.Right);
+                    this.PushNext(_reverse ? n.Left! : n.Right!);
                     return true;
                 }
                 else
@@ -183,7 +182,7 @@ namespace System.Collections.Immutable
 
                 _enumeratingBuilderVersion = _builder != null ? _builder.Version : -1;
                 _current = null;
-                var stack = _stack.Use(ref this);
+                var stack = _stack!.Use(ref this);
                 stack.ClearFastWhenEmpty();
                 this.PushNext(_root);
             }
@@ -224,11 +223,11 @@ namespace System.Collections.Immutable
             private void PushNext(Node node)
             {
                 Requires.NotNull(node, nameof(node));
-                var stack = _stack.Use(ref this);
+                var stack = _stack!.Use(ref this);
                 while (!node.IsEmpty)
                 {
                     stack.Push(new RefAsValueType<Node>(node));
-                    node = _reverse ? node.Right : node.Left;
+                    node = _reverse ? node.Right! : node.Left!;
                 }
             }
         }
index ed5a5eb..c08056e 100644 (file)
@@ -25,7 +25,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// The key associated with this node.
             /// </summary>
-            private readonly T _key;
+            private readonly T _key = default!;
 
             /// <summary>
             /// A value indicating whether this node has been frozen (made immutable).
@@ -55,12 +55,12 @@ namespace System.Collections.Immutable
             /// <summary>
             /// The left tree.
             /// </summary>
-            private Node _left;
+            private Node? _left;
 
             /// <summary>
             /// The right tree.
             /// </summary>
-            private Node _right;
+            private Node? _right;
 
             /// <summary>
             /// Initializes a new instance of the <see cref="ImmutableSortedSet{T}.Node"/> class
@@ -116,7 +116,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// Gets the left branch of this node.
             /// </summary>
-            public Node Left
+            public Node? Left
             {
                 get { return _left; }
             }
@@ -124,7 +124,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// Gets the left branch of this node.
             /// </summary>
-            IBinaryTree IBinaryTree.Left
+            IBinaryTree? IBinaryTree.Left
             {
                 get { return _left; }
             }
@@ -132,7 +132,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// Gets the right branch of this node.
             /// </summary>
-            public Node Right
+            public Node? Right
             {
                 get { return _right; }
             }
@@ -140,7 +140,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// Gets the right branch of this node.
             /// </summary>
-            IBinaryTree IBinaryTree.Right
+            IBinaryTree? IBinaryTree.Right
             {
                 get { return _right; }
             }
@@ -148,7 +148,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// Gets the left branch of this node.
             /// </summary>
-            IBinaryTree<T> IBinaryTree<T>.Left
+            IBinaryTree<T>? IBinaryTree<T>.Left
             {
                 get { return _left; }
             }
@@ -156,7 +156,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// Gets the right branch of this node.
             /// </summary>
-            IBinaryTree<T> IBinaryTree<T>.Right
+            IBinaryTree<T>? IBinaryTree<T>.Right
             {
                 get { return _right; }
             }
@@ -186,17 +186,18 @@ namespace System.Collections.Immutable
             /// Gets the maximum value in the collection, as defined by the comparer.
             /// </summary>
             /// <value>The maximum value in the set.</value>
+            [MaybeNull]
             internal T Max
             {
                 get
                 {
                     if (this.IsEmpty)
                     {
-                        return default(T);
+                        return default(T)!;
                     }
 
                     Node n = this;
-                    while (!n._right.IsEmpty)
+                    while (!n._right!.IsEmpty)
                     {
                         n = n._right;
                     }
@@ -209,17 +210,18 @@ namespace System.Collections.Immutable
             /// Gets the minimum value in the collection, as defined by the comparer.
             /// </summary>
             /// <value>The minimum value in the set.</value>
+            [MaybeNull]
             internal T Min
             {
                 get
                 {
                     if (this.IsEmpty)
                     {
-                        return default(T);
+                        return default(T)!;
                     }
 
                     Node n = this;
-                    while (!n._left.IsEmpty)
+                    while (!n._left!.IsEmpty)
                     {
                         n = n._left;
                     }
@@ -238,6 +240,7 @@ namespace System.Collections.Immutable
                 get
                 {
                     Requires.Range(index >= 0 && index < this.Count, nameof(index));
+                    Debug.Assert(_left != null && _right != null);
 
                     if (index < _left._count)
                     {
@@ -262,6 +265,7 @@ namespace System.Collections.Immutable
             internal ref readonly T ItemRef(int index)
             {
                 Requires.Range(index >= 0 && index < this.Count, nameof(index));
+                Debug.Assert(_left != null && _right != null);
 
                 if (index < _left._count)
                 {
@@ -379,7 +383,7 @@ namespace System.Collections.Immutable
                     int compareResult = comparer.Compare(key, _key);
                     if (compareResult > 0)
                     {
-                        var newRight = _right.Add(key, comparer, out mutated);
+                        var newRight = _right!.Add(key, comparer, out mutated);
                         if (mutated)
                         {
                             result = this.Mutate(right: newRight);
@@ -387,7 +391,7 @@ namespace System.Collections.Immutable
                     }
                     else if (compareResult < 0)
                     {
-                        var newLeft = _left.Add(key, comparer, out mutated);
+                        var newLeft = _left!.Add(key, comparer, out mutated);
                         if (mutated)
                         {
                             result = this.Mutate(left: newLeft);
@@ -421,6 +425,7 @@ namespace System.Collections.Immutable
                 }
                 else
                 {
+                    Debug.Assert(_left != null && _right != null);
                     Node result = this;
                     int compare = comparer.Compare(key, _key);
                     if (compare == 0)
@@ -448,7 +453,7 @@ namespace System.Collections.Immutable
                             // We have two children. Remove the next-highest node and replace
                             // this node with it.
                             var successor = _right;
-                            while (!successor._left.IsEmpty)
+                            while (!successor._left!.IsEmpty)
                             {
                                 successor = successor._left;
                             }
@@ -502,6 +507,7 @@ namespace System.Collections.Immutable
                 // If this node is frozen, all its descendants must already be frozen.
                 if (!_frozen)
                 {
+                    Debug.Assert(_left != null && _right != null);
                     _left.Freeze();
                     _right.Freeze();
                     _frozen = true;
@@ -532,11 +538,11 @@ namespace System.Collections.Immutable
                     }
                     else if (compare > 0)
                     {
-                        return _right.Search(key, comparer);
+                        return _right!.Search(key, comparer);
                     }
                     else
                     {
-                        return _left.Search(key, comparer);
+                        return _left!.Search(key, comparer);
                     }
                 }
             }
@@ -558,6 +564,7 @@ namespace System.Collections.Immutable
                 }
                 else
                 {
+                    Debug.Assert(_left != null && _right != null);
                     int compare = comparer.Compare(key, _key);
                     if (compare == 0)
                     {
@@ -613,13 +620,13 @@ namespace System.Collections.Immutable
                 Requires.NotNull(tree, nameof(tree));
                 Debug.Assert(!tree.IsEmpty);
 
-                if (tree._right.IsEmpty)
+                if (tree._right!.IsEmpty)
                 {
                     return tree;
                 }
 
                 var right = tree._right;
-                return right.Mutate(left: tree.Mutate(right: right._left));
+                return right.Mutate(left: tree.Mutate(right: right._left!));
             }
 
             /// <summary>
@@ -632,13 +639,13 @@ namespace System.Collections.Immutable
                 Requires.NotNull(tree, nameof(tree));
                 Debug.Assert(!tree.IsEmpty);
 
-                if (tree._left.IsEmpty)
+                if (tree._left!.IsEmpty)
                 {
                     return tree;
                 }
 
                 var left = tree._left;
-                return left.Mutate(right: tree.Mutate(left: left._right));
+                return left.Mutate(right: tree.Mutate(left: left._right!));
             }
 
             /// <summary>
@@ -651,7 +658,7 @@ namespace System.Collections.Immutable
                 Requires.NotNull(tree, nameof(tree));
                 Debug.Assert(!tree.IsEmpty);
 
-                if (tree._right.IsEmpty)
+                if (tree._right!.IsEmpty)
                 {
                     return tree;
                 }
@@ -670,7 +677,7 @@ namespace System.Collections.Immutable
                 Requires.NotNull(tree, nameof(tree));
                 Debug.Assert(!tree.IsEmpty);
 
-                if (tree._left.IsEmpty)
+                if (tree._left!.IsEmpty)
                 {
                     return tree;
                 }
@@ -690,7 +697,7 @@ namespace System.Collections.Immutable
                 Requires.NotNull(tree, nameof(tree));
                 Debug.Assert(!tree.IsEmpty);
 
-                return tree._right._height - tree._left._height;
+                return tree._right!._height - tree._left!._height;
             }
 
             /// <summary>
@@ -732,12 +739,12 @@ namespace System.Collections.Immutable
 
                 if (IsRightHeavy(tree))
                 {
-                    return Balance(tree._right) < 0 ? DoubleLeft(tree) : RotateLeft(tree);
+                    return Balance(tree._right!) < 0 ? DoubleLeft(tree) : RotateLeft(tree);
                 }
 
                 if (IsLeftHeavy(tree))
                 {
-                    return Balance(tree._left) > 0 ? DoubleRight(tree) : RotateRight(tree);
+                    return Balance(tree._left!) > 0 ? DoubleRight(tree) : RotateRight(tree);
                 }
 
                 return tree;
@@ -778,8 +785,9 @@ namespace System.Collections.Immutable
             /// <param name="left">The left branch of the mutated node.</param>
             /// <param name="right">The right branch of the mutated node.</param>
             /// <returns>The mutated (or created) node.</returns>
-            private Node Mutate(Node left = null, Node right = null)
+            private Node Mutate(Node? left = null, Node? right = null)
             {
+                Debug.Assert(_left != null && _right != null);
                 if (_frozen)
                 {
                     return new Node(_key, left ?? _left, right ?? _right);
index 6b49ad3..bc1482b 100644 (file)
@@ -50,7 +50,7 @@ namespace System.Collections.Immutable
         /// Initializes a new instance of the <see cref="ImmutableSortedSet{T}"/> class.
         /// </summary>
         /// <param name="comparer">The comparer.</param>
-        internal ImmutableSortedSet(IComparer<T> comparer = null)
+        internal ImmutableSortedSet(IComparer<T>? comparer = null)
         {
             _root = Node.EmptyNode;
             _comparer = comparer ?? Comparer<T>.Default;
@@ -83,6 +83,7 @@ namespace System.Collections.Immutable
         /// Gets the maximum value in the collection, as defined by the comparer.
         /// </summary>
         /// <value>The maximum value in the set.</value>
+        [MaybeNull]
         public T Max
         {
             get { return _root.Max; }
@@ -92,6 +93,7 @@ namespace System.Collections.Immutable
         /// Gets the minimum value in the collection, as defined by the comparer.
         /// </summary>
         /// <value>The minimum value in the set.</value>
+        [MaybeNull]
         public T Min
         {
             get { return _root.Min; }
@@ -317,7 +319,7 @@ namespace System.Collections.Immutable
         {
             Requires.NotNull(other, nameof(other));
 
-            ImmutableSortedSet<T> immutableSortedSet;
+            ImmutableSortedSet<T>? immutableSortedSet;
             if (TryCastToImmutableSortedSet(other, out immutableSortedSet) && immutableSortedSet.KeyComparer == this.KeyComparer) // argument is a compatible immutable sorted set
             {
                 if (immutableSortedSet.IsEmpty)
@@ -354,7 +356,7 @@ namespace System.Collections.Immutable
         /// See the <see cref="IImmutableSet{T}"/> interface.
         /// </summary>
         [Pure]
-        public ImmutableSortedSet<T> WithComparer(IComparer<T> comparer)
+        public ImmutableSortedSet<T> WithComparer(IComparer<T>? comparer)
         {
             if (comparer == null)
             {
@@ -859,7 +861,7 @@ namespace System.Collections.Immutable
         /// The position into which the new element was inserted, or -1 to indicate that the item was not inserted into the collection,
         /// </returns>
         /// <exception cref="System.NotSupportedException"></exception>
-        int IList.Add(object value)
+        int IList.Add(object? value)
         {
             throw new NotSupportedException();
         }
@@ -880,9 +882,9 @@ namespace System.Collections.Immutable
         /// <returns>
         /// true if the <see cref="object"/> is found in the <see cref="IList"/>; otherwise, false.
         /// </returns>
-        bool IList.Contains(object value)
+        bool IList.Contains(object? value)
         {
-            return this.Contains((T)value);
+            return this.Contains((T)value!);
         }
 
         /// <summary>
@@ -892,9 +894,9 @@ namespace System.Collections.Immutable
         /// <returns>
         /// The index of <paramref name="value"/> if found in the list; otherwise, -1.
         /// </returns>
-        int IList.IndexOf(object value)
+        int IList.IndexOf(object? value)
         {
-            return this.IndexOf((T)value);
+            return this.IndexOf((T)value!);
         }
 
         /// <summary>
@@ -903,7 +905,7 @@ namespace System.Collections.Immutable
         /// <param name="index">The zero-based index at which <paramref name="value"/> should be inserted.</param>
         /// <param name="value">The object to insert into the <see cref="IList"/>.</param>
         /// <exception cref="System.NotSupportedException"></exception>
-        void IList.Insert(int index, object value)
+        void IList.Insert(int index, object? value)
         {
             throw new NotSupportedException();
         }
@@ -913,7 +915,7 @@ namespace System.Collections.Immutable
         /// </summary>
         /// <param name="value">The object to remove from the <see cref="IList"/>.</param>
         /// <exception cref="System.NotSupportedException"></exception>
-        void IList.Remove(object value)
+        void IList.Remove(object? value)
         {
             throw new NotSupportedException();
         }
@@ -936,7 +938,7 @@ namespace System.Collections.Immutable
         /// </value>
         /// <param name="index">The index.</param>
         /// <exception cref="System.NotSupportedException"></exception>
-        object IList.this[int index]
+        object? IList.this[int index]
         {
             get { return this[index]; }
             set { throw new NotSupportedException(); }
@@ -1013,7 +1015,7 @@ namespace System.Collections.Immutable
         /// <summary>
         /// Discovers an immutable sorted set for a given value, if possible.
         /// </summary>
-        private static bool TryCastToImmutableSortedSet(IEnumerable<T> sequence, out ImmutableSortedSet<T> other)
+        private static bool TryCastToImmutableSortedSet(IEnumerable<T> sequence, [NotNullWhen(true)] out ImmutableSortedSet<T>? other)
         {
             other = sequence as ImmutableSortedSet<T>;
             if (other != null)
index 5e63d90..78f0c53 100644 (file)
@@ -23,7 +23,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// The remaining stack not yet enumerated.
             /// </summary>
-            private ImmutableStack<T> _remainingStack;
+            private ImmutableStack<T>? _remainingStack;
 
             /// <summary>
             /// Initializes a new instance of the <see cref="Enumerator"/> struct.
@@ -87,7 +87,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// The remaining stack not yet enumerated.
             /// </summary>
-            private ImmutableStack<T> _remainingStack;
+            private ImmutableStack<T>? _remainingStack;
 
             /// <summary>
             /// A flag indicating whether this enumerator has been disposed.
@@ -126,7 +126,7 @@ namespace System.Collections.Immutable
             /// <summary>
             /// Gets the current element.
             /// </summary>
-            object IEnumerator.Current
+            object? IEnumerator.Current
             {
                 get { return this.Current; }
             }
index e133cca..55decdb 100644 (file)
@@ -31,12 +31,13 @@ namespace System.Collections.Immutable
         /// <summary>
         /// The element on the top of the stack.
         /// </summary>
-        private readonly T _head;
+        [MaybeNull]
+        private readonly T _head = default!;
 
         /// <summary>
         /// A stack that contains the rest of the elements (under the top element).
         /// </summary>
-        private readonly ImmutableStack<T> _tail;
+        private readonly ImmutableStack<T>? _tail;
 
         /// <summary>
         /// Initializes a new instance of the <see cref="ImmutableStack{T}"/> class
@@ -114,7 +115,7 @@ namespace System.Collections.Immutable
                 throw new InvalidOperationException(SR.InvalidEmptyOperation);
             }
 
-            return _head;
+            return _head!;
         }
 
 #if !NETSTANDARD1_0
@@ -133,7 +134,7 @@ namespace System.Collections.Immutable
                 throw new InvalidOperationException(SR.InvalidEmptyOperation);
             }
 
-            return ref _head;
+            return ref _head!;
         }
 #endif
 
index 93899cb..46c8ab6 100644 (file)
@@ -13,7 +13,7 @@ namespace System.Collections.Immutable
     /// <typeparam name="TKey">The type of key in the dictionary.</typeparam>
     /// <typeparam name="TValue">The type of value in the dictionary.</typeparam>
     /// <typeparam name="T">Either TKey or TValue.</typeparam>
-    internal abstract class KeysOrValuesCollectionAccessor<TKey, TValue, T> : ICollection<T>, ICollection
+    internal abstract class KeysOrValuesCollectionAccessor<TKey, TValue, T> : ICollection<T>, ICollection where TKey : notnull
     {
         /// <summary>
         /// The underlying wrapped dictionary.
@@ -165,7 +165,7 @@ namespace System.Collections.Immutable
     /// <summary>
     /// A lightweight collection view over and IEnumerable of keys.
     /// </summary>
-    internal sealed class KeysCollectionAccessor<TKey, TValue> : KeysOrValuesCollectionAccessor<TKey, TValue, TKey>
+    internal sealed class KeysCollectionAccessor<TKey, TValue> : KeysOrValuesCollectionAccessor<TKey, TValue, TKey> where TKey : notnull
     {
         /// <summary>
         /// Initializes a new instance of the <see cref="KeysCollectionAccessor{TKey, TValue}"/> class.
@@ -187,7 +187,7 @@ namespace System.Collections.Immutable
     /// <summary>
     /// A lightweight collection view over and IEnumerable of values.
     /// </summary>
-    internal sealed class ValuesCollectionAccessor<TKey, TValue> : KeysOrValuesCollectionAccessor<TKey, TValue, TValue>
+    internal sealed class ValuesCollectionAccessor<TKey, TValue> : KeysOrValuesCollectionAccessor<TKey, TValue, TValue> where TKey : notnull
     {
         /// <summary>
         /// Initializes a new instance of the <see cref="ValuesCollectionAccessor{TKey, TValue}"/> class.
index 03fcf1d..68027c2 100644 (file)
@@ -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.
 
+using System.Diagnostics.CodeAnalysis;
 using System.Runtime.CompilerServices;
 using System.Threading;
 
@@ -51,7 +52,7 @@ namespace System.Collections.Immutable
             }
         }
 
-        public bool TryTake(TCaller caller, out SecurePooledObject<T> item)
+        public bool TryTake(TCaller caller, out SecurePooledObject<T>? item)
         {
             if (caller.PoolUserId != SecureObjectPool.UnassignedId && AllocFreeConcurrentStack<SecurePooledObject<T>>.TryTake(out item))
             {
@@ -114,7 +115,7 @@ namespace System.Collections.Immutable
             return _value;
         }
 
-        internal bool TryUse<TCaller>(ref TCaller caller, out T value)
+        internal bool TryUse<TCaller>(ref TCaller caller, [MaybeNullWhen(false)] out T value)
             where TCaller : struct, ISecurePooledObjectUser
         {
             if (IsOwned(ref caller))
@@ -124,7 +125,7 @@ namespace System.Collections.Immutable
             }
             else
             {
-                value = default(T);
+                value = default(T)!;
                 return false;
             }
         }
index 7ba0db9..0fbb8bc 100644 (file)
@@ -48,12 +48,12 @@ namespace System.Collections.Immutable
             /// <summary>
             /// The stack to use for enumerating the binary tree.
             /// </summary>
-            private SecurePooledObject<Stack<RefAsValueType<SortedInt32KeyNode<TValue>>>> _stack;
+            private SecurePooledObject<Stack<RefAsValueType<SortedInt32KeyNode<TValue>>>>? _stack;
 
             /// <summary>
             /// The node currently selected.
             /// </summary>
-            private SortedInt32KeyNode<TValue> _current;
+            private SortedInt32KeyNode<TValue>? _current;
 
             /// <summary>
             /// Initializes an <see cref="Enumerator"/> structure.
@@ -114,13 +114,12 @@ namespace System.Collections.Immutable
             /// </summary>
             public void Dispose()
             {
-                _root = null;
+                _root = null!;
                 _current = null;
-                Stack<RefAsValueType<SortedInt32KeyNode<TValue>>> stack;
-                if (_stack != null && _stack.TryUse(ref this, out stack))
+                if (_stack != null && _stack.TryUse(ref this, out Stack<RefAsValueType<SortedInt32KeyNode<TValue>>>? stack))
                 {
                     stack.ClearFastWhenEmpty();
-                    s_enumeratingStacks.TryAdd(this, _stack);
+                    s_enumeratingStacks.TryAdd(this, _stack!);
                 }
 
                 _stack = null;
@@ -141,7 +140,7 @@ namespace System.Collections.Immutable
                     {
                         SortedInt32KeyNode<TValue> n = stack.Pop().Value;
                         _current = n;
-                        this.PushLeft(n.Right);
+                        this.PushLeft(n.Right!);
                         return true;
                     }
                 }
@@ -190,11 +189,11 @@ namespace System.Collections.Immutable
             private void PushLeft(SortedInt32KeyNode<TValue> node)
             {
                 Requires.NotNull(node, nameof(node));
-                var stack = _stack.Use(ref this);
+                var stack = _stack!.Use(ref this);
                 while (!node.IsEmpty)
                 {
                     stack.Push(new RefAsValueType<SortedInt32KeyNode<TValue>>(node));
-                    node = node.Left;
+                    node = node.Left!;
                 }
             }
         }
index 8d919ef..8161a23 100644 (file)
@@ -4,6 +4,7 @@
 
 using System.Collections.Generic;
 using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
 using System.Diagnostics.Contracts;
 using System.Globalization;
 
@@ -35,7 +36,8 @@ namespace System.Collections.Immutable
         /// <summary>
         /// The value associated with this node.
         /// </summary>
-        private readonly TValue _value;
+        [MaybeNull]
+        private readonly TValue _value = default!;
 
         /// <summary>
         /// A value indicating whether this node has been frozen (made immutable).
@@ -54,12 +56,12 @@ namespace System.Collections.Immutable
         /// <summary>
         /// The left tree.
         /// </summary>
-        private SortedInt32KeyNode<TValue> _left;
+        private SortedInt32KeyNode<TValue>? _left;
 
         /// <summary>
         /// The right tree.
         /// </summary>
-        private SortedInt32KeyNode<TValue> _right;
+        private SortedInt32KeyNode<TValue>? _right;
 
         /// <summary>
         /// Initializes a new instance of the <see cref="SortedInt32KeyNode{TValue}"/> class that is pre-frozen.
@@ -108,22 +110,22 @@ namespace System.Collections.Immutable
         /// <summary>
         /// Gets the left branch of this node.
         /// </summary>
-        public SortedInt32KeyNode<TValue> Left { get { return _left; } }
+        public SortedInt32KeyNode<TValue>? Left { get { return _left; } }
 
         /// <summary>
         /// Gets the right branch of this node.
         /// </summary>
-        public SortedInt32KeyNode<TValue> Right { get { return _right; } }
+        public SortedInt32KeyNode<TValue>? Right { get { return _right; } }
 
         /// <summary>
         /// Gets the left branch of this node.
         /// </summary>
-        IBinaryTree IBinaryTree.Left { get { return _left; } }
+        IBinaryTree? IBinaryTree.Left { get { return _left; } }
 
         /// <summary>
         /// Gets the right branch of this node.
         /// </summary>
-        IBinaryTree IBinaryTree.Right { get { return _right; } }
+        IBinaryTree? IBinaryTree.Right { get { return _right; } }
 
         /// <summary>
         /// Gets the number of elements contained by this node and below.
@@ -138,7 +140,7 @@ namespace System.Collections.Immutable
         /// </summary>
         public KeyValuePair<int, TValue> Value
         {
-            get { return new KeyValuePair<int, TValue>(_key, _value); }
+            get { return new KeyValuePair<int, TValue>(_key, _value!); }
         }
 
         /// <summary>
@@ -198,6 +200,7 @@ namespace System.Collections.Immutable
         /// <param name="key">The key.</param>
         /// <returns>The value.</returns>
         [Pure]
+        [return: MaybeNull]
         internal TValue GetValueOrDefault(int key)
         {
             SortedInt32KeyNode<TValue> node = this;
@@ -205,21 +208,21 @@ namespace System.Collections.Immutable
             {
                 if (node.IsEmpty)
                 {
-                    return default(TValue);
+                    return default(TValue)!;
                 }
 
                 if (key == node._key)
                 {
-                    return node._value;
+                    return node._value!;
                 }
 
                 if (key > node._key)
                 {
-                    node = node._right;
+                    node = node._right!;
                 }
                 else
                 {
-                    node = node._left;
+                    node = node._left!;
                 }
             }
         }
@@ -231,30 +234,30 @@ namespace System.Collections.Immutable
         /// <param name="value">The value.</param>
         /// <returns>True if the key was found.</returns>
         [Pure]
-        internal bool TryGetValue(int key, out TValue value)
+        internal bool TryGetValue(int key, [MaybeNullWhen(false)] out TValue value)
         {
             SortedInt32KeyNode<TValue> node = this;
             while (true)
             {
                 if (node.IsEmpty)
                 {
-                    value = default(TValue);
+                    value = default(TValue)!;
                     return false;
                 }
 
                 if (key == node._key)
                 {
-                    value = node._value;
+                    value = node._value!;
                     return true;
                 }
 
                 if (key > node._key)
                 {
-                    node = node._right;
+                    node = node._right!;
                 }
                 else
                 {
-                    node = node._left;
+                    node = node._left!;
                 }
             }
         }
@@ -262,15 +265,15 @@ namespace System.Collections.Immutable
         /// <summary>
         /// Freezes this node and all descendant nodes so that any mutations require a new instance of the nodes.
         /// </summary>
-        internal void Freeze(Action<KeyValuePair<int, TValue>> freezeAction = null)
+        internal void Freeze(Action<KeyValuePair<int, TValue>>? freezeAction = null)
         {
             // If this node is frozen, all its descendants must already be frozen.
             if (!_frozen)
             {
-                freezeAction?.Invoke(new KeyValuePair<int, TValue>(_key, _value));
+                freezeAction?.Invoke(new KeyValuePair<int, TValue>(_key, _value!));
 
-                _left.Freeze(freezeAction);
-                _right.Freeze(freezeAction);
+                _left!.Freeze(freezeAction);
+                _right!.Freeze(freezeAction);
                 _frozen = true;
             }
         }
@@ -285,13 +288,13 @@ namespace System.Collections.Immutable
             Requires.NotNull(tree, nameof(tree));
             Debug.Assert(!tree.IsEmpty);
 
-            if (tree._right.IsEmpty)
+            if (tree._right!.IsEmpty)
             {
                 return tree;
             }
 
             var right = tree._right;
-            return right.Mutate(left: tree.Mutate(right: right._left));
+            return right.Mutate(left: tree.Mutate(right: right._left!));
         }
 
         /// <summary>
@@ -304,13 +307,13 @@ namespace System.Collections.Immutable
             Requires.NotNull(tree, nameof(tree));
             Debug.Assert(!tree.IsEmpty);
 
-            if (tree._left.IsEmpty)
+            if (tree._left!.IsEmpty)
             {
                 return tree;
             }
 
             var left = tree._left;
-            return left.Mutate(right: tree.Mutate(left: left._right));
+            return left.Mutate(right: tree.Mutate(left: left._right!));
         }
 
         /// <summary>
@@ -323,7 +326,7 @@ namespace System.Collections.Immutable
             Requires.NotNull(tree, nameof(tree));
             Debug.Assert(!tree.IsEmpty);
 
-            if (tree._right.IsEmpty)
+            if (tree._right!.IsEmpty)
             {
                 return tree;
             }
@@ -342,7 +345,7 @@ namespace System.Collections.Immutable
             Requires.NotNull(tree, nameof(tree));
             Debug.Assert(!tree.IsEmpty);
 
-            if (tree._left.IsEmpty)
+            if (tree._left!.IsEmpty)
             {
                 return tree;
             }
@@ -362,7 +365,7 @@ namespace System.Collections.Immutable
             Requires.NotNull(tree, nameof(tree));
             Debug.Assert(!tree.IsEmpty);
 
-            return tree._right._height - tree._left._height;
+            return tree._right!._height - tree._left!._height;
         }
 
         /// <summary>
@@ -404,12 +407,12 @@ namespace System.Collections.Immutable
 
             if (IsRightHeavy(tree))
             {
-                return Balance(tree._right) < 0 ? DoubleLeft(tree) : RotateLeft(tree);
+                return Balance(tree._right!) < 0 ? DoubleLeft(tree) : RotateLeft(tree);
             }
 
             if (IsLeftHeavy(tree))
             {
-                return Balance(tree._left) > 0 ? DoubleRight(tree) : RotateRight(tree);
+                return Balance(tree._left!) > 0 ? DoubleRight(tree) : RotateRight(tree);
             }
 
             return tree;
@@ -441,7 +444,7 @@ namespace System.Collections.Immutable
                 SortedInt32KeyNode<TValue> result = this;
                 if (key > _key)
                 {
-                    var newRight = _right.SetOrAdd(key, value, valueComparer, overwriteExistingValue, out replacedExistingValue, out mutated);
+                    var newRight = _right!.SetOrAdd(key, value, valueComparer, overwriteExistingValue, out replacedExistingValue, out mutated);
                     if (mutated)
                     {
                         result = this.Mutate(right: newRight);
@@ -449,7 +452,7 @@ namespace System.Collections.Immutable
                 }
                 else if (key < _key)
                 {
-                    var newLeft = _left.SetOrAdd(key, value, valueComparer, overwriteExistingValue, out replacedExistingValue, out mutated);
+                    var newLeft = _left!.SetOrAdd(key, value, valueComparer, overwriteExistingValue, out replacedExistingValue, out mutated);
                     if (mutated)
                     {
                         result = this.Mutate(left: newLeft);
@@ -457,7 +460,7 @@ namespace System.Collections.Immutable
                 }
                 else
                 {
-                    if (valueComparer.Equals(_value, value))
+                    if (valueComparer.Equals(_value!, value))
                     {
                         mutated = false;
                         return this;
@@ -466,7 +469,7 @@ namespace System.Collections.Immutable
                     {
                         mutated = true;
                         replacedExistingValue = true;
-                        result = new SortedInt32KeyNode<TValue>(key, value, _left, _right);
+                        result = new SortedInt32KeyNode<TValue>(key, value, _left!, _right!);
                     }
                     else
                     {
@@ -493,6 +496,7 @@ namespace System.Collections.Immutable
             }
             else
             {
+                Debug.Assert(_right != null && _left != null);
                 SortedInt32KeyNode<TValue> result = this;
                 if (key == _key)
                 {
@@ -519,7 +523,7 @@ namespace System.Collections.Immutable
                         // We have two children. Remove the next-highest node and replace
                         // this node with it.
                         var successor = _right;
-                        while (!successor._left.IsEmpty)
+                        while (!successor._left!.IsEmpty)
                         {
                             successor = successor._left;
                         }
@@ -558,11 +562,12 @@ namespace System.Collections.Immutable
         /// <param name="left">The left branch of the mutated node.</param>
         /// <param name="right">The right branch of the mutated node.</param>
         /// <returns>The mutated (or created) node.</returns>
-        private SortedInt32KeyNode<TValue> Mutate(SortedInt32KeyNode<TValue> left = null, SortedInt32KeyNode<TValue> right = null)
+        private SortedInt32KeyNode<TValue> Mutate(SortedInt32KeyNode<TValue>? left = null, SortedInt32KeyNode<TValue>? right = null)
         {
+            Debug.Assert(_right != null && _left != null);
             if (_frozen)
             {
-                return new SortedInt32KeyNode<TValue>(_key, _value, left ?? _left, right ?? _right);
+                return new SortedInt32KeyNode<TValue>(_key, _value!, left ?? _left, right ?? _right);
             }
             else
             {
index 8f2f063..b187317 100644 (file)
@@ -4,6 +4,7 @@
 
 using System.Collections.Generic;
 using System.Collections.Immutable;
+using System.Diagnostics.CodeAnalysis;
 using System.Diagnostics.Contracts;
 
 namespace System.Linq
@@ -30,7 +31,7 @@ namespace System.Linq
             // LINQ Select/Where have optimized treatment for arrays.
             // They also do not modify the source arrays or expose them to modifications.
             // Therefore we will just apply Select/Where to the underlying this.array array.
-            return immutableArray.array.Select(selector);
+            return immutableArray.array!.Select(selector);
         }
 
         /// <summary>
@@ -60,7 +61,7 @@ namespace System.Linq
             if (collectionSelector == null || resultSelector == null)
             {
                 // throw the same exception as would LINQ
-                return Enumerable.SelectMany(immutableArray, collectionSelector, resultSelector);
+                return Enumerable.SelectMany(immutableArray, collectionSelector!, resultSelector!);
             }
 
             // This SelectMany overload is used by the C# compiler for a query of the form:
@@ -90,7 +91,7 @@ namespace System.Linq
             // LINQ Select/Where have optimized treatment for arrays.
             // They also do not modify the source arrays or expose them to modifications.
             // Therefore we will just apply Select/Where to the underlying this.array array.
-            return immutableArray.array.Where(predicate);
+            return immutableArray.array!.Where(predicate);
         }
 
         /// <summary>
@@ -117,7 +118,7 @@ namespace System.Linq
             immutableArray.ThrowNullRefIfNotInitialized();
             Requires.NotNull(predicate, nameof(predicate));
 
-            foreach (var v in immutableArray.array)
+            foreach (var v in immutableArray.array!)
             {
                 if (predicate(v))
                 {
@@ -144,7 +145,7 @@ namespace System.Linq
             immutableArray.ThrowNullRefIfNotInitialized();
             Requires.NotNull(predicate, nameof(predicate));
 
-            foreach (var v in immutableArray.array)
+            foreach (var v in immutableArray.array!)
             {
                 if (!predicate(v))
                 {
@@ -161,7 +162,7 @@ namespace System.Linq
         /// <typeparam name="TDerived">The type of element in the compared array.</typeparam>
         /// <typeparam name="TBase">The type of element contained by the collection.</typeparam>
         [Pure]
-        public static bool SequenceEqual<TDerived, TBase>(this ImmutableArray<TBase> immutableArray, ImmutableArray<TDerived> items, IEqualityComparer<TBase> comparer = null) where TDerived : TBase
+        public static bool SequenceEqual<TDerived, TBase>(this ImmutableArray<TBase> immutableArray, ImmutableArray<TDerived> items, IEqualityComparer<TBase>? comparer = null) where TDerived : TBase
         {
             immutableArray.ThrowNullRefIfNotInitialized();
             items.ThrowNullRefIfNotInitialized();
@@ -182,7 +183,7 @@ namespace System.Linq
 
             for (int i = 0; i < immutableArray.Length; i++)
             {
-                if (!comparer.Equals(immutableArray.array[i], items.array[i]))
+                if (!comparer.Equals(immutableArray.array![i], items.array![i]))
                 {
                     return false;
                 }
@@ -197,7 +198,7 @@ namespace System.Linq
         /// <typeparam name="TDerived">The type of element in the compared array.</typeparam>
         /// <typeparam name="TBase">The type of element contained by the collection.</typeparam>
         [Pure]
-        public static bool SequenceEqual<TDerived, TBase>(this ImmutableArray<TBase> immutableArray, IEnumerable<TDerived> items, IEqualityComparer<TBase> comparer = null) where TDerived : TBase
+        public static bool SequenceEqual<TDerived, TBase>(this ImmutableArray<TBase> immutableArray, IEnumerable<TDerived> items, IEqualityComparer<TBase>? comparer = null) where TDerived : TBase
         {
             Requires.NotNull(items, nameof(items));
 
@@ -264,13 +265,14 @@ namespace System.Linq
         /// </summary>
         /// <typeparam name="T">The type of element contained by the collection.</typeparam>
         [Pure]
+        [return: MaybeNull]
         public static T Aggregate<T>(this ImmutableArray<T> immutableArray, Func<T, T, T> func)
         {
             Requires.NotNull(func, nameof(func));
 
             if (immutableArray.Length == 0)
             {
-                return default(T);
+                return default(T)!;
             }
 
             var result = immutableArray[0];
@@ -293,7 +295,7 @@ namespace System.Linq
             Requires.NotNull(func, nameof(func));
 
             var result = seed;
-            foreach (var v in immutableArray.array)
+            foreach (var v in immutableArray.array!)
             {
                 result = func(result, v);
             }
@@ -330,11 +332,12 @@ namespace System.Linq
         /// </summary>
         /// <typeparam name="T">The type of element contained by the collection.</typeparam>
         [Pure]
+        [return: MaybeNull]
         public static T ElementAtOrDefault<T>(this ImmutableArray<T> immutableArray, int index)
         {
             if (index < 0 || index >= immutableArray.Length)
             {
-                return default(T);
+                return default(T)!;
             }
 
             return immutableArray[index];
@@ -349,7 +352,7 @@ namespace System.Linq
         {
             Requires.NotNull(predicate, nameof(predicate));
 
-            foreach (var v in immutableArray.array)
+            foreach (var v in immutableArray.array!)
             {
                 if (predicate(v))
                 {
@@ -369,11 +372,12 @@ namespace System.Linq
         [Pure]
         public static T First<T>(this ImmutableArray<T> immutableArray)
         {
+
             // In the event of an empty array, generate the same exception
             // that the linq extension method would.
             return immutableArray.Length > 0
                 ? immutableArray[0]
-                : Enumerable.First(immutableArray.array);
+                : Enumerable.First(immutableArray.array!);
         }
 
         /// <summary>
@@ -382,9 +386,10 @@ namespace System.Linq
         /// <typeparam name="T">The type of element contained by the collection.</typeparam>
         /// <param name="immutableArray"></param>
         [Pure]
+        [return: MaybeNull]
         public static T FirstOrDefault<T>(this ImmutableArray<T> immutableArray)
         {
-            return immutableArray.array.Length > 0 ? immutableArray.array[0] : default(T);
+            return immutableArray.array!.Length > 0 ? immutableArray.array[0] : default(T)!;
         }
 
         /// <summary>
@@ -392,11 +397,12 @@ namespace System.Linq
         /// </summary>
         /// <typeparam name="T">The type of element contained by the collection.</typeparam>
         [Pure]
+        [return: MaybeNull]
         public static T FirstOrDefault<T>(this ImmutableArray<T> immutableArray, Func<T, bool> predicate)
         {
             Requires.NotNull(predicate, nameof(predicate));
 
-            foreach (var v in immutableArray.array)
+            foreach (var v in immutableArray.array!)
             {
                 if (predicate(v))
                 {
@@ -404,7 +410,7 @@ namespace System.Linq
                 }
             }
 
-            return default(T);
+            return default(T)!;
         }
 
         /// <summary>
@@ -419,7 +425,7 @@ namespace System.Linq
             // that the linq extension method would.
             return immutableArray.Length > 0
                 ? immutableArray[immutableArray.Length - 1]
-                : Enumerable.Last(immutableArray.array);
+                : Enumerable.Last(immutableArray.array!);
         }
 
         /// <summary>
@@ -449,10 +455,11 @@ namespace System.Linq
         /// <typeparam name="T">The type of element contained by the collection.</typeparam>
         /// <param name="immutableArray"></param>
         [Pure]
+        [return: MaybeNull]
         public static T LastOrDefault<T>(this ImmutableArray<T> immutableArray)
         {
             immutableArray.ThrowNullRefIfNotInitialized();
-            return immutableArray.array.LastOrDefault();
+            return immutableArray.array!.LastOrDefault()!;
         }
 
         /// <summary>
@@ -460,6 +467,7 @@ namespace System.Linq
         /// </summary>
         /// <typeparam name="T">The type of element contained by the collection.</typeparam>
         [Pure]
+        [return: MaybeNull]
         public static T LastOrDefault<T>(this ImmutableArray<T> immutableArray, Func<T, bool> predicate)
         {
             Requires.NotNull(predicate, nameof(predicate));
@@ -472,7 +480,7 @@ namespace System.Linq
                 }
             }
 
-            return default(T);
+            return default(T)!;
         }
 
         /// <summary>
@@ -484,7 +492,7 @@ namespace System.Linq
         public static T Single<T>(this ImmutableArray<T> immutableArray)
         {
             immutableArray.ThrowNullRefIfNotInitialized();
-            return immutableArray.array.Single();
+            return immutableArray.array!.Single();
         }
 
         /// <summary>
@@ -497,8 +505,8 @@ namespace System.Linq
             Requires.NotNull(predicate, nameof(predicate));
 
             var first = true;
-            var result = default(T);
-            foreach (var v in immutableArray.array)
+            var result = default(T)!;
+            foreach (var v in immutableArray.array!)
             {
                 if (predicate(v))
                 {
@@ -526,10 +534,11 @@ namespace System.Linq
         /// <typeparam name="T">The type of element contained by the collection.</typeparam>
         /// <param name="immutableArray"></param>
         [Pure]
+        [return: MaybeNull]
         public static T SingleOrDefault<T>(this ImmutableArray<T> immutableArray)
         {
             immutableArray.ThrowNullRefIfNotInitialized();
-            return immutableArray.array.SingleOrDefault();
+            return immutableArray.array!.SingleOrDefault()!;
         }
 
         /// <summary>
@@ -537,13 +546,14 @@ namespace System.Linq
         /// </summary>
         /// <typeparam name="T">The type of element contained by the collection.</typeparam>
         [Pure]
+        [return: MaybeNull]
         public static T SingleOrDefault<T>(this ImmutableArray<T> immutableArray, Func<T, bool> predicate)
         {
             Requires.NotNull(predicate, nameof(predicate));
 
             var first = true;
-            var result = default(T);
-            foreach (var v in immutableArray.array)
+            var result = default(T)!;
+            foreach (var v in immutableArray.array!)
             {
                 if (predicate(v))
                 {
@@ -569,7 +579,7 @@ namespace System.Linq
         /// <param name="keySelector">The key selector.</param>
         /// <returns>The newly initialized dictionary.</returns>
         [Pure]
-        public static Dictionary<TKey, T> ToDictionary<TKey, T>(this ImmutableArray<T> immutableArray, Func<T, TKey> keySelector)
+        public static Dictionary<TKey, T> ToDictionary<TKey, T>(this ImmutableArray<T> immutableArray, Func<T, TKey> keySelector) where TKey : notnull
         {
             return ToDictionary(immutableArray, keySelector, EqualityComparer<TKey>.Default);
         }
@@ -585,7 +595,7 @@ namespace System.Linq
         /// <param name="elementSelector">The element selector.</param>
         /// <returns>The newly initialized dictionary.</returns>
         [Pure]
-        public static Dictionary<TKey, TElement> ToDictionary<TKey, TElement, T>(this ImmutableArray<T> immutableArray, Func<T, TKey> keySelector, Func<T, TElement> elementSelector)
+        public static Dictionary<TKey, TElement> ToDictionary<TKey, TElement, T>(this ImmutableArray<T> immutableArray, Func<T, TKey> keySelector, Func<T, TElement> elementSelector) where TKey : notnull
         {
             return ToDictionary(immutableArray, keySelector, elementSelector, EqualityComparer<TKey>.Default);
         }
@@ -600,7 +610,7 @@ namespace System.Linq
         /// <param name="comparer">The comparer to initialize the dictionary with.</param>
         /// <returns>The newly initialized dictionary.</returns>
         [Pure]
-        public static Dictionary<TKey, T> ToDictionary<TKey, T>(this ImmutableArray<T> immutableArray, Func<T, TKey> keySelector, IEqualityComparer<TKey> comparer)
+        public static Dictionary<TKey, T> ToDictionary<TKey, T>(this ImmutableArray<T> immutableArray, Func<T, TKey> keySelector, IEqualityComparer<TKey>? comparer) where TKey : notnull
         {
             Requires.NotNull(keySelector, nameof(keySelector));
 
@@ -625,13 +635,13 @@ namespace System.Linq
         /// <param name="comparer">The comparer to initialize the dictionary with.</param>
         /// <returns>The newly initialized dictionary.</returns>
         [Pure]
-        public static Dictionary<TKey, TElement> ToDictionary<TKey, TElement, T>(this ImmutableArray<T> immutableArray, Func<T, TKey> keySelector, Func<T, TElement> elementSelector, IEqualityComparer<TKey> comparer)
+        public static Dictionary<TKey, TElement> ToDictionary<TKey, TElement, T>(this ImmutableArray<T> immutableArray, Func<T, TKey> keySelector, Func<T, TElement> elementSelector, IEqualityComparer<TKey>? comparer) where TKey : notnull
         {
             Requires.NotNull(keySelector, nameof(keySelector));
             Requires.NotNull(elementSelector, nameof(elementSelector));
 
             var result = new Dictionary<TKey, TElement>(immutableArray.Length, comparer);
-            foreach (var v in immutableArray.array)
+            foreach (var v in immutableArray.array!)
             {
                 result.Add(keySelector(v), elementSelector(v));
             }
@@ -649,9 +659,9 @@ namespace System.Linq
         public static T[] ToArray<T>(this ImmutableArray<T> immutableArray)
         {
             immutableArray.ThrowNullRefIfNotInitialized();
-            if (immutableArray.array.Length == 0)
+            if (immutableArray.array!.Length == 0)
             {
-                return ImmutableArray<T>.Empty.array;
+                return ImmutableArray<T>.Empty.array!;
             }
 
             return (T[])immutableArray.array.Clone();
@@ -682,11 +692,12 @@ namespace System.Linq
         /// Returns the first element in the collection, or the default value if the collection is empty.
         /// </summary>
         [Pure]
+        [return: MaybeNull]
         public static T FirstOrDefault<T>(this ImmutableArray<T>.Builder builder)
         {
             Requires.NotNull(builder, nameof(builder));
 
-            return builder.Any() ? builder[0] : default(T);
+            return builder.Any() ? builder[0] : default(T)!;
         }
 
         /// <summary>
@@ -710,11 +721,12 @@ namespace System.Linq
         /// Returns the last element in the collection, or the default value if the collection is empty.
         /// </summary>
         [Pure]
+        [return: MaybeNull]
         public static T LastOrDefault<T>(this ImmutableArray<T>.Builder builder)
         {
             Requires.NotNull(builder, nameof(builder));
 
-            return builder.Any() ? builder[builder.Count - 1] : default(T);
+            return builder.Any() ? builder[builder.Count - 1] : default(T)!;
         }
 
         /// <summary>
@@ -736,7 +748,7 @@ namespace System.Linq
             Func<TSource, IEnumerable<TCollection>> collectionSelector,
             Func<TSource, TCollection, TResult> resultSelector)
         {
-            foreach (TSource item in immutableArray.array)
+            foreach (TSource item in immutableArray.array!)
             {
                 foreach (TCollection result in collectionSelector(item))
                 {
index c936f96..06e65df 100644 (file)
@@ -22,7 +22,7 @@ namespace System.Collections.Immutable
         /// <param name="parameterName">The name of the parameter to include in any thrown exception.</param>
         /// <exception cref="ArgumentNullException">Thrown if <paramref name="value"/> is <c>null</c></exception>
         [DebuggerStepThrough]
-        public static void NotNull<T>([ValidatedNotNull]T value, string parameterName)
+        public static void NotNull<T>([ValidatedNotNull]T value, string? parameterName)
             where T : class // ensures value-types aren't passed to a null checking method
         {
             if (value == null)
@@ -40,7 +40,7 @@ namespace System.Collections.Immutable
         /// <returns>The value of the parameter.</returns>
         /// <exception cref="ArgumentNullException">Thrown if <paramref name="value"/> is <c>null</c></exception>
         [DebuggerStepThrough]
-        public static T NotNullPassthrough<T>([ValidatedNotNull]T value, string parameterName)
+        public static T NotNullPassthrough<T>([ValidatedNotNull]T value, string? parameterName)
             where T : class // ensures value-types aren't passed to a null checking method
         {
             NotNull(value, parameterName);
@@ -59,7 +59,7 @@ namespace System.Collections.Immutable
         /// may or may not be a class, but certainly cannot be null.
         /// </remarks>
         [DebuggerStepThrough]
-        public static void NotNullAllowStructs<T>([ValidatedNotNull]T value, string parameterName)
+        public static void NotNullAllowStructs<T>([ValidatedNotNull]T value, string? parameterName)
         {
             if (null == value)
             {
@@ -72,7 +72,7 @@ namespace System.Collections.Immutable
         /// </summary>
         /// <param name="parameterName">The name of the parameter that was null.</param>
         [DebuggerStepThrough]
-        private static void FailArgumentNullException(string parameterName)
+        private static void FailArgumentNullException(string? parameterName)
         {
             // Separating out this throwing operation helps with inlining of the caller
             throw new ArgumentNullException(parameterName);
@@ -82,7 +82,7 @@ namespace System.Collections.Immutable
         /// Throws an <see cref="ArgumentOutOfRangeException"/> if a condition does not evaluate to true.
         /// </summary>
         [DebuggerStepThrough]
-        public static void Range(bool condition, string parameterName, string message = null)
+        public static void Range(bool condition, string? parameterName, string? message = null)
         {
             if (!condition)
             {
@@ -94,7 +94,7 @@ namespace System.Collections.Immutable
         /// Throws an <see cref="ArgumentOutOfRangeException"/>.
         /// </summary>
         [DebuggerStepThrough]
-        public static void FailRange(string parameterName, string message = null)
+        public static void FailRange(string? parameterName, string? message = null)
         {
             if (string.IsNullOrEmpty(message))
             {
@@ -110,7 +110,7 @@ namespace System.Collections.Immutable
         /// Throws an <see cref="ArgumentException"/> if a condition does not evaluate to true.
         /// </summary>
         [DebuggerStepThrough]
-        public static void Argument(bool condition, string parameterName, string message)
+        public static void Argument(bool condition, string? parameterName, string? message)
         {
             if (!condition)
             {
@@ -142,7 +142,7 @@ namespace System.Collections.Immutable
         {
             // separating out this throwing helps with inlining of the caller, especially
             // due to the retrieval of the type's name
-            throw new ObjectDisposedException(disposed.GetType().FullName);
+            throw new ObjectDisposedException(disposed!.GetType().FullName);
         }
     }
 }