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
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; }
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; }
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; }
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; }
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
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; }
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; }
}
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;
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; } }
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; }
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() { }
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 { } }
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; }
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
{
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>
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() { }
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() { }
}
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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
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; }
}
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() { }
}
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;
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; } }
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() { }
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 { } }
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; }
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
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>
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 { } }
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; }
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; }
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; } }
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() { }
{
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; }
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; }
}
}
<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" />
<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" />
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
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)
return true;
}
- item = default(T);
+ item = default(T)!;
return false;
}
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);
// 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;
}
}
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;
get { return _inner.Current.Key; }
}
- public object Value
+ public object? Value
{
get { return _inner.Current.Value; }
}
/// <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>.
/// <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>
/// <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; }
}
}
/// <summary>
/// Gets an untyped reference to the array.
/// </summary>
- Array Array { get; }
+ Array? Array { get; }
}
}
/// 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
/// 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.
/// </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
/// 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.
/// <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);
}
}
/// 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}"/>
/// 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);
}
}
var immutableArray = items as IImmutableArray;
if (immutableArray != null)
{
- Array array = immutableArray.Array;
+ Array? array = immutableArray.Array;
if (array == null)
{
throw new InvalidOperationException(SR.InvalidOperationOnDefaultArray);
/// <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)
{
}
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);
}
[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>
/// 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>
[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>
/// <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>
}
else
{
- _elements = ImmutableArray<T>.Empty.array;
+ _elements = ImmutableArray<T>.Empty.array!;
}
}
}
{
for (int i = value; i < this.Count; i++)
{
- _elements[i] = default(T);
+ _elements[i] = default(T)!;
}
}
}
}
T[] temp = _elements;
- _elements = ImmutableArray<T>.Empty.array;
+ _elements = ImmutableArray<T>.Empty.array!;
_count = 0;
return new ImmutableArray<T>(temp);
}
{
if (this.Count == 0)
{
- return Empty.array;
+ return Empty.array!;
}
T[] result = new T[this.Count];
/// </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)
{
/// <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)
{
/// 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)
{
/// <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.
/// 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.
/// <summary>
/// Gets the currently enumerated value.
/// </summary>
- object IEnumerator.Current
+ object? IEnumerator.Current
{
get { return this.Current; }
}
/// 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;
}
// 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];
}
}
// 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
// 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;
}
}
/// Gets an untyped reference to the array.
/// </summary>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
- Array IImmutableArray.Array
+ Array? IImmutableArray.Array
{
get { return this.array; }
}
{
var self = this;
self.ThrowNullRefIfNotInitialized();
- Array.Copy(self.array, 0, destination, 0, self.Length);
+ Array.Copy(self.array!, 0, destination, 0, self.Length);
}
/// <summary>
{
var self = this;
self.ThrowNullRefIfNotInitialized();
- Array.Copy(self.array, 0, destination, destinationIndex, self.Length);
+ Array.Copy(self.array!, 0, destination, destinationIndex, self.Length);
}
/// <summary>
{
var self = this;
self.ThrowNullRefIfNotInitialized();
- Array.Copy(self.array, sourceIndex, destination, destinationIndex, length);
+ Array.Copy(self.array!, sourceIndex, destination, destinationIndex, length);
}
/// <summary>
{
var self = this;
self.ThrowNullRefIfNotInitialized();
- return new Enumerator(self.array);
+ return new Enumerator(self.array!);
}
/// <summary>
/// <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>
[Pure]
public ImmutableArray<TOther> CastArray<TOther>() where TOther : class
{
- return new ImmutableArray<TOther>((TOther[])(object)array);
+ return new ImmutableArray<TOther>((TOther[])(object)array!);
}
/// <summary>
[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>
{
var self = this;
self.ThrowInvalidOperationIfNotInitialized();
- return EnumeratorObject.Create(self.array);
+ return EnumeratorObject.Create(self.array!);
}
/// <summary>
{
var self = this;
self.ThrowInvalidOperationIfNotInitialized();
- return EnumeratorObject.Create(self.array);
+ return EnumeratorObject.Create(self.array!);
}
/// <summary>
// 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>
/// <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);
/// </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();
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;
}
/// <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();
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;
}
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);
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.
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);
}
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);
}
/// <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);
/// </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();
}
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);
}
/// 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();
/// 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)
{
}
else
{
- return self.RemoveRange(items.array, equalityComparer);
+ return self.RemoveRange(items.array!, equalityComparer);
}
}
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]))
{
/// </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);
/// <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();
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;
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);
}
/// 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();
/// 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();
/// <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();
/// </returns>
/// <exception cref="System.NotSupportedException"></exception>
[ExcludeFromCodeCoverage]
- int IList.Add(object value)
+ int IList.Add(object? value)
{
throw new NotSupportedException();
}
/// 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>
/// 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>
/// <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();
}
/// <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();
}
/// <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
{
{
var self = this;
self.ThrowInvalidOperationIfNotInitialized();
- Array.Copy(self.array, 0, array, index, self.Length);
+ Array.Copy(self.array!, 0, array, index, self.Length);
}
/// <summary>
/// <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;
}
}
- IStructuralEquatable ours = self.array;
+ IStructuralEquatable ours = self.array!;
return ours.Equals(otherArray, comparer);
}
int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
{
var self = this;
- IStructuralEquatable ours = self.array;
+ IStructuralEquatable? ours = self.array;
return ours != null ? ours.GetHashCode(comparer) : self.GetHashCode();
}
/// 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;
if (otherArray != null)
{
- IStructuralComparable ours = self.array;
+ IStructuralComparable? ours = self.array;
if (ours == null)
{
throw new ArgumentException(SR.ArrayInitializedStateNotEqual, nameof(other));
{
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);
}
/// <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;
}
/// 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);
}
/// 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);
}
/// <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);
}
/// <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);
}
/// <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);
}
/// <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();
}
/// <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();
}
/// <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();
}
/// <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));
/// <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));
/// <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);
}
/// <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);
}
/// <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);
}
/// <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);
}
/// <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));
/// <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);
}
/// <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);
}
/// <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));
/// <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>
/// 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;
}
/// 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.
/// <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.
{
if (_syncRoot == null)
{
- Threading.Interlocked.CompareExchange<object>(ref _syncRoot, new object(), null);
+ Threading.Interlocked.CompareExchange<object?>(ref _syncRoot, new object(), null);
}
return _syncRoot;
/// </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>
/// </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
get
{
TValue value;
- if (this.TryGetValue(key, out value))
+ if (this.TryGetValue(key, out value!))
{
return value;
}
/// <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>
Requires.NotNullAllowStructs(key, nameof(key));
TValue value;
- if (this.TryGetValue(key, out value))
+ if (this.TryGetValue(key, out value!))
{
return value;
}
/// 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>
/// <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.
/// <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.
/// <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.
/// </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);
// 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
/// </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;
/// <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();
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)
{
// 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));
}
/// <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;
}
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;
}
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)
{
/// <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.
/// 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;
Requires.NotNullAllowStructs(key, nameof(key));
TValue value;
- if (this.TryGetValue(key, out value))
+ if (this.TryGetValue(key, out value!))
{
return value;
}
/// <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>
/// 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)
{
/// 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);
}
/// </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();
}
/// </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(); }
/// <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)
return true;
}
- var builder = sequence as Builder;
- if (builder != null)
+ if (sequence is Builder builder)
{
other = builder.ToImmutable();
return true;
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;
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);
}
/// <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;
}
/// <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)
{
{
// 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);
}
/// </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.
/// <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.
/// <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;
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;
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;
}
}
if (count == 0)
{
- return ImmutableArray<T>.Empty.array;
+ return ImmutableArray<T>.Empty.array!;
}
T[] array = new T[count];
{
internal static bool IsValueType<T>()
{
- if (default(T) != null)
+ if (default(T)! != null)
{
return true;
}
/// <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.
/// 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);
}
/// <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);
}
/// <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);
}
/// <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);
}
/// 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();
}
/// <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);
}
/// 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.
/// <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.
/// </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);
/// <summary>
/// Gets the current element.
/// </summary>
- object IEnumerator.Current
+ object? IEnumerator.Current
{
get { return this.Current; }
}
/// </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;
/// <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();
{
// 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));
}
/// <summary>
/// Gets the current element.
/// </summary>
- object IEnumerator.Current
+ object? IEnumerator.Current
{
get { return this.Current; }
}
/// 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)
{
// 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
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));
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
}
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);
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
}
/// <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));
Requires.NotNull(map, nameof(location));
TValue value;
- if (map.TryGetValue(key, out value))
+ if (map.TryGetValue(key, out value!))
{
return value;
}
/// 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));
Requires.NotNull(map, nameof(location));
TValue value;
- if (map.TryGetValue(key, out value))
+ if (map.TryGetValue(key, out value!))
{
return value;
}
/// <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;
{
Requires.NotNull(priorCollection, nameof(location));
TValue oldValue;
- if (priorCollection.TryGetValue(key, out oldValue))
+ if (priorCollection.TryGetValue(key, out oldValue!))
{
return oldValue;
}
/// <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));
Requires.NotNull(priorCollection, nameof(location));
TValue oldValue;
- if (priorCollection.TryGetValue(key, out oldValue))
+ if (priorCollection.TryGetValue(key, out oldValue!))
{
newValue = updateValueFactory(key, oldValue);
}
/// <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));
Requires.NotNull(priorCollection, nameof(location));
TValue oldValue;
- if (priorCollection.TryGetValue(key, out oldValue))
+ if (priorCollection.TryGetValue(key, out oldValue!))
{
newValue = updateValueFactory(key, oldValue);
}
/// <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;
/// <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);
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;
/// <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;
{
Requires.NotNull(priorCollection, nameof(location));
- if (!priorCollection.TryGetValue(key, out value))
+ if (!priorCollection.TryGetValue(key, out value!))
{
return false;
}
/// <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;
if (priorCollection.IsEmpty)
{
- value = default(T);
+ value = default(T)!;
return false;
}
/// <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;
if (priorCollection.IsEmpty)
{
- value = default(T);
+ value = default(T)!;
return false;
}
/// 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);
/// <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));
/// 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.
/// <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.
/// 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>
/// 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>
/// 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>
/// 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>
/// 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);
}
/// 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));
/// cannot find an implementation of the System.IComparable<T> 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);
}
/// cannot find an implementation of the System.IComparable<T> 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);
}
/// <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;
}
/// <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;
/// <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;
/// </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>
/// 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!);
}
}
/// </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
{
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;
/// <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.
using System.Collections.Generic;
using System.ComponentModel;
+using System.Diagnostics;
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.
/// <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.
/// <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));
/// <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;
{
Node n = stack.Pop().Value;
_current = n;
- this.PushNext(this.NextBranch(n));
+ this.PushNext(this.NextBranch(n)!);
_remainingCount--;
return true;
}
/// <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)!;
}
}
/// <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.
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)!;
}
}
}
/// <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).
/// <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
/// <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.
get
{
Requires.Range(index >= 0 && index < this.Count, nameof(index));
+ Debug.Assert(_left != null && _right != null);
if (index < _left._count)
{
{
Requires.Range(index >= 0 && index < this.Count, nameof(index));
+ Debug.Assert(_left != null && _right != null);
if (index < _left._count)
{
return ref _left.ItemRef(index);
return CreateLeaf(key);
}
- Node newRight = _right.Add(key);
+ Node newRight = _right!.Add(key);
Node result = this.MutateRight(newRight);
return result.IsBalanced ? result : result.BalanceRight();
}
return CreateLeaf(key);
}
- if (index <= _left._count)
+ if (index <= _left!._count)
{
Node newLeft = _left.Insert(index, key);
Node result = this.MutateLeft(newLeft);
}
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();
}
return CreateRange(keys);
}
- Node newRight = _right.AddRange(keys);
+ Node newRight = _right!.AddRange(keys);
Node result = this.MutateRight(newRight);
return result.BalanceMany();
}
}
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);
}
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)
// 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;
}
Debug.Assert(!this.IsEmpty);
Node result = this;
- if (index == _left._count)
+ if (index == _left!._count)
{
// We have a match.
result = this.MutateKey(value);
}
else
{
- var newRight = _right.ReplaceAt(index - _left._count - 1, value);
+ var newRight = _right!.ReplaceAt(index - _left._count - 1, value);
result = this.MutateRight(newRight);
}
/// 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}"/>
/// 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));
/// 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));
}
// 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;
}
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;
}
/// <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.
/// 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));
/// 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));
/// 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));
}
}
- return default(T);
+ return default(T)!;
}
/// <summary>
return ImmutableList<T>.Empty;
}
- List<T> list = null;
+ List<T>? list = null;
foreach (var item in this)
{
if (match(item))
/// 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));
}
}
- return default(T);
+ return default(T)!;
}
/// <summary>
// If this node is frozen, all its descendants must already be frozen.
if (!_frozen)
{
- _left.Freeze();
- _right.Freeze();
+ _left!.Freeze();
+ _right!.Freeze();
_frozen = true;
}
}
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>
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>
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>
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>
get
{
Debug.Assert(!this.IsEmpty);
- return _right._height - _left._height;
+ return _right!._height - _left!._height;
}
}
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>
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>
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());
}
}
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;
}
}
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;
}
}
if (_frozen)
{
- return new Node(key, _left, _right);
+ return new Node(key, _left!, _right!);
}
else
{
/// <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;
/// 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));
}
}
}
/// 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}"/>
/// 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
/// 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);
/// 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));
/// 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)
/// </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}"/>
/// </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));
/// 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>
/// 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>
/// 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
/// 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}"/>
/// 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.
/// 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.
/// </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
/// 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.
/// <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"/>.
/// <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.
/// <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.
/// </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.
/// <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();
/// <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)
/// <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>
{
// 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;
}
/// <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.
{
return _remainingForwardsStack.Peek();
}
- else if (!_remainingBackwardsStack.IsEmpty)
+ else if (!_remainingBackwardsStack!.IsEmpty)
{
return _remainingBackwardsStack.Peek();
}
{
_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>
/// 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.
{
return _remainingForwardsStack.Peek();
}
- else if (!_remainingBackwardsStack.IsEmpty)
+ else if (!_remainingBackwardsStack!.IsEmpty)
{
return _remainingBackwardsStack.Peek();
}
/// </summary>
object IEnumerator.Current
{
- get { return this.Current; }
+ get { return this.Current!; }
}
/// <summary>
{
_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>
/// <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.
/// <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;
}
/// <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);
}
/// <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);
}
/// <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);
}
/// <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);
}
/// <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);
}
/// <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();
}
/// <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();
}
/// <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();
}
/// <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));
/// <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));
/// <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);
}
/// <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);
}
/// <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));
/// <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);
}
/// <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);
}
/// 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,
/// 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.
/// <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.
get
{
TValue value;
- if (this.TryGetValue(key, out value))
+ if (this.TryGetValue(key, out value!))
{
return value;
}
{
if (_syncRoot == null)
{
- Threading.Interlocked.CompareExchange<object>(ref _syncRoot, new object(), null);
+ Threading.Interlocked.CompareExchange<object?>(ref _syncRoot, new object(), null);
}
return _syncRoot;
/// </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>
/// </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
/// <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>
/// <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>
Requires.NotNullAllowStructs(key, nameof(key));
TValue value;
- if (this.TryGetValue(key, out value))
+ if (this.TryGetValue(key, out value!))
{
return value;
}
/// <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.
/// <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.
using System.Collections.Generic;
using System.ComponentModel;
+using System.Diagnostics;
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.
/// <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.
/// </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));
/// </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;
{
Node n = stack.Pop().Value;
_current = n;
- this.PushLeft(n.Right);
+ this.PushLeft(n.Right!);
return true;
}
}
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!;
}
}
}
using System.Collections.Generic;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Globalization;
/// <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).
/// <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
/// <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; }
}
/// <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; }
}
/// <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; }
}
/// <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; }
}
/// <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));
var match = this.Search(key, keyComparer);
if (match.IsEmpty)
{
- value = default(TValue);
+ value = default(TValue)!;
return false;
}
else
// If this node is frozen, all its descendants must already be frozen.
if (!_frozen)
{
- _left.Freeze();
- _right.Freeze();
+ _left!.Freeze();
+ _right!.Freeze();
_frozen = true;
}
}
Requires.NotNull(tree, nameof(tree));
Debug.Assert(!tree.IsEmpty);
- if (tree._right.IsEmpty)
+ if (tree._right!.IsEmpty)
{
return tree;
}
Requires.NotNull(tree, nameof(tree));
Debug.Assert(!tree.IsEmpty);
- if (tree._left.IsEmpty)
+ if (tree._left!.IsEmpty)
{
return tree;
}
Requires.NotNull(tree, nameof(tree));
Debug.Assert(!tree.IsEmpty);
- if (tree._right.IsEmpty)
+ if (tree._right!.IsEmpty)
{
return tree;
}
Requires.NotNull(tree, nameof(tree));
Debug.Assert(!tree.IsEmpty);
- if (tree._left.IsEmpty)
+ if (tree._left!.IsEmpty)
{
return tree;
}
Requires.NotNull(tree, nameof(tree));
Debug.Assert(!tree.IsEmpty);
- return tree._right._height - tree._left._height;
+ return tree._right!._height - tree._left!._height;
}
/// <summary>
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;
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);
}
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);
{
mutated = true;
replacedExistingValue = true;
- result = new Node(key, value, _left, _right);
+ result = new Node(key, value, _left!, _right!);
}
else
{
}
else
{
+ Debug.Assert(_right != null && _left != null);
Node result = this;
int compare = keyComparer.Compare(key, _key);
if (compare == 0)
// 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;
}
/// <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);
}
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);
}
}
}
/// </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;
/// 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)
{
/// 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);
}
/// <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>
/// </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();
}
/// </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(); }
/// <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)
return true;
}
- var builder = sequence as Builder;
- if (builder != null)
+ if (sequence is Builder builder)
{
other = builder.ToImmutable();
return true;
// 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);
}
else
{
TValue value;
- if (dictionary.TryGetValue(item.Key, out value))
+ if (dictionary.TryGetValue(item.Key, out value!))
{
if (!_valueComparer.Equals(value, item.Value))
{
/// 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);
}
/// <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);
}
/// <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);
}
/// <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);
}
/// 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();
}
/// <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);
}
/// 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.
/// <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.
/// 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; }
/// 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; }
{
if (_syncRoot == null)
{
- Threading.Interlocked.CompareExchange<object>(ref _syncRoot, new object(), null);
+ Threading.Interlocked.CompareExchange<object?>(ref _syncRoot, new object(), null);
}
return _syncRoot;
/// <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.
/// 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.
/// <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));
/// <summary>
/// The current element.
/// </summary>
- object System.Collections.IEnumerator.Current
+ object? System.Collections.IEnumerator.Current
{
get { return this.Current; }
}
/// </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;
}
}
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
_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);
}
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!;
}
}
}
/// <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).
/// <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
/// <summary>
/// Gets the left branch of this node.
/// </summary>
- public Node 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; }
}
/// <summary>
/// Gets the right branch of this node.
/// </summary>
- public Node 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; }
}
/// <summary>
/// Gets the left branch of this node.
/// </summary>
- IBinaryTree<T> IBinaryTree<T>.Left
+ IBinaryTree<T>? IBinaryTree<T>.Left
{
get { return _left; }
}
/// <summary>
/// Gets the right branch of this node.
/// </summary>
- IBinaryTree<T> IBinaryTree<T>.Right
+ IBinaryTree<T>? IBinaryTree<T>.Right
{
get { return _right; }
}
/// 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;
}
/// 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;
}
get
{
Requires.Range(index >= 0 && index < this.Count, nameof(index));
+ Debug.Assert(_left != null && _right != null);
if (index < _left._count)
{
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)
{
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);
}
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);
}
else
{
+ Debug.Assert(_left != null && _right != null);
Node result = this;
int compare = comparer.Compare(key, _key);
if (compare == 0)
// 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;
}
// 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;
}
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);
}
}
}
}
else
{
+ Debug.Assert(_left != null && _right != null);
int compare = comparer.Compare(key, _key);
if (compare == 0)
{
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>
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>
Requires.NotNull(tree, nameof(tree));
Debug.Assert(!tree.IsEmpty);
- if (tree._right.IsEmpty)
+ if (tree._right!.IsEmpty)
{
return tree;
}
Requires.NotNull(tree, nameof(tree));
Debug.Assert(!tree.IsEmpty);
- if (tree._left.IsEmpty)
+ if (tree._left!.IsEmpty)
{
return tree;
}
Requires.NotNull(tree, nameof(tree));
Debug.Assert(!tree.IsEmpty);
- return tree._right._height - tree._left._height;
+ return tree._right!._height - tree._left!._height;
}
/// <summary>
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;
/// <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);
/// 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;
/// 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; }
/// 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; }
{
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)
/// 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)
{
/// 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();
}
/// <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>
/// <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>
/// <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();
}
/// </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();
}
/// </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(); }
/// <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)
/// <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.
/// <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.
/// <summary>
/// Gets the current element.
/// </summary>
- object IEnumerator.Current
+ object? IEnumerator.Current
{
get { return this.Current; }
}
/// <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
throw new InvalidOperationException(SR.InvalidEmptyOperation);
}
- return _head;
+ return _head!;
}
#if !NETSTANDARD1_0
throw new InvalidOperationException(SR.InvalidEmptyOperation);
}
- return ref _head;
+ return ref _head!;
}
#endif
/// <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.
/// <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.
/// <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.
// 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;
}
}
- 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))
{
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))
}
else
{
- value = default(T);
+ value = default(T)!;
return false;
}
}
/// <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.
/// </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;
{
SortedInt32KeyNode<TValue> n = stack.Pop().Value;
_current = n;
- this.PushLeft(n.Right);
+ this.PushLeft(n.Right!);
return true;
}
}
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!;
}
}
}
using System.Collections.Generic;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Globalization;
/// <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).
/// <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.
/// <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.
/// </summary>
public KeyValuePair<int, TValue> Value
{
- get { return new KeyValuePair<int, TValue>(_key, _value); }
+ get { return new KeyValuePair<int, TValue>(_key, _value!); }
}
/// <summary>
/// <param name="key">The key.</param>
/// <returns>The value.</returns>
[Pure]
+ [return: MaybeNull]
internal TValue GetValueOrDefault(int key)
{
SortedInt32KeyNode<TValue> node = this;
{
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!;
}
}
}
/// <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!;
}
}
}
/// <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;
}
}
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>
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>
Requires.NotNull(tree, nameof(tree));
Debug.Assert(!tree.IsEmpty);
- if (tree._right.IsEmpty)
+ if (tree._right!.IsEmpty)
{
return tree;
}
Requires.NotNull(tree, nameof(tree));
Debug.Assert(!tree.IsEmpty);
- if (tree._left.IsEmpty)
+ if (tree._left!.IsEmpty)
{
return tree;
}
Requires.NotNull(tree, nameof(tree));
Debug.Assert(!tree.IsEmpty);
- return tree._right._height - tree._left._height;
+ return tree._right!._height - tree._left!._height;
}
/// <summary>
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;
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);
}
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);
}
else
{
- if (valueComparer.Equals(_value, value))
+ if (valueComparer.Equals(_value!, value))
{
mutated = false;
return this;
{
mutated = true;
replacedExistingValue = true;
- result = new SortedInt32KeyNode<TValue>(key, value, _left, _right);
+ result = new SortedInt32KeyNode<TValue>(key, value, _left!, _right!);
}
else
{
}
else
{
+ Debug.Assert(_right != null && _left != null);
SortedInt32KeyNode<TValue> result = this;
if (key == _key)
{
// 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;
}
/// <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
{
using System.Collections.Generic;
using System.Collections.Immutable;
+using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
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>
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:
// 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>
immutableArray.ThrowNullRefIfNotInitialized();
Requires.NotNull(predicate, nameof(predicate));
- foreach (var v in immutableArray.array)
+ foreach (var v in immutableArray.array!)
{
if (predicate(v))
{
immutableArray.ThrowNullRefIfNotInitialized();
Requires.NotNull(predicate, nameof(predicate));
- foreach (var v in immutableArray.array)
+ foreach (var v in immutableArray.array!)
{
if (!predicate(v))
{
/// <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();
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;
}
/// <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));
/// </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];
Requires.NotNull(func, nameof(func));
var result = seed;
- foreach (var v in immutableArray.array)
+ foreach (var v in immutableArray.array!)
{
result = func(result, v);
}
/// </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];
{
Requires.NotNull(predicate, nameof(predicate));
- foreach (var v in immutableArray.array)
+ foreach (var v in immutableArray.array!)
{
if (predicate(v))
{
[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>
/// <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>
/// </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))
{
}
}
- return default(T);
+ return default(T)!;
}
/// <summary>
// that the linq extension method would.
return immutableArray.Length > 0
? immutableArray[immutableArray.Length - 1]
- : Enumerable.Last(immutableArray.array);
+ : Enumerable.Last(immutableArray.array!);
}
/// <summary>
/// <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>
/// </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));
}
}
- return default(T);
+ return default(T)!;
}
/// <summary>
public static T Single<T>(this ImmutableArray<T> immutableArray)
{
immutableArray.ThrowNullRefIfNotInitialized();
- return immutableArray.array.Single();
+ return immutableArray.array!.Single();
}
/// <summary>
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))
{
/// <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>
/// </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))
{
/// <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);
}
/// <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);
}
/// <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));
/// <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));
}
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();
/// 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>
/// 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>
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))
{
/// <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)
/// <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);
/// 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)
{
/// </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);
/// 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)
{
/// 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))
{
/// 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)
{
{
// 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);
}
}
}