// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Diagnostics;
{
internal interface IArraySortHelper<TKey>
{
- void Sort(TKey[] keys, int index, int length, IComparer<TKey> comparer);
- int BinarySearch(TKey[] keys, int index, int length, TKey value, IComparer<TKey> comparer);
+ void Sort(TKey[] keys, int index, int length, IComparer<TKey>? comparer);
+ int BinarySearch(TKey[] keys, int index, int length, TKey value, IComparer<TKey>? comparer);
}
[TypeDependencyAttribute("System.Collections.Generic.GenericArraySortHelper`1")]
internal interface IArraySortHelper<TKey, TValue>
{
- void Sort(TKey[] keys, TValue[] values, int index, int length, IComparer<TKey> comparer);
+ void Sort(TKey[] keys, TValue[] values, int index, int length, IComparer<TKey>? comparer);
}
[TypeDependencyAttribute("System.Collections.Generic.GenericArraySortHelper`2")]
: IArraySortHelper<TKey, TValue>
{
}
-}
\ No newline at end of file
+}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-
+#nullable enable
using System.Runtime;
using System.Runtime.CompilerServices;
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System.Diagnostics;
using static System.RuntimeTypeHandle;
{
Debug.Assert(type != null && type is RuntimeType);
- object result = null;
+ object? result = null;
var runtimeType = (RuntimeType)type;
// If T implements IComparable<T> return a GenericComparer<T>
/// Creates the default <see cref="Comparer{T}"/> for a nullable type.
/// </summary>
/// <param name="nullableType">The nullable type to create the default comparer for.</param>
- private static object TryCreateNullableComparer(RuntimeType nullableType)
+ private static object? TryCreateNullableComparer(RuntimeType nullableType)
{
Debug.Assert(nullableType != null);
Debug.Assert(nullableType.IsGenericType && nullableType.GetGenericTypeDefinition() == typeof(Nullable<>));
/// Creates the default <see cref="Comparer{T}"/> for an enum type.
/// </summary>
/// <param name="enumType">The enum type to create the default comparer for.</param>
- private static object TryCreateEnumComparer(RuntimeType enumType)
+ private static object? TryCreateEnumComparer(RuntimeType enumType)
{
Debug.Assert(enumType != null);
Debug.Assert(enumType.IsEnum);
{
Debug.Assert(type != null && type is RuntimeType);
- object result = null;
+ object? result = null;
var runtimeType = (RuntimeType)type;
// Specialize for byte so Array.IndexOf is faster.
/// Creates the default <see cref="EqualityComparer{T}"/> for a nullable type.
/// </summary>
/// <param name="nullableType">The nullable type to create the default equality comparer for.</param>
- private static object TryCreateNullableEqualityComparer(RuntimeType nullableType)
+ private static object? TryCreateNullableEqualityComparer(RuntimeType nullableType)
{
Debug.Assert(nullableType != null);
Debug.Assert(nullableType.IsGenericType && nullableType.GetGenericTypeDefinition() == typeof(Nullable<>));
/// Creates the default <see cref="EqualityComparer{T}"/> for an enum type.
/// </summary>
/// <param name="enumType">The enum type to create the default equality comparer for.</param>
- private static object TryCreateEnumEqualityComparer(RuntimeType enumType)
+ private static object? TryCreateEnumEqualityComparer(RuntimeType enumType)
{
Debug.Assert(enumType != null);
Debug.Assert(enumType.IsEnum);
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System.Runtime;
using System.Runtime.CompilerServices;
using System.Diagnostics;
{
for (int i = startIndex; i < endIndex; i++)
{
- if (array[i] != null && array[i].Equals(value)) return i;
+ if (array[i] != null && array[i]!.Equals(value)) return i; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644
}
}
return -1;
{
for (int i = startIndex; i >= endIndex; i--)
{
- if (array[i] != null && array[i].Equals(value)) return i;
+ if (array[i] != null && array[i]!.Equals(value)) return i; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644
}
}
return -1;
if (Data["__RestrictedErrorObject"] is __RestrictedErrorObject restrictedObject)
restrictedErrorObject = restrictedObject.RealErrorObject;
}
- return (bool)Data["__HasRestrictedLanguageErrorObject"];
+ return (bool)Data["__HasRestrictedLanguageErrorObject"]!;
}
return false;
}
}
- internal static unsafe void ConvertContentsToNative_KeyValuePair<K, V>(ref KeyValuePair<K, V>[]? managedArray, IntPtr pNativeHome)
+ internal static unsafe void ConvertContentsToNative_KeyValuePair<K, V>(ref KeyValuePair<K, V>[]? managedArray, IntPtr pNativeHome)
{
if (managedArray != null)
{
for (int i = (this.Length >= 8 ? this.Length - 8 : 0); i < this.Length; i++)
{
- ret = CombineHashCodes(ret, comparer!.GetHashCode(GetValue(i))); // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
+ ret = CombineHashCodes(ret, comparer!.GetHashCode(GetValue(i)!)); // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
}
return ret;
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparison);
}
- ArraySortHelper<T>.Sort(array!, 0, array!.Length, comparison); // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
+ ArraySortHelper<T>.Sort(array!, 0, array!.Length, comparison!); // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
}
public static bool TrueForAll<T>(T[] array, Predicate<T> match)
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System.ComponentModel;
namespace System.Collections
public struct DictionaryEntry
{
private object _key; // Do not rename (binary serialization)
- private object _value; // Do not rename (binary serialization)
+ private object? _value; // Do not rename (binary serialization)
// Constructs a new DictionaryEnumerator by setting the Key
// and Value fields appropriately.
- public DictionaryEntry(object key, object value)
+ public DictionaryEntry(object key, object? value)
{
_key = key;
_value = value;
}
}
- public object Value
+ public object? Value
{
get
{
}
[EditorBrowsable(EditorBrowsableState.Never)]
- public void Deconstruct(out object key, out object value)
+ public void Deconstruct(out object key, out object? value)
{
key = Key;
value = Value;
**
===========================================================*/
+#nullable enable
using System.Diagnostics;
using System.Runtime.CompilerServices;
return result;
}
- internal static void ThrowOrIgnoreBadComparer(object comparer)
+ internal static void ThrowOrIgnoreBadComparer(object? comparer)
{
throw new ArgumentException(SR.Format(SR.Arg_BogusIComparer, comparer));
}
{
#region IArraySortHelper<T> Members
- public void Sort(T[] keys, int index, int length, IComparer<T> comparer)
+ public void Sort(T[] keys, int index, int length, IComparer<T>? comparer)
{
Debug.Assert(keys != null, "Check the arguments in the caller!");
Debug.Assert(index >= 0 && length >= 0 && (keys.Length - index >= length), "Check the arguments in the caller!");
}
}
- public int BinarySearch(T[] array, int index, int length, T value, IComparer<T> comparer)
+ public int BinarySearch(T[] array, int index, int length, T value, IComparer<T>? comparer)
{
try
{
#region IArraySortHelper<T> Members
- public void Sort(T[] keys, int index, int length, IComparer<T> comparer)
+ public void Sort(T[] keys, int index, int length, IComparer<T>? comparer)
{
Debug.Assert(keys != null, "Check the arguments in the caller!");
Debug.Assert(index >= 0 && length >= 0 && (keys.Length - index >= length), "Check the arguments in the caller!");
}
}
- public int BinarySearch(T[] array, int index, int length, T value, IComparer<T> comparer)
+ public int BinarySearch(T[] array, int index, int length, T value, IComparer<T>? comparer)
{
Debug.Assert(array != null, "Check the arguments in the caller!");
Debug.Assert(index >= 0 && length >= 0 && (array.Length - index >= length), "Check the arguments in the caller!");
internal partial class ArraySortHelper<TKey, TValue>
{
- public void Sort(TKey[] keys, TValue[] values, int index, int length, IComparer<TKey> comparer)
+ public void Sort(TKey[] keys, TValue[] values, int index, int length, IComparer<TKey>? comparer)
{
Debug.Assert(keys != null, "Check the arguments in the caller!"); // Precondition on interface method
Debug.Assert(values != null, "Check the arguments in the caller!");
internal partial class GenericArraySortHelper<TKey, TValue>
where TKey : IComparable<TKey>
{
- public void Sort(TKey[] keys, TValue[] values, int index, int length, IComparer<TKey> comparer)
+ public void Sort(TKey[] keys, TValue[] values, int index, int length, IComparer<TKey>? comparer)
{
Debug.Assert(keys != null, "Check the arguments in the caller!");
Debug.Assert(index >= 0 && length >= 0 && (keys.Length - index >= length), "Check the arguments in the caller!");
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
return new ComparisonComparer<T>(comparison);
}
- public abstract int Compare(T x, T y);
+ public abstract int Compare(T x, T y); // TODO-NULLABLE-GENERIC: x and y must be marked as nullable
- int IComparer.Compare(object x, object y)
+ int IComparer.Compare(object? x, object? y)
{
if (x == null) return y == null ? 0 : -1;
if (y == null) return 1;
// Needs to be public to support binary serialization compatibility
public sealed partial class GenericComparer<T> : Comparer<T> where T : IComparable<T>
{
- public override int Compare(T x, T y)
+ public override int Compare(T x, T y) // TODO-NULLABLE-GENERIC: x and y must be marked as nullable
{
if (x != null)
{
}
// Equals method for the comparer itself.
- public override bool Equals(object obj) =>
+ public override bool Equals(object? obj) =>
obj != null && GetType() == obj.GetType();
public override int GetHashCode() =>
}
// Equals method for the comparer itself.
- public override bool Equals(object obj) =>
+ public override bool Equals(object? obj) =>
obj != null && GetType() == obj.GetType();
public override int GetHashCode() =>
// Needs to be public to support binary serialization compatibility
public sealed partial class ObjectComparer<T> : Comparer<T>
{
- public override int Compare(T x, T y)
+ public override int Compare(T x, T y) // TODO-NULLABLE-GENERIC: x and y must be marked as nullable
{
return System.Collections.Comparer.Default.Compare(x, y);
}
// Equals method for the comparer itself.
- public override bool Equals(object obj) =>
+ public override bool Equals(object? obj) =>
obj != null && GetType() == obj.GetType();
public override int GetHashCode() =>
// public override int Compare(T x, T y) is runtime-specific
// Equals method for the comparer itself.
- public override bool Equals(object obj) =>
+ public override bool Equals(object? obj) =>
obj != null && GetType() == obj.GetType();
public override int GetHashCode() =>
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
[DebuggerDisplay("Count = {Count}")]
[Serializable]
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public class Dictionary<TKey, TValue> : IDictionary<TKey, TValue>, IDictionary, IReadOnlyDictionary<TKey, TValue>, ISerializable, IDeserializationCallback
+ public class Dictionary<TKey, TValue> : IDictionary<TKey, TValue>, IDictionary, IReadOnlyDictionary<TKey, TValue>, ISerializable, IDeserializationCallback where TKey : object
{
private struct Entry
{
public TValue value; // Value of entry
}
- private int[] _buckets;
- private Entry[] _entries;
+ private int[]? _buckets;
+ private Entry[]? _entries;
private int _count;
private int _freeList;
private int _freeCount;
private int _version;
- private IEqualityComparer<TKey> _comparer;
- private KeyCollection _keys;
- private ValueCollection _values;
+ private IEqualityComparer<TKey>? _comparer;
+ private KeyCollection? _keys;
+ private ValueCollection? _values;
private const int StartOfFreeList = -3;
// constants for serialization
public Dictionary(int capacity) : this(capacity, null) { }
- public Dictionary(IEqualityComparer<TKey> comparer) : this(0, comparer) { }
+ public Dictionary(IEqualityComparer<TKey>? comparer) : this(0, comparer) { }
- public Dictionary(int capacity, IEqualityComparer<TKey> comparer)
+ public Dictionary(int capacity, IEqualityComparer<TKey>? comparer)
{
if (capacity < 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.capacity);
if (capacity > 0) Initialize(capacity);
public Dictionary(IDictionary<TKey, TValue> dictionary) : this(dictionary, null) { }
- public Dictionary(IDictionary<TKey, TValue> dictionary, IEqualityComparer<TKey> comparer) :
+ public Dictionary(IDictionary<TKey, TValue> dictionary, IEqualityComparer<TKey>? comparer) :
this(dictionary != null ? dictionary.Count : 0, comparer)
{
if (dictionary == null)
// avoid the enumerator allocation and overhead by looping through the entries array directly.
// We only do this when dictionary is Dictionary<TKey,TValue> and not a subclass, to maintain
// back-compat with subclasses that may have overridden the enumerator behavior.
- if (dictionary.GetType() == typeof(Dictionary<TKey, TValue>))
+ if (dictionary!.GetType() == typeof(Dictionary<TKey, TValue>)) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
{
Dictionary<TKey, TValue> d = (Dictionary<TKey, TValue>)dictionary;
int count = d._count;
- Entry[] entries = d._entries;
+ Entry[]? entries = d._entries;
for (int i = 0; i < count; i++)
{
- if (entries[i].next >= -1)
+ if (entries![i].next >= -1)
{
Add(entries[i].key, entries[i].value);
}
public Dictionary(IEnumerable<KeyValuePair<TKey, TValue>> collection) : this(collection, null) { }
- public Dictionary(IEnumerable<KeyValuePair<TKey, TValue>> collection, IEqualityComparer<TKey> comparer) :
+ public Dictionary(IEnumerable<KeyValuePair<TKey, TValue>> collection, IEqualityComparer<TKey>? comparer) :
this((collection as ICollection<KeyValuePair<TKey, TValue>>)?.Count ?? 0, comparer)
{
if (collection == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
}
- foreach (KeyValuePair<TKey, TValue> pair in collection)
+ foreach (KeyValuePair<TKey, TValue> pair in collection!) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
{
Add(pair.Key, pair.Value);
}
get
{
int i = FindEntry(key);
- if (i >= 0) return _entries[i].value;
+ if (i >= 0) return _entries![i].value;
ThrowHelper.ThrowKeyNotFoundException(key);
- return default;
+ return default!; // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538 (annotating ThrowHelper removes this return statement).
}
set
{
bool ICollection<KeyValuePair<TKey, TValue>>.Contains(KeyValuePair<TKey, TValue> keyValuePair)
{
int i = FindEntry(keyValuePair.Key);
- if (i >= 0 && EqualityComparer<TValue>.Default.Equals(_entries[i].value, keyValuePair.Value))
+ if (i >= 0 && EqualityComparer<TValue>.Default.Equals(_entries![i].value, keyValuePair.Value))
{
return true;
}
bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> keyValuePair)
{
int i = FindEntry(keyValuePair.Key);
- if (i >= 0 && EqualityComparer<TValue>.Default.Equals(_entries[i].value, keyValuePair.Value))
+ if (i >= 0 && EqualityComparer<TValue>.Default.Equals(_entries![i].value, keyValuePair.Value))
{
Remove(keyValuePair.Key);
return true;
int count = _count;
if (count > 0)
{
+ Debug.Assert(_buckets != null, "_buckets should be non-null");
+ Debug.Assert(_entries != null, "_entries should be non-null");
+
Array.Clear(_buckets, 0, _buckets.Length);
_count = 0;
public bool ContainsValue(TValue value)
{
- Entry[] entries = _entries;
+ Entry[]? entries = _entries;
if (value == null)
{
for (int i = 0; i < _count; i++)
{
- if (entries[i].next >= -1 && entries[i].value == null) return true;
+ if (entries![i].next >= -1 && entries[i].value == null) return true;
}
}
else
{
- if (default(TValue) != null)
+ if (default(TValue)! != null) // TODO-NULLABLE-GENERIC: https://github.com/dotnet/roslyn/issues/34757
{
// ValueType: Devirtualize with EqualityComparer<TValue>.Default intrinsic
for (int i = 0; i < _count; i++)
{
- if (entries[i].next >= -1 && EqualityComparer<TValue>.Default.Equals(entries[i].value, value)) return true;
+ if (entries![i].next >= -1 && EqualityComparer<TValue>.Default.Equals(entries[i].value, value)) return true;
}
}
else
EqualityComparer<TValue> defaultComparer = EqualityComparer<TValue>.Default;
for (int i = 0; i < _count; i++)
{
- if (entries[i].next >= -1 && defaultComparer.Equals(entries[i].value, value)) return true;
+ if (entries![i].next >= -1 && defaultComparer.Equals(entries[i].value, value)) return true;
}
}
}
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
- if ((uint)index > (uint)array.Length)
+ if ((uint)index > (uint)array!.Length) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
{
ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
}
}
int count = _count;
- Entry[] entries = _entries;
+ Entry[]? entries = _entries;
for (int i = 0; i < count; i++)
{
- if (entries[i].next >= -1)
+ if (entries![i].next >= -1)
{
array[index++] = new KeyValuePair<TKey, TValue>(entries[i].key, entries[i].value);
}
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.info);
}
- info.AddValue(VersionName, _version);
+ info!.AddValue(VersionName, _version); // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
info.AddValue(ComparerName, _comparer ?? EqualityComparer<TKey>.Default, typeof(IEqualityComparer<TKey>));
info.AddValue(HashSizeName, _buckets == null ? 0 : _buckets.Length); // This is the length of the bucket array
}
int i = -1;
- int[] buckets = _buckets;
- Entry[] entries = _entries;
+ int[]? buckets = _buckets;
+ Entry[]? entries = _entries;
int collisionCount = 0;
if (buckets != null)
{
- IEqualityComparer<TKey> comparer = _comparer;
+ Debug.Assert(entries != null, "expected entries to be != null");
+ IEqualityComparer<TKey>? comparer = _comparer;
if (comparer == null)
{
- uint hashCode = (uint)key.GetHashCode();
+ uint hashCode = (uint)key!.GetHashCode(); // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
// Value in _buckets is 1-based
i = buckets[hashCode % (uint)buckets.Length] - 1;
- if (default(TKey) != null)
+ if (default(TKey)! != null) // TODO-NULLABLE-GENERIC: https://github.com/dotnet/roslyn/issues/34757
{
// ValueType: Devirtualize with EqualityComparer<TValue>.Default intrinsic
do
Initialize(0);
}
- Entry[] entries = _entries;
- IEqualityComparer<TKey> comparer = _comparer;
+ Entry[]? entries = _entries;
+ Debug.Assert(entries != null, "expected entries to be non-null");
- uint hashCode = (uint)((comparer == null) ? key.GetHashCode() : comparer.GetHashCode(key));
+ IEqualityComparer<TKey>? comparer = _comparer;
+ uint hashCode = (uint)((comparer == null) ? key!.GetHashCode() : comparer.GetHashCode(key)); // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
int collisionCount = 0;
- ref int bucket = ref _buckets[hashCode % (uint)_buckets.Length];
+ ref int bucket = ref _buckets![hashCode % (uint)_buckets.Length]; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761 (Initialize inits sets _buckets to non null)
// Value in _buckets is 1-based
int i = bucket - 1;
if (comparer == null)
{
- if (default(TKey) != null)
+ if (default(TKey)! != null) // TODO-NULLABLE-GENERIC: https://github.com/dotnet/roslyn/issues/34757
{
// ValueType: Devirtualize with EqualityComparer<TValue>.Default intrinsic
do
entries = _entries;
}
- ref Entry entry = ref entries[index];
+ ref Entry entry = ref entries![index];
if (updateFreeList)
{
_version++;
// Value types never rehash
- if (default(TKey) == null && collisionCount > HashHelpers.HashCollisionThreshold && comparer is NonRandomizedStringEqualityComparer)
+ if (default(TKey)! == null && collisionCount > HashHelpers.HashCollisionThreshold && comparer is NonRandomizedStringEqualityComparer) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34757
{
// If we hit the collision threshold we'll need to switch to the comparer which is using randomized string hashing
// i.e. EqualityComparer<string>.Default.
int realVersion = siInfo.GetInt32(VersionName);
int hashsize = siInfo.GetInt32(HashSizeName);
- _comparer = (IEqualityComparer<TKey>)siInfo.GetValue(ComparerName, typeof(IEqualityComparer<TKey>));
+ _comparer = (IEqualityComparer<TKey>)siInfo.GetValue(ComparerName, typeof(IEqualityComparer<TKey>))!; // When serialized if comparer is null, we use the default.
if (hashsize != 0)
{
Initialize(hashsize);
- KeyValuePair<TKey, TValue>[] array = (KeyValuePair<TKey, TValue>[])
+ KeyValuePair<TKey, TValue>[]? array = (KeyValuePair<TKey, TValue>[]?)
siInfo.GetValue(KeyValuePairsName, typeof(KeyValuePair<TKey, TValue>[]));
if (array == null)
ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_MissingKeys);
}
- for (int i = 0; i < array.Length; i++)
+ for (int i = 0; i < array!.Length; i++) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
{
if (array[i].Key == null)
{
private void Resize(int newSize, bool forceNewHashCodes)
{
// Value types never rehash
- Debug.Assert(!forceNewHashCodes || default(TKey) == null);
+ Debug.Assert(!forceNewHashCodes || default(TKey)! == null); // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34757
+ Debug.Assert(_entries != null, "_entries should be non-null");
Debug.Assert(newSize >= _entries.Length);
int[] buckets = new int[newSize];
int count = _count;
Array.Copy(_entries, 0, entries, 0, count);
- if (default(TKey) == null && forceNewHashCodes)
+ if (default(TKey)! == null && forceNewHashCodes) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34757
{
for (int i = 0; i < count; i++)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
}
- int[] buckets = _buckets;
- Entry[] entries = _entries;
+ int[]? buckets = _buckets;
+ Entry[]? entries = _entries;
int collisionCount = 0;
if (buckets != null)
{
- uint hashCode = (uint)(_comparer?.GetHashCode(key) ?? key.GetHashCode());
+ Debug.Assert(entries != null, "entries should be non-null");
+ uint hashCode = (uint)(_comparer?.GetHashCode(key) ?? key!.GetHashCode()); // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
uint bucket = hashCode % (uint)buckets.Length;
int last = -1;
// Value in buckets is 1-based
if (RuntimeHelpers.IsReferenceOrContainsReferences<TKey>())
{
- entry.key = default;
+ entry.key = default!; // TODO-NULLABLE-GENERIC
}
if (RuntimeHelpers.IsReferenceOrContainsReferences<TValue>())
{
- entry.value = default;
+ entry.value = default!; // TODO-NULLABLE-GENERIC
}
_freeList = i;
_freeCount++;
// This overload is a copy of the overload Remove(TKey key) with one additional
// statement to copy the value for entry being removed into the output parameter.
// Code has been intentionally duplicated for performance reasons.
- public bool Remove(TKey key, out TValue value)
+ public bool Remove(TKey key, out TValue value) // TODO-NULLABLE-GENERIC: https://github.com/dotnet/roslyn/issues/26761
{
if (key == null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
}
- int[] buckets = _buckets;
- Entry[] entries = _entries;
+ int[]? buckets = _buckets;
+ Entry[]? entries = _entries;
int collisionCount = 0;
if (buckets != null)
{
- uint hashCode = (uint)(_comparer?.GetHashCode(key) ?? key.GetHashCode());
+ Debug.Assert(entries != null, "entries should be non-null");
+ uint hashCode = (uint)(_comparer?.GetHashCode(key) ?? key!.GetHashCode()); // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
uint bucket = hashCode % (uint)buckets.Length;
int last = -1;
// Value in buckets is 1-based
if (RuntimeHelpers.IsReferenceOrContainsReferences<TKey>())
{
- entry.key = default;
+ entry.key = default!; // TODO-NULLABLE-GENERIC
}
if (RuntimeHelpers.IsReferenceOrContainsReferences<TValue>())
{
- entry.value = default;
+ entry.value = default!; // TODO-NULLABLE-GENERIC
}
_freeList = i;
_freeCount++;
collisionCount++;
}
}
- value = default;
+ value = default!; // TODO-NULLABLE-GENERIC
return false;
}
- public bool TryGetValue(TKey key, out TValue value)
+ public bool TryGetValue(TKey key, out TValue value) // TODO-NULLABLE-GENERIC: https://github.com/dotnet/roslyn/issues/26761
{
int i = FindEntry(key);
if (i >= 0)
{
- value = _entries[i].value;
+ value = _entries![i].value;
return true;
}
- value = default;
+ value = default!; // TODO-NULLABLE-GENERIC
return false;
}
{
if (array == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- if (array.Rank != 1)
+ if (array!.Rank != 1) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
if (array.GetLowerBound(0) != 0)
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NonZeroLowerBound);
}
else if (array is DictionaryEntry[] dictEntryArray)
{
- Entry[] entries = _entries;
+ Entry[]? entries = _entries;
for (int i = 0; i < _count; i++)
{
- if (entries[i].next >= -1)
+ if (entries![i].next >= -1)
{
dictEntryArray[index++] = new DictionaryEntry(entries[i].key, entries[i].value);
}
}
else
{
- object[] objects = array as object[];
+ object[]? objects = array as object[];
if (objects == null)
{
ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType();
try
{
int count = _count;
- Entry[] entries = _entries;
+ Entry[]? entries = _entries;
for (int i = 0; i < count; i++)
{
- if (entries[i].next >= -1)
+ if (entries![i].next >= -1)
{
- objects[index++] = new KeyValuePair<TKey, TValue>(entries[i].key, entries[i].value);
+ objects![index++] = new KeyValuePair<TKey, TValue>(entries[i].key, entries[i].value); // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
}
}
}
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.capacity);
int newSize = HashHelpers.GetPrime(capacity);
- Entry[] oldEntries = _entries;
+ Entry[]? oldEntries = _entries;
int currentCapacity = oldEntries == null ? 0 : oldEntries.Length;
if (newSize >= currentCapacity)
return;
int oldCount = _count;
_version++;
Initialize(newSize);
- Entry[] entries = _entries;
- int[] buckets = _buckets;
+ Entry[]? entries = _entries;
+ int[]? buckets = _buckets;
int count = 0;
for (int i = 0; i < oldCount; i++)
{
- uint hashCode = oldEntries[i].hashCode;
+ uint hashCode = oldEntries![i].hashCode; // At this point, we know we have entries.
if (oldEntries[i].next >= -1)
{
- ref Entry entry = ref entries[count];
+ ref Entry entry = ref entries![count];
entry = oldEntries[i];
uint bucket = hashCode % (uint)newSize;
// Value in _buckets is 1-based
- entry.next = buckets[bucket] - 1;
+ entry.next = buckets![bucket] - 1; // If we get here, we have entries, therefore buckets is not null.
// Value in _buckets is 1-based
buckets[bucket] = count + 1;
count++;
ICollection IDictionary.Values => (ICollection)Values;
- object IDictionary.this[object key]
+ object? IDictionary.this[object key] // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/2384
{
get
{
int i = FindEntry((TKey)key);
if (i >= 0)
{
- return _entries[i].value;
+ return _entries![i].value;
}
}
return null;
try
{
- TKey tempKey = (TKey)key;
+ TKey tempKey = (TKey)key!; // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
try
{
- this[tempKey] = (TValue)value;
+ this[tempKey] = (TValue)value!;
}
catch (InvalidCastException)
{
return (key is TKey);
}
- void IDictionary.Add(object key, object value)
+ void IDictionary.Add(object key, object? value)
{
if (key == null)
{
try
{
- TKey tempKey = (TKey)key;
+ TKey tempKey = (TKey)key!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
try
{
- Add(tempKey, (TValue)value);
+ Add(tempKey, (TValue)value!);
}
catch (InvalidCastException)
{
// dictionary.count+1 could be negative if dictionary.count is int.MaxValue
while ((uint)_index < (uint)_dictionary._count)
{
- ref Entry entry = ref _dictionary._entries[_index++];
+ ref Entry entry = ref _dictionary._entries![_index++];
if (entry.next >= -1)
{
{
}
- object IEnumerator.Current
+ object? IEnumerator.Current // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/23268
{
get
{
}
}
- object IDictionaryEnumerator.Value
+ object? IDictionaryEnumerator.Value
{
get
{
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.dictionary);
}
- _dictionary = dictionary;
+ _dictionary = dictionary!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
}
public Enumerator GetEnumerator()
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
- if (index < 0 || index > array.Length)
+ if (index < 0 || index > array!.Length) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
{
ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
}
- if (array.Length - index < _dictionary.Count)
+ if (array!.Length - index < _dictionary.Count) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
{
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
}
int count = _dictionary._count;
- Entry[] entries = _dictionary._entries;
+ Entry[]? entries = _dictionary._entries;
for (int i = 0; i < count; i++)
{
- if (entries[i].next >= -1) array[index++] = entries[i].key;
+ if (entries![i].next >= -1) array[index++] = entries[i].key;
}
}
{
if (array == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- if (array.Rank != 1)
+ if (array!.Rank != 1) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
if (array.GetLowerBound(0) != 0)
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NonZeroLowerBound);
}
else
{
- object[] objects = array as object[];
+ object[]? objects = array as object[];
if (objects == null)
{
ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType();
}
int count = _dictionary._count;
- Entry[] entries = _dictionary._entries;
+ Entry[]? entries = _dictionary._entries;
try
{
for (int i = 0; i < count; i++)
{
- if (entries[i].next >= -1) objects[index++] = entries[i].key;
+ if (entries![i].next >= -1) objects![index++] = entries[i].key; // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538 (objects)
}
}
catch (ArrayTypeMismatchException)
_dictionary = dictionary;
_version = dictionary._version;
_index = 0;
- _currentKey = default;
+ _currentKey = default!; // TODO-NULLABLE-GENERIC
}
public void Dispose()
while ((uint)_index < (uint)_dictionary._count)
{
- ref Entry entry = ref _dictionary._entries[_index++];
+ ref Entry entry = ref _dictionary._entries![_index++];
if (entry.next >= -1)
{
}
_index = _dictionary._count + 1;
- _currentKey = default;
+ _currentKey = default!; // TODO-NULLABLE-GENERIC
return false;
}
public TKey Current => _currentKey;
- object IEnumerator.Current
+ object? IEnumerator.Current // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/23268
{
get
{
}
_index = 0;
- _currentKey = default;
+ _currentKey = default!; // TODO-NULLABLE-GENERIC
}
}
}
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.dictionary);
}
- _dictionary = dictionary;
+ _dictionary = dictionary!; // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
}
public Enumerator GetEnumerator()
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
- if (index < 0 || index > array.Length)
+ if ((uint)index > array!.Length) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
{
ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
}
}
int count = _dictionary._count;
- Entry[] entries = _dictionary._entries;
+ Entry[]? entries = _dictionary._entries;
for (int i = 0; i < count; i++)
{
- if (entries[i].next >= -1) array[index++] = entries[i].value;
+ if (entries![i].next >= -1) array[index++] = entries[i].value;
}
}
{
if (array == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- if (array.Rank != 1)
+ if (array!.Rank != 1) // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
if (array.GetLowerBound(0) != 0)
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NonZeroLowerBound);
}
else
{
- object[] objects = array as object[];
+ object[]? objects = array as object[];
if (objects == null)
{
ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType();
}
int count = _dictionary._count;
- Entry[] entries = _dictionary._entries;
+ Entry[]? entries = _dictionary._entries;
try
{
for (int i = 0; i < count; i++)
{
- if (entries[i].next >= -1) objects[index++] = entries[i].value;
+ if (entries![i].next >= -1) objects![index++] = entries[i].value!; // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
}
}
catch (ArrayTypeMismatchException)
_dictionary = dictionary;
_version = dictionary._version;
_index = 0;
- _currentValue = default;
+ _currentValue = default!; // TODO-NULLABLE-GENERIC
}
public void Dispose()
while ((uint)_index < (uint)_dictionary._count)
{
- ref Entry entry = ref _dictionary._entries[_index++];
+ ref Entry entry = ref _dictionary._entries![_index++];
if (entry.next >= -1)
{
}
}
_index = _dictionary._count + 1;
- _currentValue = default;
+ _currentValue = default!; // TODO-NULLABLE-GENERIC
return false;
}
public TValue Current => _currentValue;
- object IEnumerator.Current
+ object? IEnumerator.Current
{
get
{
ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion();
}
_index = 0;
- _currentValue = default;
+ _currentValue = default!; // TODO-NULLABLE-GENERIC
}
}
}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
// public static EqualityComparer<T> Default is runtime-specific
public abstract bool Equals(T x, T y);
- public abstract int GetHashCode(T obj);
+ public abstract int GetHashCode(T obj); // TODO-NULLABLE-GENERIC: Shouldn't accept nulls.
- int IEqualityComparer.GetHashCode(object obj)
+#pragma warning disable CS8617 // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/30958
+ int IEqualityComparer.GetHashCode(object? obj)
+#pragma warning restore CS8617
{
if (obj == null) return 0;
if (obj is T) return GetHashCode((T)obj);
return 0;
}
- bool IEqualityComparer.Equals(object x, object y)
+ bool IEqualityComparer.Equals(object? x, object? y)
{
if (x == y) return true;
if (x == null || y == null) return false;
// Equals method for the comparer itself.
// If in the future this type is made sealed, change the is check to obj != null && GetType() == obj.GetType().
- public override bool Equals(object obj) =>
+ public override bool Equals(object? obj) =>
obj is GenericEqualityComparer<T>;
// If in the future this type is made sealed, change typeof(...) to GetType().
public override int GetHashCode(T? obj) => obj.GetHashCode();
// Equals method for the comparer itself.
- public override bool Equals(object obj) =>
+ public override bool Equals(object? obj) =>
obj != null && GetType() == obj.GetType();
public override int GetHashCode() =>
public override int GetHashCode(T obj) => obj?.GetHashCode() ?? 0;
// Equals method for the comparer itself.
- public override bool Equals(object obj) =>
+ public override bool Equals(object? obj) =>
obj != null && GetType() == obj.GetType();
public override int GetHashCode() =>
}
// Equals method for the comparer itself.
- public override bool Equals(object obj) =>
+ public override bool Equals(object? obj) =>
obj != null && GetType() == obj.GetType();
public override int GetHashCode() =>
}
// Equals method for the comparer itself.
- public override bool Equals(object obj) =>
+ public override bool Equals(object? obj) =>
obj != null && GetType() == obj.GetType();
public override int GetHashCode() =>
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System.ComponentModel;
using System.Text;
/// <summary>
/// Used by KeyValuePair.ToString to reduce generic code
/// </summary>
- internal static string PairToString(object key, object value)
+ internal static string PairToString(object? key, object? value)
{
StringBuilder s = StringBuilderCache.Acquire();
s.Append('[');
// 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;
+#nullable enable
namespace System.Collections
{
// Interfaces are not serializable
// The Item property provides methods to read and edit entries
// in the Dictionary.
- object this[object key]
+ object? this[object key] // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/2384
{
get;
set;
// Adds a key-value pair to the dictionary.
//
- void Add(object key, object value);
+ void Add(object key, object? value);
// Removes all pairs from the dictionary.
void Clear();
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
namespace System.Collections
{
// This interface represents an enumerator that allows sequential access to the
// to GetValue with no intervening calls to GetNext will
// return the same object.
//
- object Value
+ object? Value
{
get;
}
// 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;
-
+#nullable enable
namespace System.Collections
{
// An IEqualityComparer is a mechanism to consume custom performant comparison infrastructure
// that can be consumed by some of the common collections.
public interface IEqualityComparer
{
- bool Equals(object x, object y);
+ bool Equals(object? x, object? y);
int GetHashCode(object obj);
}
}
while (enumerator.MoveNext())
{
string attrName = (string)enumerator.Key;
- string attrValue = (string)enumerator.Value;
+ string? attrValue = (string?)enumerator.Value;
if (!IsValidAttributeName(attrName))
throw new ArgumentException(SR.Format(SR.Argument_InvalidElementName, attrName));
int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
{
- return comparer.GetHashCode(m_Item1);
+ return comparer.GetHashCode(m_Item1!); // TODO-NULLABLE-GENERIC
}
int ITupleInternal.GetHashCode(IEqualityComparer comparer)
int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
{
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1), comparer.GetHashCode(m_Item2));
+ return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!)); // TODO-NULLABLE-GENERIC
}
int ITupleInternal.GetHashCode(IEqualityComparer comparer)
int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
{
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1), comparer.GetHashCode(m_Item2), comparer.GetHashCode(m_Item3));
+ return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!)); // TODO-NULLABLE-GENERIC
}
int ITupleInternal.GetHashCode(IEqualityComparer comparer)
int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
{
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1), comparer.GetHashCode(m_Item2), comparer.GetHashCode(m_Item3), comparer.GetHashCode(m_Item4));
+ return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!)); // TODO-NULLABLE-GENERIC
}
int ITupleInternal.GetHashCode(IEqualityComparer comparer)
int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
{
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1), comparer.GetHashCode(m_Item2), comparer.GetHashCode(m_Item3), comparer.GetHashCode(m_Item4), comparer.GetHashCode(m_Item5));
+ return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!)); // TODO-NULLABLE-GENERIC
}
int ITupleInternal.GetHashCode(IEqualityComparer comparer)
int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
{
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1), comparer.GetHashCode(m_Item2), comparer.GetHashCode(m_Item3), comparer.GetHashCode(m_Item4), comparer.GetHashCode(m_Item5), comparer.GetHashCode(m_Item6));
+ return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!)); // TODO-NULLABLE-GENERIC
}
int ITupleInternal.GetHashCode(IEqualityComparer comparer)
int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
{
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1), comparer.GetHashCode(m_Item2), comparer.GetHashCode(m_Item3), comparer.GetHashCode(m_Item4), comparer.GetHashCode(m_Item5), comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7));
+ return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!)); // TODO-NULLABLE-GENERIC
}
int ITupleInternal.GetHashCode(IEqualityComparer comparer)
switch (k)
{
case 1:
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item7), t.GetHashCode(comparer));
+ return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer)); // TODO-NULLABLE-GENERIC
case 2:
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7), t.GetHashCode(comparer));
+ return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer)); // TODO-NULLABLE-GENERIC
case 3:
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item5), comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7), t.GetHashCode(comparer));
+ return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer)); // TODO-NULLABLE-GENERIC
case 4:
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item4), comparer.GetHashCode(m_Item5), comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7), t.GetHashCode(comparer));
+ return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer)); // TODO-NULLABLE-GENERIC
case 5:
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item3), comparer.GetHashCode(m_Item4), comparer.GetHashCode(m_Item5), comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7), t.GetHashCode(comparer));
+ return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer)); // TODO-NULLABLE-GENERIC
case 6:
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item2), comparer.GetHashCode(m_Item3), comparer.GetHashCode(m_Item4), comparer.GetHashCode(m_Item5), comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7), t.GetHashCode(comparer));
+ return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer)); // TODO-NULLABLE-GENERIC
case 7:
- return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1), comparer.GetHashCode(m_Item2), comparer.GetHashCode(m_Item3), comparer.GetHashCode(m_Item4), comparer.GetHashCode(m_Item5), comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7), t.GetHashCode(comparer));
+ return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1!), comparer.GetHashCode(m_Item2!), comparer.GetHashCode(m_Item3!), comparer.GetHashCode(m_Item4!), comparer.GetHashCode(m_Item5!), comparer.GetHashCode(m_Item6!), comparer.GetHashCode(m_Item7!), t.GetHashCode(comparer)); // TODO-NULLABLE-GENERIC
}
Debug.Fail("Missed all cases for computing Tuple hash code");
return -1;
int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
{
- return comparer.GetHashCode(Item1);
+ return comparer.GetHashCode(Item1!); // TODO-NULLABLE-GENERIC
}
int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
{
- return comparer.GetHashCode(Item1);
+ return comparer.GetHashCode(Item1!); // TODO-NULLABLE-GENERIC
}
/// <summary>
private int GetHashCodeCore(IEqualityComparer comparer)
{
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item1),
- comparer.GetHashCode(Item2));
+ return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item1!),
+ comparer.GetHashCode(Item2!)); // TODO-NULLABLE-GENERIC
}
int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
private int GetHashCodeCore(IEqualityComparer comparer)
{
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item1),
- comparer.GetHashCode(Item2),
- comparer.GetHashCode(Item3));
+ return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item1!),
+ comparer.GetHashCode(Item2!),
+ comparer.GetHashCode(Item3!)); // TODO-NULLABLE-GENERIC
}
int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
private int GetHashCodeCore(IEqualityComparer comparer)
{
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item1),
- comparer.GetHashCode(Item2),
- comparer.GetHashCode(Item3),
- comparer.GetHashCode(Item4));
+ return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item1!),
+ comparer.GetHashCode(Item2!),
+ comparer.GetHashCode(Item3!),
+ comparer.GetHashCode(Item4!)); // TODO-NULLABLE-GENERIC
}
int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
private int GetHashCodeCore(IEqualityComparer comparer)
{
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item1),
- comparer.GetHashCode(Item2),
- comparer.GetHashCode(Item3),
- comparer.GetHashCode(Item4),
- comparer.GetHashCode(Item5));
+ return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item1!),
+ comparer.GetHashCode(Item2!),
+ comparer.GetHashCode(Item3!),
+ comparer.GetHashCode(Item4!),
+ comparer.GetHashCode(Item5!)); // TODO-NULLABLE-GENERIC
}
int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
private int GetHashCodeCore(IEqualityComparer comparer)
{
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item1),
- comparer.GetHashCode(Item2),
- comparer.GetHashCode(Item3),
- comparer.GetHashCode(Item4),
- comparer.GetHashCode(Item5),
- comparer.GetHashCode(Item6));
+ return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item1!),
+ comparer.GetHashCode(Item2!),
+ comparer.GetHashCode(Item3!),
+ comparer.GetHashCode(Item4!),
+ comparer.GetHashCode(Item5!),
+ comparer.GetHashCode(Item6!)); // TODO-NULLABLE-GENERIC
}
int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
private int GetHashCodeCore(IEqualityComparer comparer)
{
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item1),
- comparer.GetHashCode(Item2),
- comparer.GetHashCode(Item3),
- comparer.GetHashCode(Item4),
- comparer.GetHashCode(Item5),
- comparer.GetHashCode(Item6),
- comparer.GetHashCode(Item7));
+ return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item1!),
+ comparer.GetHashCode(Item2!),
+ comparer.GetHashCode(Item3!),
+ comparer.GetHashCode(Item4!),
+ comparer.GetHashCode(Item5!),
+ comparer.GetHashCode(Item6!),
+ comparer.GetHashCode(Item7!)); // TODO-NULLABLE-GENERIC
}
int IValueTupleInternal.GetHashCode(IEqualityComparer comparer)
IValueTupleInternal? rest = Rest as IValueTupleInternal;
if (rest == null)
{
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item1), comparer.GetHashCode(Item2), comparer.GetHashCode(Item3),
- comparer.GetHashCode(Item4), comparer.GetHashCode(Item5), comparer.GetHashCode(Item6),
- comparer.GetHashCode(Item7));
+ return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item1!), comparer.GetHashCode(Item2!), comparer.GetHashCode(Item3!),
+ comparer.GetHashCode(Item4!), comparer.GetHashCode(Item5!), comparer.GetHashCode(Item6!),
+ comparer.GetHashCode(Item7!)); // TODO-NULLABLE-GENERIC
}
int size = rest.Length;
switch (k)
{
case 1:
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item7), rest.GetHashCode(comparer));
+ return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item7!), rest.GetHashCode(comparer)); // TODO-NULLABLE-GENERIC
case 2:
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item6), comparer.GetHashCode(Item7), rest.GetHashCode(comparer));
+ return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item6!), comparer.GetHashCode(Item7!), rest.GetHashCode(comparer)); // TODO-NULLABLE-GENERIC
case 3:
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item5), comparer.GetHashCode(Item6), comparer.GetHashCode(Item7),
- rest.GetHashCode(comparer));
+ return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item5!), comparer.GetHashCode(Item6!), comparer.GetHashCode(Item7!),
+ rest.GetHashCode(comparer)); // TODO-NULLABLE-GENERIC
case 4:
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item4), comparer.GetHashCode(Item5), comparer.GetHashCode(Item6),
- comparer.GetHashCode(Item7), rest.GetHashCode(comparer));
+ return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item4!), comparer.GetHashCode(Item5!), comparer.GetHashCode(Item6!),
+ comparer.GetHashCode(Item7!), rest.GetHashCode(comparer)); // TODO-NULLABLE-GENERIC
case 5:
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item3), comparer.GetHashCode(Item4), comparer.GetHashCode(Item5),
- comparer.GetHashCode(Item6), comparer.GetHashCode(Item7), rest.GetHashCode(comparer));
+ return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item3!), comparer.GetHashCode(Item4!), comparer.GetHashCode(Item5!),
+ comparer.GetHashCode(Item6!), comparer.GetHashCode(Item7!), rest.GetHashCode(comparer)); // TODO-NULLABLE-GENERIC
case 6:
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item2), comparer.GetHashCode(Item3), comparer.GetHashCode(Item4),
- comparer.GetHashCode(Item5), comparer.GetHashCode(Item6), comparer.GetHashCode(Item7),
- rest.GetHashCode(comparer));
+ return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item2!), comparer.GetHashCode(Item3!), comparer.GetHashCode(Item4!),
+ comparer.GetHashCode(Item5!), comparer.GetHashCode(Item6!), comparer.GetHashCode(Item7!),
+ rest.GetHashCode(comparer)); // TODO-NULLABLE-GENERIC
case 7:
case 8:
- return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item1), comparer.GetHashCode(Item2), comparer.GetHashCode(Item3),
- comparer.GetHashCode(Item4), comparer.GetHashCode(Item5), comparer.GetHashCode(Item6),
- comparer.GetHashCode(Item7), rest.GetHashCode(comparer));
+ return ValueTuple.CombineHashCodes(comparer.GetHashCode(Item1!), comparer.GetHashCode(Item2!), comparer.GetHashCode(Item3!),
+ comparer.GetHashCode(Item4!), comparer.GetHashCode(Item5!), comparer.GetHashCode(Item6!),
+ comparer.GetHashCode(Item7!), rest.GetHashCode(comparer)); // TODO-NULLABLE-GENERIC
}
Debug.Fail("Missed all cases for computing ValueTuple hash code");