int dwFlagsAndAttributes,
IntPtr hTemplateFile)
{
- lpFileName = PathInternal.EnsureExtendedPrefixIfNeeded(lpFileName)!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
+ lpFileName = PathInternal.EnsureExtendedPrefixIfNeeded(lpFileName);
return CreateFilePrivate(lpFileName, dwDesiredAccess, dwShareMode, ref securityAttrs, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
}
}
FileMode dwCreationDisposition,
ref Kernel32.CREATEFILE2_EXTENDED_PARAMETERS pCreateExParams)
{
- lpFileName = PathInternal.EnsureExtendedPrefixIfNeeded(lpFileName)!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
+ lpFileName = PathInternal.EnsureExtendedPrefixIfNeeded(lpFileName);
return CreateFile2Private(lpFileName, dwDesiredAccess, dwShareMode, dwCreationDisposition, ref pCreateExParams);
}
}
internal static SafeFindHandle FindFirstFile(string fileName, ref WIN32_FIND_DATA data)
{
- fileName = PathInternal.EnsureExtendedPrefixIfNeeded(fileName)!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
+ fileName = PathInternal.EnsureExtendedPrefixIfNeeded(fileName);
// use FindExInfoBasic since we don't care about short name and it has better perf
return FindFirstFileExPrivate(fileName, FINDEX_INFO_LEVELS.FindExInfoBasic, ref data, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, 0);
internal static bool GetFileAttributesEx(string name, GET_FILEEX_INFO_LEVELS fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation)
{
- name = PathInternal.EnsureExtendedPrefixIfNeeded(name)!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
+ name = PathInternal.EnsureExtendedPrefixIfNeeded(name);
return GetFileAttributesExPrivate(name, fileInfoLevel, ref lpFileInformation);
}
}
}
#pragma warning disable CS0067 // events raised by the VM
- public static event UnhandledExceptionEventHandler UnhandledException;
+ public static event UnhandledExceptionEventHandler UnhandledException; // TODO-NULLABLE: Should all events use nullable delegate types?
- public static event System.EventHandler<FirstChanceExceptionEventArgs> FirstChanceException;
+ public static event System.EventHandler<FirstChanceExceptionEventArgs> FirstChanceException; // TODO-NULLABLE: Should all events use nullable delegate types?
#pragma warning restore CS0067
- public static event System.EventHandler ProcessExit;
+ public static event System.EventHandler ProcessExit; // TODO-NULLABLE: Should all events use nullable delegate types?
internal static void OnProcessExit()
{
Interlocked.CompareExchange(ref s_switches, new Dictionary<string, bool>(), null);
}
- lock (s_switches!) // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability
+ lock (s_switches)
{
s_switches[switchName] = isEnabled;
}
public PermissionSet PermissionSet => new PermissionSet(PermissionState.Unrestricted);
- public event UnhandledExceptionEventHandler UnhandledException
+ public event UnhandledExceptionEventHandler UnhandledException // TODO-NULLABLE: Should all events use nullable delegate types?
{
add { AppContext.UnhandledException += value; }
remove { AppContext.UnhandledException -= value; }
public bool IsHomogenous => true;
- public event EventHandler DomainUnload = null!;
+ public event EventHandler DomainUnload = null!; // TODO-NULLABLE: Should all events use nullable delegate types?
- public event EventHandler<FirstChanceExceptionEventArgs> FirstChanceException
+ public event EventHandler<FirstChanceExceptionEventArgs> FirstChanceException // TODO-NULLABLE: Should all events use nullable delegate types?
{
add { AppContext.FirstChanceException += value; }
remove { AppContext.FirstChanceException -= value; }
}
- public event EventHandler ProcessExit
+ public event EventHandler ProcessExit // TODO-NULLABLE: Should all events use nullable delegate types?
{
add { AppContext.ProcessExit += value; }
remove { AppContext.ProcessExit -= value; }
public Assembly[] GetAssemblies() => AssemblyLoadContext.GetLoadedAssemblies();
- public event AssemblyLoadEventHandler AssemblyLoad
+ public event AssemblyLoadEventHandler AssemblyLoad // TODO-NULLABLE: Should all events use nullable delegate types?
{
add { AssemblyLoadContext.AssemblyLoad += value; }
remove { AssemblyLoadContext.AssemblyLoad -= value; }
}
- public event ResolveEventHandler AssemblyResolve
+ public event ResolveEventHandler AssemblyResolve // TODO-NULLABLE: Should all events use nullable delegate types?
{
add { AssemblyLoadContext.AssemblyResolve += value; }
remove { AssemblyLoadContext.AssemblyResolve -= value; }
}
- public event ResolveEventHandler ReflectionOnlyAssemblyResolve = null!;
+ public event ResolveEventHandler ReflectionOnlyAssemblyResolve = null!; // TODO-NULLABLE: Should all events use nullable delegate types?
- public event ResolveEventHandler TypeResolve
+ public event ResolveEventHandler TypeResolve // TODO-NULLABLE: Should all events use nullable delegate types?
{
add { AssemblyLoadContext.TypeResolve += value; }
remove { AssemblyLoadContext.TypeResolve -= value; }
}
- public event ResolveEventHandler ResourceResolve
+ public event ResolveEventHandler ResourceResolve // TODO-NULLABLE: Should all events use nullable delegate types?
{
add { AssemblyLoadContext.ResourceResolve += value; }
remove { AssemblyLoadContext.ResourceResolve -= value; }
(Func<IPrincipal>)mi.CreateDelegate(typeof(Func<IPrincipal>)));
}
- principal = s_getUnauthenticatedPrincipal!(); // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
+ principal = s_getUnauthenticatedPrincipal();
break;
case PrincipalPolicy.WindowsPrincipal:
(Func<IPrincipal>)mi.CreateDelegate(typeof(Func<IPrincipal>)));
}
- principal = s_getWindowsPrincipal!(); // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
+ principal = s_getWindowsPrincipal();
break;
}
}
}
// T[] implements IList<T>.
- return new ReadOnlyCollection<T>(array!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return new ReadOnlyCollection<T>(array);
}
public static void Resize<T>([NotNull] ref T[]? array, int newSize)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.lengths);
}
- if (lengths!.Length == 0) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (lengths.Length == 0)
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NeedAtLeast1Rank);
int[] intLengths = new int[lengths.Length];
{
if (indices == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.indices);
- if (Rank != indices!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (Rank != indices.Length)
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankIndices);
int[] intIndices = new int[indices.Length];
{
if (indices == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.indices);
- if (Rank != indices!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (Rank != indices.Length)
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankIndices);
int[] intIndices = new int[indices.Length];
int i = 0;
int c = 0;
- while (i < o!.Length && c == 0) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ while (i < o.Length && c == 0)
{
object? left = GetValue(i);
object? right = o.GetValue(i);
for (int i = (this.Length >= 8 ? this.Length - 8 : 0); i < this.Length; i++)
{
- ret = CombineHashCodes(ret, comparer!.GetHashCode(GetValue(i)!)); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ ret = CombineHashCodes(ret, comparer.GetHashCode(GetValue(i)!));
}
return ret;
{
if (array == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- return BinarySearch(array!, array!.GetLowerBound(0), array.Length, value, null); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return BinarySearch(array, array.GetLowerBound(0), array.Length, value, null);
}
// Searches a section of an array for a given element using a binary search
{
if (array == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- return BinarySearch(array!, array!.GetLowerBound(0), array.Length, value, comparer); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return BinarySearch(array, array.GetLowerBound(0), array.Length, value, comparer);
}
// Searches a section of an array for a given element using a binary search
{
if (array == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- int lb = array!.GetLowerBound(0); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ int lb = array.GetLowerBound(0);
if (index < lb)
ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
if (length < 0)
{
if (array == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- return BinarySearch<T>(array!, 0, array!.Length, value, null); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return BinarySearch<T>(array, 0, array.Length, value, null);
}
public static int BinarySearch<T>(T[] array, T value, System.Collections.Generic.IComparer<T>? comparer)
{
if (array == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- return BinarySearch<T>(array!, 0, array!.Length, value, comparer); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return BinarySearch<T>(array, 0, array.Length, value, comparer);
}
public static int BinarySearch<T>(T[] array, int index, int length, T value)
if (length < 0)
ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum();
- if (array!.Length - index < length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (array.Length - index < length)
ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
return ArraySortHelper<T>.Default.BinarySearch(array, index, length, value, comparer);
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.converter);
}
- TOutput[] newArray = new TOutput[array!.Length]; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ TOutput[] newArray = new TOutput[array.Length];
for (int i = 0; i < array.Length; i++)
{
- newArray[i] = converter!(array[i]); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ newArray[i] = converter(array[i]);
}
return newArray;
}
if (array != null && array.Rank != 1)
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
// Note: Array.Copy throws a RankException and we want a consistent ArgumentException for all the IList CopyTo methods.
- Array.Copy(this, GetLowerBound(0), array!, index, Length); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ Array.Copy(this, GetLowerBound(0), array!, index, Length);
}
public void CopyTo(Array array, long index)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
- for (int i = 0; i < array!.Length; i++) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ for (int i = 0; i < array.Length; i++)
{
array[i] = value;
}
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
- if (startIndex < 0 || startIndex > array!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (startIndex < 0 || startIndex > array.Length)
{
ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
}
- if (count < 0 || startIndex > array!.Length - count) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (count < 0 || startIndex > array.Length - count)
{
ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count();
}
for (int i = startIndex; i < startIndex + count; i++)
{
- array![i] = value; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ array[i] = value;
}
}
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
}
- for (int i = 0; i < array!.Length; i++) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ for (int i = 0; i < array.Length; i++)
{
- if (match!(array[i])) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (match(array[i]))
{
return array[i];
}
}
List<T> list = new List<T>();
- for (int i = 0; i < array!.Length; i++) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ for (int i = 0; i < array.Length; i++)
{
- if (match!(array[i])) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (match(array[i]))
{
list.Add(array[i]);
}
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
- return FindIndex(array!, 0, array!.Length, match); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return FindIndex(array, 0, array.Length, match);
}
public static int FindIndex<T>(T[] array, int startIndex, Predicate<T> match)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
- return FindIndex(array!, startIndex, array!.Length - startIndex, match); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return FindIndex(array, startIndex, array.Length - startIndex, match);
}
public static int FindIndex<T>(T[] array, int startIndex, int count, Predicate<T> match)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
- if (startIndex < 0 || startIndex > array!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (startIndex < 0 || startIndex > array.Length)
{
ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
}
- if (count < 0 || startIndex > array!.Length - count) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (count < 0 || startIndex > array.Length - count)
{
ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count();
}
int endIndex = startIndex + count;
for (int i = startIndex; i < endIndex; i++)
{
- if (match!(array![i])) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (match!(array[i]))
return i;
}
return -1;
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
}
- for (int i = array!.Length - 1; i >= 0; i--) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ for (int i = array.Length - 1; i >= 0; i--)
{
- if (match!(array[i])) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (match(array[i]))
{
return array[i];
}
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
- return FindLastIndex(array!, array!.Length - 1, array.Length, match); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return FindLastIndex(array, array.Length - 1, array.Length, match);
}
public static int FindLastIndex<T>(T[] array, int startIndex, Predicate<T> match)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
- return FindLastIndex(array!, startIndex, startIndex + 1, match); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return FindLastIndex(array, startIndex, startIndex + 1, match);
}
public static int FindLastIndex<T>(T[] array, int startIndex, int count, Predicate<T> match)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
}
- if (array!.Length == 0) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (array.Length == 0)
{
// Special case for 0 length List
if (startIndex != -1)
int endIndex = startIndex - count;
for (int i = startIndex; i > endIndex; i--)
{
- if (match!(array[i])) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (match(array[i]))
{
return i;
}
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.action);
}
- for (int i = 0; i < array!.Length; i++) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ for (int i = 0; i < array.Length; i++)
{
- action!(array[i]); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ action(array[i]);
}
}
{
if (array == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- return IndexOf(array!, value, array!.GetLowerBound(0), array.Length); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return IndexOf(array, value, array.GetLowerBound(0), array.Length);
}
// Returns the index of the first occurrence of a given value in a range of
{
if (array == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- int lb = array!.GetLowerBound(0); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ int lb = array.GetLowerBound(0);
return IndexOf(array, value, startIndex, array.Length - startIndex + lb);
}
{
if (array == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- if (array!.Rank != 1) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (array.Rank != 1)
ThrowHelper.ThrowRankException(ExceptionResource.Rank_MultiDimNotSupported);
int lb = array.GetLowerBound(0);
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
- return IndexOf(array!, value, 0, array!.Length); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return IndexOf(array, value, 0, array.Length);
}
public static int IndexOf<T>(T[] array, T value, int startIndex)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
- return IndexOf(array!, value, startIndex, array!.Length - startIndex); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return IndexOf(array, value, startIndex, array.Length - startIndex);
}
public static int IndexOf<T>(T[] array, T value, int startIndex, int count)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
- if ((uint)startIndex > (uint)array!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if ((uint)startIndex > (uint)array.Length)
{
ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
}
{
if (array == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- int lb = array!.GetLowerBound(0); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ int lb = array.GetLowerBound(0);
return LastIndexOf(array, value, array.Length - 1 + lb, array.Length);
}
{
if (array == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- int lb = array!.GetLowerBound(0); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ int lb = array.GetLowerBound(0);
return LastIndexOf(array, value, startIndex, startIndex + 1 - lb);
}
{
if (array == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- int lb = array!.GetLowerBound(0); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ int lb = array.GetLowerBound(0);
if (array.Length == 0)
{
return lb - 1;
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
- return LastIndexOf(array!, value, array!.Length - 1, array.Length); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return LastIndexOf(array, value, array.Length - 1, array.Length);
}
public static int LastIndexOf<T>(T[] array, T value, int startIndex)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
// if array is empty and startIndex is 0, we need to pass 0 as count
- return LastIndexOf(array!, value, startIndex, (array!.Length == 0) ? 0 : (startIndex + 1)); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return LastIndexOf(array, value, startIndex, (array.Length == 0) ? 0 : (startIndex + 1));
}
public static int LastIndexOf<T>(T[] array, T value, int startIndex, int count)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
- if (array!.Length == 0) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (array.Length == 0)
{
//
// Special case for 0 length List
{
if (array == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- Reverse(array!, array!.GetLowerBound(0), array.Length); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ Reverse(array, array.GetLowerBound(0), array.Length);
}
// Reverses the elements in a range of an array. Following a call to this
{
if (array == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- int lowerBound = array!.GetLowerBound(0); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ int lowerBound = array.GetLowerBound(0);
if (index < lowerBound)
ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
if (length < 0)
{
if (array == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- Reverse(array!, 0, array!.Length); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ Reverse(array, 0, array.Length);
}
public static void Reverse<T>(T[] array, int index, int length)
ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
if (length < 0)
ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum();
- if (array!.Length - index < length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (array.Length - index < length)
ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
if (length <= 1)
{
if (array == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- Sort(array!, null, array!.GetLowerBound(0), array.Length, null); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ Sort(array, null, array.GetLowerBound(0), array.Length, null);
}
// Sorts the elements of two arrays based on the keys in the first array.
{
if (keys == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys);
- Sort(keys!, items, keys!.GetLowerBound(0), keys.Length, null); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ Sort(keys, items, keys.GetLowerBound(0), keys.Length, null);
}
// Sorts the elements in a section of an array. The sort compares the
{
if (keys == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys);
- Sort(keys!, items, keys!.GetLowerBound(0), keys.Length, comparer); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ Sort(keys, items, keys.GetLowerBound(0), keys.Length, comparer);
}
// Sorts the elements in a section of an array. The sort compares the
{
if (keys == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys);
- if (keys!.Rank != 1 || (items != null && items.Rank != 1)) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (keys.Rank != 1 || (items != null && items.Rank != 1))
ThrowHelper.ThrowRankException(ExceptionResource.Rank_MultiDimNotSupported);
int keysLowerBound = keys.GetLowerBound(0);
if (items != null && keysLowerBound != items.GetLowerBound(0))
{
if (array == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- Sort<T>(array!, 0, array!.Length, null); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ Sort<T>(array, 0, array.Length, null);
}
public static void Sort<TKey, TValue>(TKey[] keys, TValue[]? items)
{
if (keys == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys);
- Sort<TKey, TValue>(keys!, items, 0, keys!.Length, null); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ Sort<TKey, TValue>(keys, items, 0, keys.Length, null);
}
public static void Sort<T>(T[] array, int index, int length)
{
if (array == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- Sort<T>(array!, 0, array!.Length, comparer); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ Sort<T>(array, 0, array.Length, comparer);
}
public static void Sort<TKey, TValue>(TKey[] keys, TValue[]? items, System.Collections.Generic.IComparer<TKey>? comparer)
{
if (keys == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys);
- Sort<TKey, TValue>(keys!, items, 0, keys!.Length, comparer); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ Sort<TKey, TValue>(keys, items, 0, keys.Length, comparer);
}
public static void Sort<T>(T[] array, int index, int length, System.Collections.Generic.IComparer<T>? comparer)
ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
if (length < 0)
ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum();
- if (array!.Length - index < length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (array.Length - index < length)
ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
if (length > 1)
ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
if (length < 0)
ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum();
- if (keys!.Length - index < length || (items != null && index > items.Length - length)) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (keys.Length - index < length || (items != null && index > items.Length - length))
ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
if (length > 1)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparison);
}
- ArraySortHelper<T>.Sort(array!, 0, array!.Length, comparison!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ ArraySortHelper<T>.Sort(array, 0, array.Length, comparison!);
}
public static bool TrueForAll<T>(T[] array, Predicate<T> match)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
}
- for (int i = 0; i < array!.Length; i++) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ for (int i = 0; i < array.Length; i++)
{
- if (!match!(array[i])) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (!match(array[i]))
{
return false;
}
_array = array;
_offset = 0;
- _count = array!.Length; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ _count = array.Length;
}
public ArraySegment(T[] array, int offset, int count)
{
if (value == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value);
- if (unchecked((uint)startIndex) >= unchecked((uint)value!.Length)) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (unchecked((uint)startIndex) >= unchecked((uint)value.Length))
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
if (startIndex > value.Length - sizeof(short))
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall, ExceptionArgument.value);
{
if (value == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value);
- if (unchecked((uint)startIndex) >= unchecked((uint)value!.Length)) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (unchecked((uint)startIndex) >= unchecked((uint)value.Length))
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
if (startIndex > value.Length - sizeof(int))
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall, ExceptionArgument.value);
{
if (value == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value);
- if (unchecked((uint)startIndex) >= unchecked((uint)value!.Length)) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (unchecked((uint)startIndex) >= unchecked((uint)value.Length))
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
if (startIndex > value.Length - sizeof(long))
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall, ExceptionArgument.value);
{
if (value == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value);
- if (startIndex < 0 || startIndex >= value!.Length && startIndex > 0) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (startIndex < 0 || startIndex >= value.Length && startIndex > 0)
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
if (length < 0)
throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_GenericPositive);
- if (startIndex > value!.Length - length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (startIndex > value.Length - length)
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall, ExceptionArgument.value);
if (length == 0)
{
if (value == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value);
- return ToString(value!, 0, value!.Length); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return ToString(value, 0, value.Length);
}
// Converts an array of bytes into a String.
{
if (value == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value);
- return ToString(value!, startIndex, value!.Length - startIndex); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return ToString(value, startIndex, value.Length - startIndex);
}
/*==================================ToBoolean===================================
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value);
if (startIndex < 0)
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
- if (startIndex > value!.Length - 1) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (startIndex > value.Length - 1)
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); // differs from other overloads, which throw base ArgumentException
return value[startIndex] != 0;
// Initialize the segment and add all of the data to it.
_tail = _head = new ConcurrentQueueSegment<T>(length);
- foreach (T item in collection!) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ foreach (T item in collection)
{
Enqueue(item);
}
// Otherwise, fall back to the slower path that first copies the contents
// to an array, and then uses that array's non-generic CopyTo to do the copy.
- ToArray().CopyTo(array!, index); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ ToArray().CopyTo(array, index);
}
/// <summary>
/// cref="ICollection"/>. This property is not supported.
/// </summary>
/// <exception cref="NotSupportedException">The SyncRoot property is not supported.</exception>
- object ICollection.SyncRoot { get { ThrowHelper.ThrowNotSupportedException(ExceptionResource.ConcurrentCollection_SyncRoot_NotSupported); return default!; } } // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ object ICollection.SyncRoot { get { ThrowHelper.ThrowNotSupportedException(ExceptionResource.ConcurrentCollection_SyncRoot_NotSupported); return default; } }
/// <summary>Returns an enumerator that iterates through a collection.</summary>
/// <returns>An <see cref="IEnumerator"/> that can be used to iterate through the collection.</returns>
// Get the number of items to be enumerated
long count = GetCount(head, headHead, tail, tailTail);
- if (index > array!.Length - count) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (index > array.Length - count)
{
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
}
// 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>)) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (dictionary.GetType() == typeof(Dictionary<TKey, TValue>))
{
Dictionary<TKey, TValue> d = (Dictionary<TKey, TValue>)dictionary;
int count = d._count;
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
}
- foreach (KeyValuePair<TKey, TValue> pair in collection!) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ foreach (KeyValuePair<TKey, TValue> pair in collection)
{
Add(pair.Key, pair.Value);
}
int i = FindEntry(key);
if (i >= 0) return _entries![i].value;
ThrowHelper.ThrowKeyNotFoundException(key);
- return default!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return default;
}
set
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
- if ((uint)index > (uint)array!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if ((uint)index > (uint)array.Length)
{
ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
}
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.info);
}
- info!.AddValue(VersionName, _version); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ info.AddValue(VersionName, _version);
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
IEqualityComparer<TKey>? comparer = _comparer;
if (comparer == null)
{
- uint hashCode = (uint)key!.GetHashCode(); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ uint hashCode = (uint)key.GetHashCode();
// Value in _buckets is 1-based
i = buckets[hashCode % (uint)buckets.Length] - 1;
if (default(TKey)! != null) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
Debug.Assert(entries != null, "expected entries to be non-null");
IEqualityComparer<TKey>? comparer = _comparer;
- uint hashCode = (uint)((comparer == null) ? key!.GetHashCode() : comparer.GetHashCode(key)); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ uint hashCode = (uint)((comparer == null) ? key.GetHashCode() : comparer.GetHashCode(key));
int collisionCount = 0;
ref int bucket = ref _buckets[hashCode % (uint)_buckets.Length];
ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_MissingKeys);
}
- for (int i = 0; i < array!.Length; i++) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ for (int i = 0; i < array.Length; i++)
{
if (array[i].Key == null)
{
if (buckets != null)
{
Debug.Assert(entries != null, "entries should be non-null");
- uint hashCode = (uint)(_comparer?.GetHashCode(key) ?? key!.GetHashCode()); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ uint hashCode = (uint)(_comparer?.GetHashCode(key) ?? key.GetHashCode());
uint bucket = hashCode % (uint)buckets.Length;
int last = -1;
// Value in buckets is 1-based
if (buckets != null)
{
Debug.Assert(entries != null, "entries should be non-null");
- uint hashCode = (uint)(_comparer?.GetHashCode(key) ?? key!.GetHashCode()); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ uint hashCode = (uint)(_comparer?.GetHashCode(key) ?? key.GetHashCode());
uint bucket = hashCode % (uint)buckets.Length;
int last = -1;
// Value in buckets is 1-based
{
if (array == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- if (array!.Rank != 1) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (array.Rank != 1)
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
if (array.GetLowerBound(0) != 0)
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NonZeroLowerBound);
{
if (entries![i].next >= -1)
{
- objects![index++] = new KeyValuePair<TKey, TValue>(entries[i].key, entries[i].value); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ objects[index++] = new KeyValuePair<TKey, TValue>(entries[i].key, entries[i].value);
}
}
}
try
{
- TKey tempKey = (TKey)key!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ TKey tempKey = (TKey)key;
try
{
this[tempKey] = (TValue)value!;
try
{
- TKey tempKey = (TKey)key!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ TKey tempKey = (TKey)key;
try
{
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.dictionary);
}
- _dictionary = dictionary!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ _dictionary = dictionary;
}
public Enumerator GetEnumerator()
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
- if (index < 0 || index > array!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (index < 0 || index > array.Length)
{
ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
}
- if (array!.Length - index < _dictionary.Count) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (array.Length - index < _dictionary.Count)
{
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
}
{
if (array == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- if (array!.Rank != 1) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (array.Rank != 1)
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
if (array.GetLowerBound(0) != 0)
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NonZeroLowerBound);
{
for (int i = 0; i < count; i++)
{
- if (entries![i].next >= -1) objects![index++] = entries[i].key; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (entries![i].next >= -1) objects[index++] = entries[i].key;
}
}
catch (ArrayTypeMismatchException)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.dictionary);
}
- _dictionary = dictionary!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ _dictionary = dictionary;
}
public Enumerator GetEnumerator()
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
- if ((uint)index > array!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if ((uint)index > array.Length)
{
ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException();
}
{
if (array == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- if (array!.Rank != 1) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (array.Rank != 1)
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
if (array.GetLowerBound(0) != 0)
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NonZeroLowerBound);
{
for (int i = 0; i < count; i++)
{
- if (entries![i].next >= -1) objects![index++] = entries[i].value!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (entries![i].next >= -1) objects[index++] = entries[i].value!;
}
}
catch (ArrayTypeMismatchException)
List<TOutput> list = new List<TOutput>(_size);
for (int i = 0; i < _size; i++)
{
- list._items[i] = converter!(_items[i]); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ list._items[i] = converter(_items[i]);
}
list._size = _size;
return list;
List<T> list = new List<T>();
for (int i = 0; i < _size; i++)
{
- if (match!(_items[i])) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (match(_items[i]))
{
list.Add(_items[i]);
}
int endIndex = startIndex - count;
for (int i = startIndex; i > endIndex; i--)
{
- if (match!(_items[i])) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (match(_items[i]))
{
return i;
}
}
else
{
- using (IEnumerator<T> en = collection!.GetEnumerator()) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ using (IEnumerator<T> en = collection.GetEnumerator())
{
while (en.MoveNext())
{
int freeIndex = 0; // the first free slot in items array
// Find the first item which needs to be removed.
- while (freeIndex < _size && !match!(_items[freeIndex])) freeIndex++; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ while (freeIndex < _size && !match(_items[freeIndex])) freeIndex++;
if (freeIndex >= _size) return 0;
int current = freeIndex + 1;
if (_size > 1)
{
- ArraySortHelper<T>.Sort(_items, 0, _size, comparison!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ ArraySortHelper<T>.Sort(_items, 0, _size, comparison);
}
_version++;
}
if (s_serializationInfoTable == null)
Interlocked.CompareExchange(ref s_serializationInfoTable, new ConditionalWeakTable<object, SerializationInfo>(), null);
- return s_serializationInfoTable!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability
+ return s_serializationInfoTable;
}
}
}
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.list);
}
- items = list!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ items = list;
}
public int Count
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
- if (array!.Rank != 1) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (array.Rank != 1)
{
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
}
{
for (int i = 0; i < count; i++)
{
- objects![index++] = items[i]; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ objects[index++] = items[i];
}
}
catch (ArrayTypeMismatchException)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.list);
}
- this.list = list!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ this.list = list;
}
public int Count
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
- if (array!.Rank != 1) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (array.Rank != 1)
{
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
}
{
for (int i = 0; i < count; i++)
{
- objects![index++] = list[i]; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ objects[index++] = list[i];
}
}
catch (ArrayTypeMismatchException)
public static DateTimeOffset Parse(string input, IFormatProvider? formatProvider)
{
if (input == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
- return Parse(input!, formatProvider, DateTimeStyles.None); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return Parse(input, formatProvider, DateTimeStyles.None);
}
public static DateTimeOffset Parse(string input, IFormatProvider? formatProvider, DateTimeStyles styles)
{
if (input == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input);
if (format == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.format);
- return ParseExact(input!, format!, formatProvider, DateTimeStyles.None); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return ParseExact(input, format, formatProvider, DateTimeStyles.None);
}
// Constructs a DateTimeOffset from a string. The string must specify a
/// full trust, because it will inform you of bugs in the appdomain and because the event handler
/// could allow you to continue execution.
/// </summary>
- public static event EventHandler<ContractFailedEventArgs> ContractFailed
+ public static event EventHandler<ContractFailedEventArgs> ContractFailed // TODO-NULLABLE: Should all events use nullable delegate types?
{
add
{
/// <summary>
/// Fires when a Command (e.g. Enable) comes from a an EventListener.
/// </summary>
- public event EventHandler<EventCommandEventArgs> EventCommandExecuted
+ public event EventHandler<EventCommandEventArgs> EventCommandExecuted // TODO-NULLABLE: Should all events use nullable delegate types?
{
add
{
/// In a multi-threaded environment, it is possible that 'EventSourceEventWrittenCallback'
/// events for a particular eventSource to occur BEFORE the EventSourceCreatedCallback is issued.
/// </summary>
- public event EventHandler<EventSourceCreatedEventArgs> EventSourceCreated
+ public event EventHandler<EventSourceCreatedEventArgs> EventSourceCreated // TODO-NULLABLE: Should all events use nullable delegate types?
{
add
{
/// This event is raised whenever an event has been written by a EventSource for which
/// the EventListener has enabled events.
/// </summary>
- public event EventHandler<EventWrittenEventArgs> EventWritten = null!;
+ public event EventHandler<EventWrittenEventArgs> EventWritten = null!; // TODO-NULLABLE: Should all events use nullable delegate types?
static EventListener()
{
{
if (s_EventSources == null)
Interlocked.CompareExchange(ref s_EventSources, new List<WeakReference>(2), null);
- return s_EventSources!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability
+ return s_EventSources;
}
}
{
foreach (string name in environmentKey.GetValueNames())
{
- string? value = environmentKey.GetValue(name, "")!.ToString(); // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
+ string? value = environmentKey.GetValue(name, "").ToString();
try
{
results.Add(name, value);
{
Interlocked.CompareExchange(ref s_osVersion, GetOSVersion(), null);
}
- return s_osVersion!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability
+ return s_osVersion;
}
}
return s;
}
- protected event EventHandler<SafeSerializationEventArgs> SerializeObjectState
+ protected event EventHandler<SafeSerializationEventArgs> SerializeObjectState // TODO-NULLABLE: Should all events use nullable delegate types?
{
add { throw new PlatformNotSupportedException(SR.PlatformNotSupported_SecureBinarySerialization); }
remove { throw new PlatformNotSupportedException(SR.PlatformNotSupported_SecureBinarySerialization); }
{
for (int i = 0; i < array.Length; i++)
{
- array[i] = ReescapeWin32String(array[i])!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
+ array[i] = ReescapeWin32String(array[i]);
}
}
/// Handlers registered with this event will be invoked on the
/// <see cref="System.Threading.SynchronizationContext"/> captured when the instance was constructed.
/// </remarks>
- public event EventHandler<T> ProgressChanged = null!;
+ public event EventHandler<T> ProgressChanged = null!; // TODO-NULLABLE: Should all events use nullable delegate types?
/// <summary>Reports a progress change.</summary>
/// <param name="value">The value of the updated progress.</param>
return Activator.CreateInstance(t, bindingAttr, binder, args, culture, activationAttributes);
}
- public virtual event ModuleResolveEventHandler ModuleResolve { add { throw NotImplemented.ByDesign; } remove { throw NotImplemented.ByDesign; } }
+ public virtual event ModuleResolveEventHandler ModuleResolve { add { throw NotImplemented.ByDesign; } remove { throw NotImplemented.ByDesign; } } // TODO-NULLABLE: Should all events use nullable delegate types?
public virtual Module ManifestModule { get { throw NotImplemented.ByDesign; } }
public virtual Module? GetModule(string name) { throw NotImplemented.ByDesign; }
// and decrement its outstanding operation count.
try
{
- System.Threading.Tasks.Task.ThrowAsync(exception!, targetContext: _synchronizationContext); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ System.Threading.Tasks.Task.ThrowAsync(exception, targetContext: _synchronizationContext);
}
finally
{
// Otherwise, queue the exception to be thrown on the ThreadPool. This will
// result in a crash unless legacy exception behavior is enabled by a config
// file or a CLR host.
- System.Threading.Tasks.Task.ThrowAsync(exception!, targetContext: null); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ System.Threading.Tasks.Task.ThrowAsync(exception, targetContext: null);
}
// The exception was propagated already; we don't need or want to fault the builder, just mark it as completed.
if (context == null)
{
Debug.Assert(StateMachine != null);
- StateMachine!.MoveNext(); // TODO-NULLABLE: remove ! when Debug.Assert on fields is respected (https://github.com/dotnet/roslyn/issues/36830)
+ StateMachine.MoveNext();
}
else
{
// If the exception represents cancellation, cancel the task. Otherwise, fault the task.
bool successfullySet = exception is OperationCanceledException oce ?
task.TrySetCanceled(oce.CancellationToken, oce) :
- task.TrySetException(exception!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ task.TrySetException(exception);
// Unlike with TaskCompletionSource, we do not need to spin here until _taskAndStateMachine is completed,
// since AsyncTaskMethodBuilder.SetException should not be immediately followed by any code
try
{
- stateMachine!.MoveNext(); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ stateMachine.MoveNext();
}
finally
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
}
- return _container.TryGetValueWorker(key!, out value); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return _container.TryGetValueWorker(key, out value);
}
/// <summary>Adds a key to the table.</summary>
lock (_lock)
{
- int entryIndex = _container.FindEntry(key!, out _); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ int entryIndex = _container.FindEntry(key, out _);
if (entryIndex != -1)
{
ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_AddingDuplicate);
}
- CreateEntry(key!, value); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ CreateEntry(key, value);
}
}
lock (_lock)
{
- int entryIndex = _container.FindEntry(key!, out _); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ int entryIndex = _container.FindEntry(key, out _);
// if we found a key we should just update, if no we should create a new entry.
if (entryIndex != -1)
}
else
{
- CreateEntry(key!, value); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ CreateEntry(key, value);
}
}
}
lock (_lock)
{
- return _container.Remove(key!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return _container.Remove(key);
}
}
/// event handlers sets the Cancel flag in the ContractFailedEventArgs, then the Contract class will
/// not pop up an assert dialog box or trigger escalation policy.
/// </summary>
- internal static event EventHandler<ContractFailedEventArgs> InternalContractFailed;
+ internal static event EventHandler<ContractFailedEventArgs> InternalContractFailed; // TODO-NULLABLE: Should all events use nullable delegate types?
/// <summary>
/// Rewriter will call this method on a contract failure to allow listeners to be notified.
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
- (int offset, int length) = range.GetOffsetAndLength(array!.Length); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ (int offset, int length) = range.GetOffsetAndLength(array.Length);
if (default(T)! != null || typeof(T[]) == array.GetType()) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757)
{
try
{
- s_nativeDllResolveMap!.Add(assembly, resolver); // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability
+ s_nativeDllResolveMap.Add(assembly, resolver);
}
catch (ArgumentException)
{
//
// Inputs: Invoking assembly, and library name to resolve
// Returns: A handle to the loaded native library
- public event Func<Assembly, string, IntPtr> ResolvingUnmanagedDll
+ public event Func<Assembly, string, IntPtr> ResolvingUnmanagedDll // TODO-NULLABLE: Should all events use nullable delegate types?
{
add
{
//
// Inputs: The AssemblyLoadContext and AssemblyName to be loaded
// Returns: The Loaded assembly object.
- public event Func<AssemblyLoadContext, AssemblyName, Assembly?> Resolving
+ public event Func<AssemblyLoadContext, AssemblyName, Assembly?> Resolving // TODO-NULLABLE: Should all events use nullable delegate types?
{
add
{
}
}
- public event Action<AssemblyLoadContext> Unloading
+ public event Action<AssemblyLoadContext> Unloading // TODO-NULLABLE: Should all events use nullable delegate types?
{
add
{
#region AppDomainEvents
// Occurs when an Assembly is loaded
- internal static event AssemblyLoadEventHandler AssemblyLoad;
+ internal static event AssemblyLoadEventHandler AssemblyLoad; // TODO-NULLABLE: Should all events use nullable delegate types?
// Occurs when resolution of type fails
- internal static event ResolveEventHandler TypeResolve;
+ internal static event ResolveEventHandler TypeResolve; // TODO-NULLABLE: Should all events use nullable delegate types?
// Occurs when resolution of resource fails
- internal static event ResolveEventHandler ResourceResolve;
+ internal static event ResolveEventHandler ResourceResolve; // TODO-NULLABLE: Should all events use nullable delegate types?
// Occurs when resolution of assembly fails
// This event is fired after resolve events of AssemblyLoadContext fails
- internal static event ResolveEventHandler AssemblyResolve;
+ internal static event ResolveEventHandler AssemblyResolve; // TODO-NULLABLE: Should all events use nullable delegate types?
#endregion
public static AssemblyLoadContext Default => DefaultAssemblyLoadContext.s_loadContext;
return SpanHelpers.IndexOf(
ref _firstChar,
Length,
- ref value!._firstChar, // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ ref value._firstChar,
value.Length) >= 0;
}
if (_ignoreCase)
{
- return obj!.GetHashCodeOrdinalIgnoreCase(); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return obj.GetHashCodeOrdinalIgnoreCase();
}
- return obj!.GetHashCode(); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return obj.GetHashCode();
}
// Equals method for the comparer itself.
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.obj);
}
- return obj!.GetHashCode(); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return obj.GetHashCode();
}
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.obj);
}
- return obj!.GetHashCodeOrdinalIgnoreCase(); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return obj.GetHashCodeOrdinalIgnoreCase();
}
public void GetObjectData(SerializationInfo info, StreamingContext context)
object o = new object();
Interlocked.CompareExchange<object?>(ref s_InternalSyncObject, o, null);
}
- return s_InternalSyncObject!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability
+ return s_InternalSyncObject;
}
}
private static DecoderFallback? s_exceptionFallback;
public static DecoderFallback ReplacementFallback =>
- s_replacementFallback ?? Interlocked.CompareExchange(ref s_replacementFallback, new DecoderReplacementFallback(), null) ?? s_replacementFallback!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability
+ s_replacementFallback ?? Interlocked.CompareExchange(ref s_replacementFallback, new DecoderReplacementFallback(), null) ?? s_replacementFallback;
public static DecoderFallback ExceptionFallback =>
- s_exceptionFallback ?? Interlocked.CompareExchange<DecoderFallback?>(ref s_exceptionFallback, new DecoderExceptionFallback(), null) ?? s_exceptionFallback!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability
+ s_exceptionFallback ?? Interlocked.CompareExchange<DecoderFallback?>(ref s_exceptionFallback, new DecoderExceptionFallback(), null) ?? s_exceptionFallback;
// Fallback
//
object o = new object();
Interlocked.CompareExchange<object?>(ref s_InternalSyncObject, o, null);
}
- return s_InternalSyncObject!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability
+ return s_InternalSyncObject;
}
}
if (s_replacementFallback == null)
Interlocked.CompareExchange<EncoderFallback?>(ref s_replacementFallback, new EncoderReplacementFallback(), null);
- return s_replacementFallback!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability
+ return s_replacementFallback;
}
}
if (s_exceptionFallback == null)
Interlocked.CompareExchange<EncoderFallback?>(ref s_exceptionFallback, new EncoderExceptionFallback(), null);
- return s_exceptionFallback!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability
+ return s_exceptionFallback;
}
}
return null;
}
- CodePageDataItem? data = s_codePageToCodePageData![index]; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability
+ CodePageDataItem? data = s_codePageToCodePageData[index];
if (data == null)
{
Interlocked.CompareExchange<CodePageDataItem?>(ref s_codePageToCodePageData[index], InternalGetCodePageDataItem(codePage, index), null);
ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen();
}
- return new ReadOnlyMemory<char>(_currentChunk!.m_ChunkChars, 0, _currentChunk.m_ChunkLength); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return new ReadOnlyMemory<char>(_currentChunk.m_ChunkChars, 0, _currentChunk.m_ChunkLength);
}
}
ThrowHelper.ThrowArgumentOutOfRangeException((index < 0) ? ExceptionArgument.index : ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
}
- if (chars!.Length - index < count) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (chars.Length - index < count)
{
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.chars, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer);
}
fixed (char* pChars = chars)
{
- return GetByteCountCommon(pChars, chars!.Length); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return GetByteCountCommon(pChars, chars.Length);
}
}
resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
}
- if (s!.Length - charIndex < charCount) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (s.Length - charIndex < charCount)
{
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.s, ExceptionResource.ArgumentOutOfRange_IndexCount);
}
- if ((uint)byteIndex > bytes!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if ((uint)byteIndex > bytes.Length)
{
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_Index);
}
resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
}
- if (chars!.Length - charIndex < charCount) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (chars.Length - charIndex < charCount)
{
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.chars, ExceptionResource.ArgumentOutOfRange_IndexCount);
}
- if ((uint)byteIndex > bytes!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if ((uint)byteIndex > bytes.Length)
{
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_Index);
}
ThrowHelper.ThrowArgumentOutOfRangeException((index < 0) ? ExceptionArgument.index : ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
}
- if (bytes!.Length - index < count) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (bytes.Length - index < count)
{
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.bytes, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer);
}
resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
}
- if (bytes!.Length - byteIndex < byteCount) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (bytes.Length - byteIndex < byteCount)
{
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.bytes, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer);
}
- if ((uint)charIndex > (uint)chars!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if ((uint)charIndex > (uint)chars.Length)
{
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.charIndex, ExceptionResource.ArgumentOutOfRange_Index);
}
resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
}
- if (bytes!.Length - index < count) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (bytes.Length - index < count)
{
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.bytes, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer);
}
// 2. if IsCancellationRequested = false, then NotifyCancellation will see that the event exists, and will call Set().
if (IsCancellationRequested)
{
- _kernelEvent!.Set(); // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability
+ _kernelEvent.Set();
}
- return _kernelEvent!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability
+ return _kernelEvent;
}
}
}
}
- return target!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
+ return target!; // TODO-NULLABLE: Compiler can't infer target's non-nullness (https://github.com/dotnet/roslyn/issues/37300)
}
/// <summary>
private static object EnsureLockInitialized([NotNull] ref object? syncLock) =>
syncLock ??
Interlocked.CompareExchange(ref syncLock, new object(), null) ??
- syncLock!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability
+ syncLock;
}
}
}
// Create and schedule the future.
- Task<TResult> f = new Task<TResult>(function!, parent, cancellationToken, creationOptions, internalOptions | InternalTaskOptions.QueuedByRuntime, scheduler); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ Task<TResult> f = new Task<TResult>(function, parent, cancellationToken, creationOptions, internalOptions | InternalTaskOptions.QueuedByRuntime, scheduler);
f.ScheduleAndStart(false);
return f;
}
// Create and schedule the future.
- Task<TResult> f = new Task<TResult>(function!, state, parent, cancellationToken, creationOptions, internalOptions | InternalTaskOptions.QueuedByRuntime, scheduler); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ Task<TResult> f = new Task<TResult>(function, state, parent, cancellationToken, creationOptions, internalOptions | InternalTaskOptions.QueuedByRuntime, scheduler);
f.ScheduleAndStart(false);
return f;
out internalOptions);
Task continuationTask = new ContinuationTaskFromResultTask<TResult>(
- this, continuationAction!, null, // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ this, continuationAction, null,
creationOptions, internalOptions
);
// Register the continuation. If synchronous execution is requested, this may
// actually invoke the continuation before returning.
- ContinueWithCore(continuationTask, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ ContinueWithCore(continuationTask, scheduler, cancellationToken, continuationOptions);
return continuationTask;
}
out internalOptions);
Task continuationTask = new ContinuationTaskFromResultTask<TResult>(
- this, continuationAction!, state, // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ this, continuationAction, state,
creationOptions, internalOptions
);
// Register the continuation. If synchronous execution is requested, this may
// actually invoke the continuation before returning.
- ContinueWithCore(continuationTask, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ ContinueWithCore(continuationTask, scheduler, cancellationToken, continuationOptions);
return continuationTask;
}
out internalOptions);
Task<TNewResult> continuationFuture = new ContinuationResultTaskFromResultTask<TResult, TNewResult>(
- this, continuationFunction!, null, // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ this, continuationFunction, null,
creationOptions, internalOptions
);
// Register the continuation. If synchronous execution is requested, this may
// actually invoke the continuation before returning.
- ContinueWithCore(continuationFuture, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ ContinueWithCore(continuationFuture, scheduler, cancellationToken, continuationOptions);
return continuationFuture;
}
out internalOptions);
Task<TNewResult> continuationFuture = new ContinuationResultTaskFromResultTask<TResult, TNewResult>(
- this, continuationFunction!, state, // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ this, continuationFunction, state,
creationOptions, internalOptions
);
// Register the continuation. If synchronous execution is requested, this may
// actually invoke the continuation before returning.
- ContinueWithCore(continuationFuture, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ ContinueWithCore(continuationFuture, scheduler, cancellationToken, continuationOptions);
return continuationFuture;
}
// RespectParentCancellation.
Task t = new Task(new Action<object>(delegate
{
- FromAsyncCoreLogic(asyncResult!, endFunction, endAction, promise, requiresSynchronization: true); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ FromAsyncCoreLogic(asyncResult, endFunction, endAction, promise, requiresSynchronization: true);
}),
(object?)null, null,
default, TaskCreationOptions.None, InternalTaskOptions.None, null);
if (Task.s_asyncDebuggingEnabled)
Task.AddToActiveTasks(t);
- if (asyncResult!.IsCompleted) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (asyncResult.IsCompleted)
{
- try { t.InternalRunSynchronously(scheduler!, waitForCompletion: false); } // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ try { t.InternalRunSynchronously(scheduler, waitForCompletion: false); }
catch (Exception e) { promise.TrySetException(e); } // catch and log any scheduler exceptions
}
else
asyncResult.AsyncWaitHandle,
delegate
{
- try { t.InternalRunSynchronously(scheduler!, waitForCompletion: false); } // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ try { t.InternalRunSynchronously(scheduler, waitForCompletion: false); }
catch (Exception e) { promise.TrySetException(e); } // catch and log any scheduler exceptions
},
null,
Task<TResult> promise = new Task<TResult>(state, creationOptions);
if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCreation(promise, "TaskFactory.FromAsync: " + beginMethod!.Method.Name); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ AsyncCausalityTracer.TraceOperationCreation(promise, "TaskFactory.FromAsync: " + beginMethod.Method.Name);
if (Task.s_asyncDebuggingEnabled)
Task.AddToActiveTasks(promise);
try
{
//if we don't require synchronization, a faster set result path is taken
- var asyncResult = beginMethod!(iar => // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ var asyncResult = beginMethod(iar =>
{
if (!iar.CompletedSynchronously)
FromAsyncCoreLogic(iar, endFunction, endAction, promise, requiresSynchronization: true);
Task<TResult> promise = new Task<TResult>(state, creationOptions);
if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCreation(promise, "TaskFactory.FromAsync: " + beginMethod!.Method.Name); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ AsyncCausalityTracer.TraceOperationCreation(promise, "TaskFactory.FromAsync: " + beginMethod.Method.Name);
if (Task.s_asyncDebuggingEnabled)
Task.AddToActiveTasks(promise);
try
{
//if we don't require synchronization, a faster set result path is taken
- var asyncResult = beginMethod!(arg1, iar => // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ var asyncResult = beginMethod(arg1, iar =>
{
if (!iar.CompletedSynchronously)
FromAsyncCoreLogic(iar, endFunction, endAction, promise, requiresSynchronization: true);
Task<TResult> promise = new Task<TResult>(state, creationOptions);
if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCreation(promise, "TaskFactory.FromAsync: " + beginMethod!.Method.Name); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ AsyncCausalityTracer.TraceOperationCreation(promise, "TaskFactory.FromAsync: " + beginMethod.Method.Name);
if (Task.s_asyncDebuggingEnabled)
Task.AddToActiveTasks(promise);
try
{
//if we don't require synchronization, a faster set result path is taken
- var asyncResult = beginMethod!(arg1, arg2, iar => // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ var asyncResult = beginMethod(arg1, arg2, iar =>
{
if (!iar.CompletedSynchronously)
FromAsyncCoreLogic(iar, endFunction, endAction, promise, requiresSynchronization: true);
Task<TResult> promise = new Task<TResult>(state, creationOptions);
if (AsyncCausalityTracer.LoggingOn)
- AsyncCausalityTracer.TraceOperationCreation(promise, "TaskFactory.FromAsync: " + beginMethod!.Method.Name); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ AsyncCausalityTracer.TraceOperationCreation(promise, "TaskFactory.FromAsync: " + beginMethod.Method.Name);
if (Task.s_asyncDebuggingEnabled)
Task.AddToActiveTasks(promise);
try
{
//if we don't require synchronization, a faster set result path is taken
- var asyncResult = beginMethod!(arg1, arg2, arg3, iar => // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ var asyncResult = beginMethod(arg1, arg2, arg3, iar =>
{
if (!iar.CompletedSynchronously)
FromAsyncCoreLogic(iar, endFunction, endAction, promise, requiresSynchronization: true);
// Validate argument
if (asyncResult == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.asyncResult);
- var promise = asyncResult!.AsyncState as FromAsyncTrimPromise<TInstance>; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ var promise = asyncResult.AsyncState as FromAsyncTrimPromise<TInstance>;
if (promise == null) ThrowHelper.ThrowArgumentException(ExceptionResource.InvalidOperation_WrongAsyncResultOrEndCalledMultiple, ExceptionArgument.asyncResult);
// Grab the relevant state and then null it out so that the task doesn't hold onto the state unnecessarily
- var thisRef = promise!.m_thisRef; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ var thisRef = promise.m_thisRef;
var endMethod = promise.m_endMethod;
promise.m_thisRef = default;
promise.m_endMethod = null;
if (!asyncResult.CompletedSynchronously)
{
Debug.Assert(thisRef != null);
- promise.Complete(thisRef, endMethod!, asyncResult, requiresSynchronization: true); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ promise.Complete(thisRef, endMethod, asyncResult, requiresSynchronization: true);
}
}
if (scheduler == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
// Check tasks array and make defensive copy
- Task<TAntecedentResult>[] tasksCopy = TaskFactory.CheckMultiContinuationTasksAndCopy<TAntecedentResult>(tasks!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ Task<TAntecedentResult>[] tasksCopy = TaskFactory.CheckMultiContinuationTasksAndCopy<TAntecedentResult>(tasks);
// Bail early if cancellation has been requested.
if (cancellationToken.IsCancellationRequested
return starter.ContinueWith<TResult>(
// use a cached delegate
GenericDelegateCache<TAntecedentResult, TResult>.CWAllFuncDelegate,
- continuationFunction, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ continuationFunction, scheduler, cancellationToken, continuationOptions);
}
else
{
return starter.ContinueWith<TResult>(
// use a cached delegate
GenericDelegateCache<TAntecedentResult, TResult>.CWAllActionDelegate,
- continuationAction, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ continuationAction, scheduler, cancellationToken, continuationOptions);
}
}
if (scheduler == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
// Check tasks array and make defensive copy
- Task[] tasksCopy = TaskFactory.CheckMultiContinuationTasksAndCopy(tasks!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ Task[] tasksCopy = TaskFactory.CheckMultiContinuationTasksAndCopy(tasks);
// Bail early if cancellation has been requested.
if (cancellationToken.IsCancellationRequested
Debug.Assert(state is Func<Task[], TResult>);
return ((Func<Task[], TResult>)state)(completedTasks.Result);
},
- continuationFunction, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ continuationFunction, scheduler, cancellationToken, continuationOptions);
}
else
{
Debug.Assert(state is Action<Task[]>);
((Action<Task[]>)state)(completedTasks.Result); return default!;
},
- continuationAction, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ continuationAction, scheduler, cancellationToken, continuationOptions);
}
}
// check arguments
TaskFactory.CheckMultiTaskContinuationOptions(continuationOptions);
if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
- if (tasks!.Length == 0) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList, ExceptionArgument.tasks); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (tasks.Length == 0) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList, ExceptionArgument.tasks);
//ArgumentNullException of continuationFunction or continuationAction is checked by the caller
Debug.Assert((continuationFunction != null) != (continuationAction != null), "Expected exactly one of endFunction/endAction to be non-null");
Debug.Assert(state is Func<Task, TResult>);
return ((Func<Task, TResult>)state)(completedTask.Result);
},
- continuationFunction, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ continuationFunction, scheduler, cancellationToken, continuationOptions);
}
else
{
((Action<Task>)state)(completedTask.Result);
return default!;
},
- continuationAction, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ continuationAction, scheduler, cancellationToken, continuationOptions);
}
}
// check arguments
TaskFactory.CheckMultiTaskContinuationOptions(continuationOptions);
if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
- if (tasks!.Length == 0) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList, ExceptionArgument.tasks); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (tasks.Length == 0) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList, ExceptionArgument.tasks);
//ArgumentNullException of continuationFunction or continuationAction is checked by the caller
Debug.Assert((continuationFunction != null) != (continuationAction != null), "Expected exactly one of endFunction/endAction to be non-null");
if (scheduler == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
return starter.ContinueWith<TResult>(
// Use a cached delegate
GenericDelegateCache<TAntecedentResult, TResult>.CWAnyFuncDelegate,
- continuationFunction, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ continuationFunction, scheduler, cancellationToken, continuationOptions);
}
else
{
return starter.ContinueWith<TResult>(
// Use a cached delegate
GenericDelegateCache<TAntecedentResult, TResult>.CWAnyActionDelegate,
- continuationAction, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ continuationAction, scheduler, cancellationToken, continuationOptions);
}
}
}
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler);
}
- InternalRunSynchronously(scheduler!, waitForCompletion: true); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ InternalRunSynchronously(scheduler, waitForCompletion: true);
}
//
}
}
- return contingentProps.m_completionEvent!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability
+ return contingentProps.m_completionEvent;
}
}
lock (props)
{
- props.m_exceptionsHolder!.Add(exceptionObject, representsCancellation); // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability
+ props.m_exceptionsHolder.Add(exceptionObject, representsCancellation);
}
}
CreationOptionsFromContinuationOptions(continuationOptions, out creationOptions, out internalOptions);
Task continuationTask = new ContinuationTaskFromTask(
- this, continuationAction!, null, // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ this, continuationAction, null,
creationOptions, internalOptions
);
// Register the continuation. If synchronous execution is requested, this may
// actually invoke the continuation before returning.
- ContinueWithCore(continuationTask, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ ContinueWithCore(continuationTask, scheduler, cancellationToken, continuationOptions);
return continuationTask;
}
CreationOptionsFromContinuationOptions(continuationOptions, out creationOptions, out internalOptions);
Task continuationTask = new ContinuationTaskFromTask(
- this, continuationAction!, state, // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ this, continuationAction, state,
creationOptions, internalOptions
);
// Register the continuation. If synchronous execution is requested, this may
// actually invoke the continuation before returning.
- ContinueWithCore(continuationTask, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ ContinueWithCore(continuationTask, scheduler, cancellationToken, continuationOptions);
return continuationTask;
}
CreationOptionsFromContinuationOptions(continuationOptions, out creationOptions, out internalOptions);
Task<TResult> continuationTask = new ContinuationResultTaskFromTask<TResult>(
- this, continuationFunction!, null, // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ this, continuationFunction, null,
creationOptions, internalOptions
);
// Register the continuation. If synchronous execution is requested, this may
// actually invoke the continuation before returning.
- ContinueWithCore(continuationTask, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ ContinueWithCore(continuationTask, scheduler, cancellationToken, continuationOptions);
return continuationTask;
}
CreationOptionsFromContinuationOptions(continuationOptions, out creationOptions, out internalOptions);
Task<TResult> continuationTask = new ContinuationResultTaskFromTask<TResult>(
- this, continuationFunction!, state, // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ this, continuationFunction, state,
creationOptions, internalOptions
);
// Register the continuation. If synchronous execution is requested, this may
// actually invoke the continuation before returning.
- ContinueWithCore(continuationTask, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ ContinueWithCore(continuationTask, scheduler, cancellationToken, continuationOptions);
return continuationTask;
}
bool returnValue = true;
// Collects incomplete tasks in "waitedOnTaskList"
- for (int i = tasks!.Length - 1; i >= 0; i--) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ for (int i = tasks.Length - 1; i >= 0; i--)
{
Task task = tasks[i];
ThrowHelper.ThrowArgumentException(ExceptionResource.Task_WaitMulti_NullTask, ExceptionArgument.tasks);
}
- bool taskIsCompleted = task!.IsCompleted; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ bool taskIsCompleted = task.IsCompleted;
if (!taskIsCompleted)
{
// try inlining the task only if we have an infinite timeout and an empty cancellation token
// Make a pass through the loop to check for any tasks that may have
// already been completed, and to verify that no tasks are null.
- for (int taskIndex = 0; taskIndex < tasks!.Length; taskIndex++) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ for (int taskIndex = 0; taskIndex < tasks.Length; taskIndex++)
{
Task task = tasks[taskIndex];
ThrowHelper.ThrowArgumentException(ExceptionResource.Task_WaitMulti_NullTask, ExceptionArgument.tasks);
}
- if (signaledTaskIndex == -1 && task!.IsCompleted) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (signaledTaskIndex == -1 && task.IsCompleted)
{
// We found our first completed task. Store it, but we can't just return here,
// as we still need to validate the whole array for nulls.
if (exception == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exception);
var task = new Task();
- bool succeeded = task.TrySetException(exception!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ bool succeeded = task.TrySetException(exception);
Debug.Assert(succeeded, "This should always succeed on a new task.");
return task;
}
if (exception == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exception);
var task = new Task<TResult>();
- bool succeeded = task.TrySetException(exception!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ bool succeeded = task.TrySetException(exception);
Debug.Assert(succeeded, "This should always succeed on a new task.");
return task;
}
return Task.FromCanceled(cancellationToken);
// Kick off initial Task, which will call the user-supplied function and yield a Task.
- Task<Task?> task1 = Task<Task?>.Factory.StartNew(function!, cancellationToken, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ Task<Task?> task1 = Task<Task?>.Factory.StartNew(function, cancellationToken, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
// Create a promise-style Task to be used as a proxy for the operation
// Set lookForOce == true so that unwrap logic can be on the lookout for OCEs thrown as faults from task1, to support in-delegate cancellation.
return Task.FromCanceled<TResult>(cancellationToken);
// Kick off initial Task, which will call the user-supplied function and yield a Task.
- Task<Task<TResult>?> task1 = Task<Task<TResult>?>.Factory.StartNew(function!, cancellationToken, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ Task<Task<TResult>?> task1 = Task<Task<TResult>?>.Factory.StartNew(function, cancellationToken, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
// Create a promise-style Task to be used as a proxy for the operation
// Set lookForOce == true so that unwrap logic can be on the lookout for OCEs thrown as faults from task1, to support in-delegate cancellation.
foreach (var task in tasks)
{
if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
- taskArray[index++] = task!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ taskArray[index++] = task;
}
return InternalWhenAll(taskArray);
}
// Do some argument checking and convert tasks to a List (and later an array).
if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
List<Task> taskList = new List<Task>();
- foreach (Task task in tasks!) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ foreach (Task task in tasks)
{
if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
- taskList.Add(task!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ taskList.Add(task);
}
// Delegate the rest to InternalWhenAll()
// Do some argument checking and make a defensive copy of the tasks array
if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
- int taskCount = tasks!.Length; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ int taskCount = tasks.Length;
if (taskCount == 0) return InternalWhenAll(tasks); // Small optimization in the case of an empty array.
Task[] tasksCopy = new Task[taskCount];
{
Task task = tasks[i];
if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
- tasksCopy[i] = task!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ tasksCopy[i] = task;
}
// The rest can be delegated to InternalWhenAll()
foreach (var task in tasks)
{
if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
- taskArray[index++] = task!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ taskArray[index++] = task;
}
return InternalWhenAll<TResult>(taskArray);
}
// Do some argument checking and convert tasks into a List (later an array)
if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
List<Task<TResult>> taskList = new List<Task<TResult>>();
- foreach (Task<TResult> task in tasks!) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ foreach (Task<TResult> task in tasks)
{
if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
- taskList.Add(task!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ taskList.Add(task);
}
// Delegate the rest to InternalWhenAll<TResult>().
// Do some argument checking and make a defensive copy of the tasks array
if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
- int taskCount = tasks!.Length; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ int taskCount = tasks.Length;
if (taskCount == 0) return InternalWhenAll<TResult>(tasks); // small optimization in the case of an empty task array
Task<TResult>[] tasksCopy = new Task<TResult>[taskCount];
{
Task<TResult> task = tasks[i];
if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
- tasksCopy[i] = task!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ tasksCopy[i] = task;
}
// Delegate the rest to InternalWhenAll<TResult>()
public static Task<Task> WhenAny(params Task[] tasks)
{
if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks);
- if (tasks!.Length == 0) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (tasks.Length == 0)
{
ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList, ExceptionArgument.tasks);
}
{
Task task = tasks[i];
if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
- tasksCopy[i] = task!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ tasksCopy[i] = task;
}
// Previously implemented CommonCWAnyLogic() can handle the rest
// Make a defensive copy, as the user may manipulate the tasks collection
// after we return but before the WhenAny asynchronously completes.
List<Task> taskList = new List<Task>();
- foreach (Task task in tasks!) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ foreach (Task task in tasks)
{
if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
- taskList.Add(task!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ taskList.Add(task);
}
if (taskList.Count == 0)
{
if (exception == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exception);
- bool rval = _task.TrySetException(exception!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ bool rval = _task.TrySetException(exception);
if (!rval && !_task.IsCompleted) SpinUntilCompleted();
return rval;
}
if (exceptions == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exceptions);
List<Exception> defensiveCopy = new List<Exception>();
- foreach (Exception e in exceptions!) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ foreach (Exception e in exceptions)
{
if (e == null)
ThrowHelper.ThrowArgumentException(ExceptionResource.TaskCompletionSourceT_TrySetException_NullException, ExceptionArgument.exceptions);
- defensiveCopy.Add(e!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ defensiveCopy.Add(e);
}
if (defensiveCopy.Count == 0)
{
if (exception == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exception);
- if (!TrySetException(exception!)) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (!TrySetException(exception))
{
ThrowHelper.ThrowInvalidOperationException(ExceptionResource.TaskT_TransitionToFinal_AlreadyCompleted);
}
Interlocked.CompareExchange(ref s_activeTaskSchedulers, new ConditionalWeakTable<TaskScheduler, object?>(), null);
activeTaskSchedulers = s_activeTaskSchedulers;
}
- activeTaskSchedulers!.Add(this, null); // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability
+ activeTaskSchedulers.Add(this, null);
}
/// <summary>
/// Each handler is passed a <see cref="T:System.Threading.Tasks.UnobservedTaskExceptionEventArgs"/>
/// instance, which may be used to examine the exception and to mark it as observed.
/// </remarks>
- public static event EventHandler<UnobservedTaskExceptionEventArgs> UnobservedTaskException;
+ public static event EventHandler<UnobservedTaskExceptionEventArgs> UnobservedTaskException; // TODO-NULLABLE: Should all events use nullable delegate types?
////////////////////////////////////////////////////////////
//
}
Interlocked.CompareExchange(ref s_asyncLocalPrincipal, new AsyncLocal<IPrincipal?>(), null);
}
- s_asyncLocalPrincipal!.Value = value; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability
+ s_asyncLocalPrincipal.Value = value;
}
}
object o = new object();
Interlocked.CompareExchange<object?>(ref s_InternalSyncObject, o, null);
}
- return s_InternalSyncObject!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability
+ return s_InternalSyncObject;
}
}
// read LastEntry {(yearN, 1, 1) - MaxValue }
// read the FirstEntry and LastEntry key values (ex: "1980", "2038")
- int first = (int)dynamicKey.GetValue(FirstEntryValue, -1)!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
- int last = (int)dynamicKey.GetValue(LastEntryValue, -1)!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
+ int first = (int)dynamicKey.GetValue(FirstEntryValue, -1);
+ int last = (int)dynamicKey.GetValue(LastEntryValue, -1);
if (first == -1 || last == -1 || first > last)
{
if (length < 0)
ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum();
- RuntimeType? t = elementType!.UnderlyingSystemType as RuntimeType; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ RuntimeType? t = elementType.UnderlyingSystemType as RuntimeType;
if (t == null)
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType);
- return InternalCreate((void*)t!.TypeHandle.Value, 1, &length, null); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return InternalCreate((void*)t.TypeHandle.Value, 1, &length, null);
}
public static unsafe Array CreateInstance(Type elementType, int length1, int length2)
if (length2 < 0)
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length2, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- RuntimeType? t = elementType!.UnderlyingSystemType as RuntimeType; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ RuntimeType? t = elementType.UnderlyingSystemType as RuntimeType;
if (t == null)
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType);
int* pLengths = stackalloc int[2];
pLengths[0] = length1;
pLengths[1] = length2;
- return InternalCreate((void*)t!.TypeHandle.Value, 2, pLengths, null); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return InternalCreate((void*)t.TypeHandle.Value, 2, pLengths, null);
}
public static unsafe Array CreateInstance(Type elementType, int length1, int length2, int length3)
if (length3 < 0)
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length3, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- RuntimeType? t = elementType!.UnderlyingSystemType as RuntimeType; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ RuntimeType? t = elementType.UnderlyingSystemType as RuntimeType;
if (t == null)
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType);
int* pLengths = stackalloc int[3];
pLengths[0] = length1;
pLengths[1] = length2;
pLengths[2] = length3;
- return InternalCreate((void*)t!.TypeHandle.Value, 3, pLengths, null); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return InternalCreate((void*)t.TypeHandle.Value, 3, pLengths, null);
}
public static unsafe Array CreateInstance(Type elementType, params int[] lengths)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.elementType);
if (lengths == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.lengths);
- if (lengths!.Length == 0) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (lengths.Length == 0)
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NeedAtLeast1Rank);
- RuntimeType? t = elementType!.UnderlyingSystemType as RuntimeType; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ RuntimeType? t = elementType.UnderlyingSystemType as RuntimeType;
if (t == null)
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType);
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.lengths, i, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
fixed (int* pLengths = &lengths[0])
- return InternalCreate((void*)t!.TypeHandle.Value, lengths.Length, pLengths, null); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return InternalCreate((void*)t.TypeHandle.Value, lengths.Length, pLengths, null);
}
public static unsafe Array CreateInstance(Type elementType, int[] lengths, int[] lowerBounds)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.lengths);
if (lowerBounds == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.lowerBounds);
- if (lengths!.Length != lowerBounds!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (lengths.Length != lowerBounds!.Length)
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RanksAndBounds);
if (lengths.Length == 0)
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NeedAtLeast1Rank);
- RuntimeType? t = elementType!.UnderlyingSystemType as RuntimeType; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ RuntimeType? t = elementType.UnderlyingSystemType as RuntimeType;
if (t == null)
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType);
fixed (int* pLengths = &lengths[0])
fixed (int* pLowerBounds = &lowerBounds[0])
- return InternalCreate((void*)t!.TypeHandle.Value, lengths.Length, pLengths, pLowerBounds); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ return InternalCreate((void*)t.TypeHandle.Value, lengths.Length, pLengths, pLowerBounds);
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
if (destinationArray == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.destinationArray);
- Copy(sourceArray!, sourceArray!.GetLowerBound(0), destinationArray!, destinationArray!.GetLowerBound(0), length, false); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ Copy(sourceArray, sourceArray.GetLowerBound(0), destinationArray, destinationArray.GetLowerBound(0), length, false);
}
// Copies length elements from sourceArray, starting at sourceIndex, to
if (array == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
- ref byte p = ref GetRawArrayGeometry(array!, out uint numComponents, out uint elementSize, out int lowerBound, out bool containsGCPointers); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ ref byte p = ref GetRawArrayGeometry(array, out uint numComponents, out uint elementSize, out int lowerBound, out bool containsGCPointers);
int offset = index - lowerBound;
{
if (indices == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.indices);
- if (Rank != indices!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (Rank != indices.Length)
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankIndices);
TypedReference elemref = new TypedReference();
{
if (indices == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.indices);
- if (Rank != indices!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (Rank != indices.Length)
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankIndices);
TypedReference elemref = new TypedReference();
{
if (objAttr[i] != null)
{
- attributes[count] = (Attribute)objAttr[i]!; // TODO-NULLABLE Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
+ attributes[count] = (Attribute)objAttr[i]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
count++;
}
}
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
- if (array!.Rank != 1) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (array.Rank != 1)
{
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
}
{
foreach (var item in m_dictionary)
{
- objects![index++] = new KeyValuePair<TKey, TValue>(item.Key, item.Value); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ objects[index++] = new KeyValuePair<TKey, TValue>(item.Key, item.Value);
}
}
catch (ArrayTypeMismatchException)
Interlocked.CompareExchange<object?>(ref m_syncRoot, new object(), null);
}
}
- return m_syncRoot!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability
+ return m_syncRoot;
}
}
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
}
- m_collection = collection!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ m_collection = collection;
}
#region ICollection<T> Members
Interlocked.CompareExchange<object?>(ref m_syncRoot, new object(), null);
}
}
- return m_syncRoot!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability
+ return m_syncRoot;
}
}
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
}
- m_collection = collection!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ m_collection = collection;
}
#region ICollection<T> Members
Interlocked.CompareExchange<object?>(ref m_syncRoot, new object(), null);
}
}
- return m_syncRoot!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability
+ return m_syncRoot;
}
}
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
}
- if (array!.Rank != 1) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ if (array.Rank != 1)
{
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported);
}
{
foreach (var item in collection)
{
- objects![index++] = item; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ objects[index++] = item;
}
}
catch (ArrayTypeMismatchException)
{
if (target == null)
ThrowNullThisInDelegateToInstance();
- this._target = target!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ this._target = target;
this._methodPtr = methodPtr;
}
{
m_localSymInfos[i] = new LocalSymInfo();
}
- m_localSymInfos[i]!.AddLocalSymInfo(strName, signature, slot, startOffset, endOffset); // TODO-NULLABLE Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
+ m_localSymInfos[i]!.AddLocalSymInfo(strName, signature, slot, startOffset, endOffset); // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
}
internal void AddUsingNamespaceToCurrentScope(
{
m_localSymInfos[i] = new LocalSymInfo();
}
- m_localSymInfos[i]!.AddUsingNamespace(strNamespace); // TODO-NULLABLE Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
+ m_localSymInfos[i]!.AddUsingNamespace(strNamespace); // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
}
internal void AddScopeInfo(ScopeAction sa, int iOffset)
}
if (m_localSymInfos[i] != null)
{
- m_localSymInfos[i]!.EmitLocalSymInfo(symWriter); // TODO-NULLABLE Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
+ m_localSymInfos[i]!.EmitLocalSymInfo(symWriter); // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
}
}
}
{
Interlocked.CompareExchange<object?>(ref m_syncRoot, new object(), null);
}
- return m_syncRoot!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability
+ return m_syncRoot;
}
}
- public override event ModuleResolveEventHandler ModuleResolve
+ public override event ModuleResolveEventHandler ModuleResolve // TODO-NULLABLE: Should all events use nullable delegate types?
{
add
{
{
if (wrapper.Delegate.GetType() == d.GetType())
{
- wrapper.Delegate = Delegate.Combine(wrapper.Delegate, d)!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
+ wrapper.Delegate = Delegate.Combine(wrapper.Delegate, d);
return;
}
}
{
Interlocked.CompareExchange(ref refEventTable, new EventRegistrationTokenTable<T>(), null);
}
- return refEventTable!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability
+ return refEventTable;
}
}
}
_assemblyPaths = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
foreach (string assemblyPath in assemblyPaths)
{
- _assemblyPaths.Add(Path.GetFileNameWithoutExtension(assemblyPath)!, assemblyPath); // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
+ _assemblyPaths.Add(Path.GetFileNameWithoutExtension(assemblyPath), assemblyPath);
}
_nativeSearchPaths = SplitPathsList(nativeSearchPathsList);
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.pHandle, ExceptionResource.ArgumentNull_SafeHandle);
}
- pHandle!.DangerousAddRef(ref success); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ pHandle.DangerousAddRef(ref success);
return pHandle.DangerousGetHandle();
}
try
{
- pHandle!.DangerousRelease(); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
+ pHandle.DangerousRelease();
}
catch
{
Utf8String newString = FastAllocate(value.Length);
Buffer.Memmove(ref newString.DangerousGetMutableReference(), ref MemoryMarshal.GetReference(value), (uint)value.Length);
- return Utf8Utility.ValidateAndFixupUtf8String(newString)!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
+ return Utf8Utility.ValidateAndFixupUtf8String(newString);
}
/// <summary>