Use T? for unconstrained nullable types (#40197)
authorStephen Toub <stoub@microsoft.com>
Fri, 7 Aug 2020 15:25:42 +0000 (11:25 -0400)
committerGitHub <noreply@github.com>
Fri, 7 Aug 2020 15:25:42 +0000 (11:25 -0400)
* Temporarily upgrade compiler version for T? support

* Use T? for unconstrained nullable types

171 files changed:
docs/coding-guidelines/api-guidelines/nullability.md
eng/Versions.props
src/coreclr/src/System.Private.CoreLib/src/System/GC.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs
src/libraries/Common/src/System/Data/ProviderBase/DbReferenceCollection.cs
src/libraries/Common/src/System/Net/Http/aspnetcore/Quic/Implementations/MsQuic/MsQuicStream.cs
src/libraries/Common/src/System/Threading/Tasks/RendezvousAwaitable.cs
src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/ref/Microsoft.Extensions.DependencyInjection.Abstractions.cs
src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ServiceProviderServiceExtensions.cs
src/libraries/Microsoft.VisualBasic.Core/ref/Microsoft.VisualBasic.Core.cs
src/libraries/System.Collections.Concurrent/ref/System.Collections.Concurrent.cs
src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs
src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentBag.cs
src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentDictionary.cs
src/libraries/System.Collections.Immutable/ref/System.Collections.Immutable.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/AllocFreeConcurrentStack.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/IImmutableListQueries.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary_2.Builder.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary_2.HashBucket.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary_2.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableInterlocked.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableList_1.Builder.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableList_1.Node.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableList_1.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedDictionary_2.Builder.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedDictionary_2.Node.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedSet_1.Builder.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedSet_1.Node.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedSet_1.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableStack_1.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/SecureObjectPool.cs
src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/SortedInt32KeyNode.cs
src/libraries/System.Collections.Immutable/src/System/Linq/ImmutableArrayExtensions.cs
src/libraries/System.Collections/ref/System.Collections.cs
src/libraries/System.Collections/src/System/Collections/Generic/CollectionExtensions.cs
src/libraries/System.Collections/src/System/Collections/Generic/LinkedList.cs
src/libraries/System.Collections/src/System/Collections/Generic/Queue.cs
src/libraries/System.Collections/src/System/Collections/Generic/SortedDictionary.cs
src/libraries/System.Collections/src/System/Collections/Generic/SortedList.cs
src/libraries/System.Collections/src/System/Collections/Generic/SortedSet.TreeSubSet.cs
src/libraries/System.Collections/src/System/Collections/Generic/SortedSet.cs
src/libraries/System.Collections/src/System/Collections/Generic/Stack.cs
src/libraries/System.ComponentModel.Composition/ref/System.ComponentModel.Composition.cs
src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/CompositionResultOfT.cs
src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AtomicComposition.cs
src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/ExportProvider.GetExportOverrides.cs
src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/MetadataServices.cs
src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ReflectionModel/LazyMemberInfo.cs
src/libraries/System.Data.Common/ref/System.Data.Common.cs
src/libraries/System.Data.Common/src/System/Data/Common/DbDataReaderExtensions.cs
src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLInt64Storage.cs
src/libraries/System.Data.Common/src/System/Data/DataRowExtensions.cs
src/libraries/System.Data.Common/src/System/Data/DataViewSettingCollection.cs
src/libraries/System.Data.Common/src/System/Data/RbTree.cs
src/libraries/System.Data.Common/src/System/Data/SortExpressionBuilder.cs
src/libraries/System.Data.Common/src/System/Data/TypedTableBaseExtensions.cs
src/libraries/System.Data.Common/src/System/Data/xmlsaver.cs
src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbReferenceCollection.cs
src/libraries/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.Unix.cs
src/libraries/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.Windows.cs
src/libraries/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.cs
src/libraries/System.IO.FileSystem/src/System/IO/Iterator.cs
src/libraries/System.Linq.Expressions/src/System/Dynamic/Utils/CacheDict.cs
src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/LambdaCompiler.cs
src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/Utilities.cs
src/libraries/System.Linq.Parallel/ref/System.Linq.Parallel.cs
src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Enumerables/AggregationMinMaxHelpers.cs
src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Enumerables/EmptyEnumerable.cs
src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Helpers.cs
src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Merging/AsynchronousChannelMergeEnumerator.cs
src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Merging/SynchronousChannelMergeEnumerator.cs
src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/QueryOperators/Binary/ConcatQueryOperator.cs
src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Utils/ReverseComparer.cs
src/libraries/System.Linq.Parallel/src/System/Linq/ParallelEnumerable.cs
src/libraries/System.Linq.Queryable/ref/System.Linq.Queryable.cs
src/libraries/System.Linq.Queryable/src/System/Linq/CachedReflection.cs
src/libraries/System.Linq.Queryable/src/System/Linq/Queryable.cs
src/libraries/System.Linq/ref/System.Linq.cs
src/libraries/System.Linq/src/System/Linq/DefaultIfEmpty.cs
src/libraries/System.Linq/src/System/Linq/ElementAt.cs
src/libraries/System.Linq/src/System/Linq/First.cs
src/libraries/System.Linq/src/System/Linq/IPartition.cs
src/libraries/System.Linq/src/System/Linq/Last.cs
src/libraries/System.Linq/src/System/Linq/Max.cs
src/libraries/System.Linq/src/System/Linq/Min.cs
src/libraries/System.Linq/src/System/Linq/OrderedEnumerable.SpeedOpt.cs
src/libraries/System.Linq/src/System/Linq/OrderedEnumerable.cs
src/libraries/System.Linq/src/System/Linq/Partition.SpeedOpt.cs
src/libraries/System.Linq/src/System/Linq/Repeat.SpeedOpt.cs
src/libraries/System.Linq/src/System/Linq/Select.SpeedOpt.cs
src/libraries/System.Linq/src/System/Linq/Single.cs
src/libraries/System.Memory/src/System/Buffers/ReadOnlySequence.cs
src/libraries/System.Net.Http.Json/ref/System.Net.Http.Json.cs
src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpClientJsonExtensions.Get.cs
src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpContentJsonExtensions.cs
src/libraries/System.Net.Http/tests/StressTests/HttpStress/StressClient.cs
src/libraries/System.Net.Security/src/System/Security/Authentication/ExtendedProtection/ServiceNameCollection.cs
src/libraries/System.ObjectModel/src/System/Collections/ObjectModel/KeyedCollection.cs
src/libraries/System.Private.CoreLib/src/System/Action.cs
src/libraries/System.Private.CoreLib/src/System/Array.cs
src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueue.cs
src/libraries/System.Private.CoreLib/src/System/Collections/Concurrent/ConcurrentQueueSegment.cs
src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Comparer.cs
src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Dictionary.cs
src/libraries/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.cs
src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IComparer.cs
src/libraries/System.Private.CoreLib/src/System/Collections/Generic/IEqualityComparer.cs
src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs
src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/Collection.cs
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs
src/libraries/System.Private.CoreLib/src/System/IComparable.cs
src/libraries/System.Private.CoreLib/src/System/IEquatable.cs
src/libraries/System.Private.CoreLib/src/System/Lazy.cs
src/libraries/System.Private.CoreLib/src/System/Resources/ResourceReader.cs
src/libraries/System.Private.CoreLib/src/System/Resources/ResourceSet.cs
src/libraries/System.Private.CoreLib/src/System/Resources/RuntimeResourceSet.cs
src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskCache.cs
src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs
src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilderT.cs
src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/ConditionalWeakTable.cs
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.NoCom.cs
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs
src/libraries/System.Private.CoreLib/src/System/SpanHelpers.BinarySearch.cs
src/libraries/System.Private.CoreLib/src/System/Threading/AsyncLocal.cs
src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs
src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ProducerConsumerQueues.cs
src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Sources/ManualResetValueTaskSourceCore.cs
src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ValueTask.cs
src/libraries/System.Private.CoreLib/src/System/Threading/ThreadLocal.cs
src/libraries/System.Private.CoreLib/src/System/Type.Helpers.cs
src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/EnumerableExtensions.cs
src/libraries/System.Runtime.CompilerServices.Unsafe/ref/System.Runtime.CompilerServices.Unsafe.cs
src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs
src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryObjectWriter.cs
src/libraries/System.Runtime/ref/System.Runtime.cs
src/libraries/System.Security.Cryptography.Cng/ref/System.Security.Cryptography.Cng.cs
src/libraries/System.Security.Cryptography.Cng/src/Microsoft/Win32/SafeHandles/NCryptSafeHandles.cs
src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/AnyOS/ManagedPal.cs
src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/Windows/PkcsPalWindows.cs
src/libraries/System.Text.Json/ref/System.Text.Json.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.ReadCore.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonPropertyInfoOfT.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonResumableConverterOfT.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Helpers.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Span.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Stream.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.String.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Utf8JsonReader.cs
src/libraries/System.Text.RegularExpressions/src/System/Collections/HashtableExtensions.cs
src/libraries/System.Threading.Channels/src/System/Threading/Channels/AsyncOperation.cs
src/libraries/System.Threading.Channels/src/System/Threading/Channels/BoundedChannel.cs
src/libraries/System.Threading.Channels/src/System/Threading/Channels/UnboundedChannel.cs
src/libraries/System.Threading.Tasks.Dataflow/ref/System.Threading.Tasks.Dataflow.cs
src/libraries/System.Threading.Tasks.Dataflow/src/Base/DataflowBlock.cs
src/libraries/System.Threading.Tasks.Dataflow/src/Base/ISourceBlock.cs
src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BatchBlock.cs
src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BatchedJoinBlock.cs
src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BroadcastBlock.cs
src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BufferBlock.cs
src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/TransformBlock.cs
src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/TransformManyBlock.cs
src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/WriteOnceBlock.cs
src/libraries/System.Threading.Tasks.Dataflow/src/Internal/Common.cs
src/libraries/System.Threading.Tasks.Dataflow/src/Internal/ReorderingBuffer.cs
src/libraries/System.Threading.Tasks.Dataflow/src/Internal/SourceCore.cs
src/libraries/System.Threading.Tasks.Dataflow/src/Internal/TargetRegistry.cs
src/libraries/System.Threading/ref/System.Threading.cs
src/mono/netcore/System.Private.CoreLib/src/System/TypeIdentifier.cs
src/mono/netcore/System.Private.CoreLib/src/System/WeakReference.T.Mono.cs

index 8c029d0..62e0fe3 100644 (file)
@@ -99,6 +99,7 @@ The C# compiler respects a set of attributes that impact its flow analysis.  We
 - **DO** add `[NotNullIfNotNull(string)]` if nullable ref argument will be non-`null` upon exit, when an other argument passed evaluated to non-`null`, pass that argument name as string. Example: `public void Exchange([NotNullIfNotNull("value")] ref object? location, object? value);`.
 - **DO** add `[return: NotNullIfNotNull(string)]` if a method would not return `null` in case an argument passed evaluated to non-`null`, pass that argument name as string. Example: `[return: NotNullIfNotNull("name")] public string? FormatName(string? name);`
 - **DO** add `[MemberNotNull(string fieldName)]` to a helper method which initializes member field(s), passing in the field name. Example: `[MemberNotNull("_buffer")] private void InitializeBuffer()`.  This will help to avoid spurious warnings at call sites that call the initialization method and then proceed to use the specified field.  Note that there are two constructors to `MemberNotNull`; one that takes a single `string`, and one that takes a `params string[]`.  When the number of fields initialized is small (e.g. <= 3), it's preferable to use multiple `[MemberNotNull(string)]` attributes on the method rather than one `[MemberNotNull(string, string, string, ...)]` attribute, as the latter is not CLS compliant and will likely require `#pragma warning disable` and `#pragma warning restore` around the line to suppress warnings.
+- **AVOID** using `[MaybeNull]`, not because it's problematic, but because there's almost always a better option, such as `T?` (as of this writing, in all of the dotnet/runtime there are only 7 occurrences of `[MaybeNull]`).  One example of where it's applicable is `AsyncLocal<T>.Value`; `[DisallowNull]` can't be used here, because `null` is valid if `T` is nullable, and `T?` shouldn't be used because `Value` shouldn't be set to `null` if `T` isn't nullable.  Another is in the relatively rare case where a public or protected field is exposed, may begin life as null, but shouldn't be explicitly set to null.
 
 ## Code Review Guidance
 
index 45e7544..02bd975 100644 (file)
@@ -16,6 +16,8 @@
     <DotNetFinalVersionKind Condition="'$(StabilizePackageVersion)' == 'true'">release</DotNetFinalVersionKind>
     <!-- Opt-in/out repo features -->
     <UsingToolMicrosoftNetCompilers>true</UsingToolMicrosoftNetCompilers>
+    <!-- TODO: Upgrade compiler version to enable T?; remove this once the employed SDK uses a new enough version. -->
+    <MicrosoftNetCompilersToolsetVersion>3.8.0-2.20379.3</MicrosoftNetCompilersToolsetVersion>
     <UsingToolIbcOptimization>true</UsingToolIbcOptimization>
     <UsingToolXliff>false</UsingToolXliff>
     <UsingToolNetFrameworkReferenceAssemblies>true</UsingToolNetFrameworkReferenceAssemblies>
index 1809ea6..cb011de 100644 (file)
@@ -659,7 +659,7 @@ namespace System
         /// If pinned is set to true, <typeparamref name="T"/> must not be a reference type or a type that contains object references.
         /// </remarks>
         [MethodImpl(MethodImplOptions.AggressiveInlining)] // forced to ensure no perf drop for small memory buffers (hot path)
-        public static T[] AllocateUninitializedArray<T>(int length, bool pinned = false)
+        public static T[] AllocateUninitializedArray<T>(int length, bool pinned = false) // T[] rather than T?[] to match `new T[length]` behavior
         {
             if (!pinned)
             {
@@ -705,7 +705,7 @@ namespace System
         /// <remarks>
         /// If pinned is set to true, <typeparamref name="T"/> must not be a reference type or a type that contains object references.
         /// </remarks>
-        public static T[] AllocateArray<T>(int length, bool pinned = false)
+        public static T[] AllocateArray<T>(int length, bool pinned = false) // T[] rather than T?[] to match `new T[length]` behavior
         {
             GC_ALLOC_FLAGS flags = GC_ALLOC_FLAGS.GC_ALLOC_NO_FLAGS;
 
index 994244c..016d950 100644 (file)
@@ -706,7 +706,7 @@ namespace System.Runtime.InteropServices
         }
 
         [SupportedOSPlatform("windows")]
-        public static TWrapper CreateWrapperOfType<T, TWrapper>([AllowNull] T o)
+        public static TWrapper CreateWrapperOfType<T, TWrapper>(T? o)
         {
             return (TWrapper)CreateWrapperOfType(o, typeof(TWrapper))!;
         }
@@ -756,7 +756,7 @@ namespace System.Runtime.InteropServices
         public static extern void GetNativeVariantForObject(object? obj, /* VARIANT * */ IntPtr pDstNativeVariant);
 
         [SupportedOSPlatform("windows")]
-        public static void GetNativeVariantForObject<T>([AllowNull] T obj, IntPtr pDstNativeVariant)
+        public static void GetNativeVariantForObject<T>(T? obj, IntPtr pDstNativeVariant)
         {
             GetNativeVariantForObject((object?)obj, pDstNativeVariant);
         }
@@ -766,10 +766,9 @@ namespace System.Runtime.InteropServices
         public static extern object? GetObjectForNativeVariant(/* VARIANT * */ IntPtr pSrcNativeVariant);
 
         [SupportedOSPlatform("windows")]
-        [return: MaybeNull]
-        public static T GetObjectForNativeVariant<T>(IntPtr pSrcNativeVariant)
+        public static T? GetObjectForNativeVariant<T>(IntPtr pSrcNativeVariant)
         {
-            return (T)GetObjectForNativeVariant(pSrcNativeVariant)!;
+            return (T?)GetObjectForNativeVariant(pSrcNativeVariant);
         }
 
         [SupportedOSPlatform("windows")]
index 1ccde66..8d7aa93 100644 (file)
@@ -137,8 +137,7 @@ namespace System.Data.ProviderBase
             }
         }
 
-        [return: MaybeNull]
-        internal T FindItem<T>(int tag, Func<T, bool> filterMethod) where T : class
+        internal T? FindItem<T>(int tag, Func<T, bool> filterMethod) where T : class
         {
             bool lockObtained = false;
             try
index fc451a7..be0e4a8 100644 (file)
@@ -398,7 +398,7 @@ namespace System.Net.Quic.Implementations.MsQuic
         {
             ThrowIfDisposed();
 
-            return default!;
+            return Task.CompletedTask;
         }
 
         public override ValueTask DisposeAsync()
index 3b4fd9a..b6d1b46 100644 (file)
@@ -24,7 +24,7 @@ namespace System.Threading.Tasks
         /// <summary>The exception representing the failed async operation, if it failed.</summary>
         private ExceptionDispatchInfo? _error;
         /// <summary>The result of the async operation, if it succeeded.</summary>
-        [AllowNull] private TResult _result = default;
+        private TResult? _result;
 #if DEBUG
         private bool _resultSet;
 #endif
@@ -64,7 +64,7 @@ namespace System.Threading.Tasks
             }
 
             // The operation completed successfully.  Clear and return the result.
-            TResult result = _result;
+            TResult result = _result!;
             _result = default(TResult);
 #if DEBUG
             _resultSet = false;
index 5f91373..dffd433 100644 (file)
@@ -111,8 +111,7 @@ namespace Microsoft.Extensions.DependencyInjection
         public static T GetRequiredService<T>(this System.IServiceProvider provider) where T : notnull { throw null; }
         public static System.Collections.Generic.IEnumerable<object?> GetServices(this System.IServiceProvider provider, System.Type serviceType) { throw null; }
         public static System.Collections.Generic.IEnumerable<T> GetServices<T>(this System.IServiceProvider provider) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static T GetService<T>(this System.IServiceProvider provider) { throw null; }
+        public static T? GetService<T>(this System.IServiceProvider provider) { throw null; }
     }
 }
 namespace Microsoft.Extensions.DependencyInjection.Extensions
index e35fc65..29fcd6c 100644 (file)
@@ -18,15 +18,14 @@ namespace Microsoft.Extensions.DependencyInjection
         /// <typeparam name="T">The type of service object to get.</typeparam>
         /// <param name="provider">The <see cref="IServiceProvider"/> to retrieve the service object from.</param>
         /// <returns>A service object of type <typeparamref name="T"/> or null if there is no such service.</returns>
-        [return: MaybeNull]
-        public static T GetService<T>(this IServiceProvider provider)
+        public static T? GetService<T>(this IServiceProvider provider)
         {
             if (provider == null)
             {
                 throw new ArgumentNullException(nameof(provider));
             }
 
-            return (T)provider.GetService(typeof(T));
+            return (T?)provider.GetService(typeof(T));
         }
 
         /// <summary>
index 7b0bfbc..db97852 100644 (file)
@@ -771,9 +771,8 @@ namespace Microsoft.VisualBasic.CompilerServices
         public static decimal ToDecimal(string? Value) { throw null; }
         public static double ToDouble(object? Value) { throw null; }
         public static double ToDouble(string? Value) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
         [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull("Value")]
-        public static T ToGenericParameter<T>(object? Value) { throw null; }
+        public static T? ToGenericParameter<T>(object? Value) { throw null; }
         public static int ToInteger(object? Value) { throw null; }
         public static int ToInteger(string? Value) { throw null; }
         public static long ToLong(object? Value) { throw null; }
index cef519b..c1a477b 100644 (file)
@@ -33,8 +33,8 @@ namespace System.Collections.Concurrent
         System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
         public T Take() { throw null; }
         public T Take(System.Threading.CancellationToken cancellationToken) { throw null; }
-        public static int TakeFromAny(System.Collections.Concurrent.BlockingCollection<T>[] collections, [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] out T item) { throw null; }
-        public static int TakeFromAny(System.Collections.Concurrent.BlockingCollection<T>[] collections, [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] out T item, System.Threading.CancellationToken cancellationToken) { throw null; }
+        public static int TakeFromAny(System.Collections.Concurrent.BlockingCollection<T>[] collections, out T? item) { throw null; }
+        public static int TakeFromAny(System.Collections.Concurrent.BlockingCollection<T>[] collections, out T? item, System.Threading.CancellationToken cancellationToken) { throw null; }
         public T[] ToArray() { throw null; }
         public bool TryAdd(T item) { throw null; }
         public bool TryAdd(T item, int millisecondsTimeout) { throw null; }
@@ -48,10 +48,10 @@ namespace System.Collections.Concurrent
         public bool TryTake([System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out T item, int millisecondsTimeout) { throw null; }
         public bool TryTake([System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out T item, int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) { throw null; }
         public bool TryTake([System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out T item, System.TimeSpan timeout) { throw null; }
-        public static int TryTakeFromAny(System.Collections.Concurrent.BlockingCollection<T>[] collections, [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] out T item) { throw null; }
-        public static int TryTakeFromAny(System.Collections.Concurrent.BlockingCollection<T>[] collections, [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] out T item, int millisecondsTimeout) { throw null; }
-        public static int TryTakeFromAny(System.Collections.Concurrent.BlockingCollection<T>[] collections, [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] out T item, int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) { throw null; }
-        public static int TryTakeFromAny(System.Collections.Concurrent.BlockingCollection<T>[] collections, [System.Diagnostics.CodeAnalysis.MaybeNullAttribute] out T item, System.TimeSpan timeout) { throw null; }
+        public static int TryTakeFromAny(System.Collections.Concurrent.BlockingCollection<T>[] collections, out T? item) { throw null; }
+        public static int TryTakeFromAny(System.Collections.Concurrent.BlockingCollection<T>[] collections, out T? item, int millisecondsTimeout) { throw null; }
+        public static int TryTakeFromAny(System.Collections.Concurrent.BlockingCollection<T>[] collections, out T? item, int millisecondsTimeout, System.Threading.CancellationToken cancellationToken) { throw null; }
+        public static int TryTakeFromAny(System.Collections.Concurrent.BlockingCollection<T>[] collections, out T? item, System.TimeSpan timeout) { throw null; }
     }
     public partial class ConcurrentBag<T> : System.Collections.Concurrent.IProducerConsumerCollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.ICollection, System.Collections.IEnumerable
     {
index ec80b76..a7a74c6 100644 (file)
@@ -1169,7 +1169,7 @@ namespace System.Collections.Concurrent
         /// <exception cref="System.ArgumentOutOfRangeException">The count of <paramref name="collections"/> is greater than the maximum size of
         /// 62 for STA and 63 for MTA.</exception>
         /// <remarks>A call to TakeFromAny may block until an item is available to be removed.</remarks>
-        public static int TakeFromAny(BlockingCollection<T>[] collections, [MaybeNull] out T item)
+        public static int TakeFromAny(BlockingCollection<T>[] collections, out T? item)
         {
             return TakeFromAny(collections, out item, CancellationToken.None);
         }
@@ -1198,7 +1198,7 @@ namespace System.Collections.Concurrent
         /// <exception cref="System.ArgumentOutOfRangeException">The count of <paramref name="collections"/> is greater than the maximum size of
         /// 62 for STA and 63 for MTA.</exception>
         /// <remarks>A call to TakeFromAny may block until an item is available to be removed.</remarks>
-        public static int TakeFromAny(BlockingCollection<T>[] collections, [MaybeNull] out T item, CancellationToken cancellationToken)
+        public static int TakeFromAny(BlockingCollection<T>[] collections, out T? item, CancellationToken cancellationToken)
         {
             int returnValue = TryTakeFromAnyCore(collections, out item, Timeout.Infinite, true, cancellationToken);
             Debug.Assert(returnValue >= 0 && returnValue < collections.Length,
@@ -1226,7 +1226,7 @@ namespace System.Collections.Concurrent
         /// <exception cref="System.ArgumentOutOfRangeException">The count of <paramref name="collections"/> is greater than the maximum size of
         /// 62 for STA and 63 for MTA.</exception>
         /// <remarks>A call to TryTakeFromAny may block until an item is available to be removed.</remarks>
-        public static int TryTakeFromAny(BlockingCollection<T>[] collections, [MaybeNull] out T item)
+        public static int TryTakeFromAny(BlockingCollection<T>[] collections, out T? item)
         {
             return TryTakeFromAny(collections, out item, 0);
         }
@@ -1257,7 +1257,7 @@ namespace System.Collections.Concurrent
         /// <exception cref="System.ArgumentOutOfRangeException">The count of <paramref name="collections"/> is greater than the maximum size of
         /// 62 for STA and 63 for MTA.</exception>
         /// <remarks>A call to TryTakeFromAny may block until an item is available to be removed.</remarks>
-        public static int TryTakeFromAny(BlockingCollection<T>[] collections, [MaybeNull] out T item, TimeSpan timeout)
+        public static int TryTakeFromAny(BlockingCollection<T>[] collections, out T? item, TimeSpan timeout)
         {
             ValidateTimeout(timeout);
             return TryTakeFromAnyCore(collections, out item, (int)timeout.TotalMilliseconds, false, CancellationToken.None);
@@ -1287,7 +1287,7 @@ namespace System.Collections.Concurrent
         /// <exception cref="System.ArgumentOutOfRangeException">The count of <paramref name="collections"/> is greater than the maximum size of
         /// 62 for STA and 63 for MTA.</exception>
         /// <remarks>A call to TryTakeFromAny may block until an item is available to be removed.</remarks>
-        public static int TryTakeFromAny(BlockingCollection<T>[] collections, [MaybeNull] out T item, int millisecondsTimeout)
+        public static int TryTakeFromAny(BlockingCollection<T>[] collections, out T? item, int millisecondsTimeout)
         {
             ValidateMillisecondsTimeout(millisecondsTimeout);
             return TryTakeFromAnyCore(collections, out item, millisecondsTimeout, false, CancellationToken.None);
@@ -1321,7 +1321,7 @@ namespace System.Collections.Concurrent
         /// <exception cref="System.ArgumentOutOfRangeException">The count of <paramref name="collections"/> is greater than the maximum size of
         /// 62 for STA and 63 for MTA.</exception>
         /// <remarks>A call to TryTakeFromAny may block until an item is available to be removed.</remarks>
-        public static int TryTakeFromAny(BlockingCollection<T>[] collections, [MaybeNull] out T item, int millisecondsTimeout, CancellationToken cancellationToken)
+        public static int TryTakeFromAny(BlockingCollection<T>[] collections, out T? item, int millisecondsTimeout, CancellationToken cancellationToken)
         {
             ValidateMillisecondsTimeout(millisecondsTimeout);
             return TryTakeFromAnyCore(collections, out item, millisecondsTimeout, false, cancellationToken);
@@ -1344,7 +1344,7 @@ namespace System.Collections.Concurrent
         /// <exception cref="System.ArgumentException">If the collections argument is a 0-length array or contains a
         /// null element. Also, if at least one of the collections has been marked complete for adds.</exception>
         /// <exception cref="System.ObjectDisposedException">If at least one of the collections has been disposed.</exception>
-        private static int TryTakeFromAnyCore(BlockingCollection<T>[] collections, [MaybeNull] out T item, int millisecondsTimeout, bool isTakeOperation, CancellationToken externalCancellationToken)
+        private static int TryTakeFromAnyCore(BlockingCollection<T>[] collections, out T? item, int millisecondsTimeout, bool isTakeOperation, CancellationToken externalCancellationToken)
         {
             ValidateCollectionsArray(collections, false);
 
@@ -1378,7 +1378,7 @@ namespace System.Collections.Concurrent
         /// <exception cref="System.ArgumentException">If the collections argument is a 0-length array or contains a
         /// null element. Also, if at least one of the collections has been marked complete for adds.</exception>
         /// <exception cref="System.ObjectDisposedException">If at least one of the collections has been disposed.</exception>
-        private static int TryTakeFromAnyCoreSlow(BlockingCollection<T>[] collections, [MaybeNull] out T item, int millisecondsTimeout, bool isTakeOperation, CancellationToken externalCancellationToken)
+        private static int TryTakeFromAnyCoreSlow(BlockingCollection<T>[] collections, out T? item, int millisecondsTimeout, bool isTakeOperation, CancellationToken externalCancellationToken)
         {
             const int OPERATION_FAILED = -1;
 
index e225354..2ac047d 100644 (file)
@@ -1089,7 +1089,7 @@ namespace System.Collections.Concurrent
         private sealed class Enumerator : IEnumerator<T>
         {
             private readonly T[] _array;
-            [AllowNull] private T _current = default;
+            private T? _current;
             private int _index;
 
             public Enumerator(T[] array)
@@ -1110,7 +1110,7 @@ namespace System.Collections.Concurrent
                 return false;
             }
 
-            public T Current => _current;
+            public T Current => _current!;
 
             object? IEnumerator.Current
             {
index 6b06c59..affa3bf 100644 (file)
@@ -344,7 +344,7 @@ namespace System.Collections.Concurrent
         /// <param name="value">The variable into which the removed value, if found, is stored.</param>
         /// <param name="matchValue">Whether removal of the key is conditional on its value.</param>
         /// <param name="oldValue">The conditional value to compare against if <paramref name="matchValue"/> is true</param>
-        private bool TryRemoveInternal(TKey key, [MaybeNullWhen(false)] out TValue value, bool matchValue, [AllowNull] TValue oldValue)
+        private bool TryRemoveInternal(TKey key, [MaybeNullWhen(false)] out TValue value, bool matchValue, TValue? oldValue)
         {
             IEqualityComparer<TKey>? comparer = _comparer;
             int hashcode = comparer is null ? key.GetHashCode() : comparer.GetHashCode(key);
@@ -375,7 +375,7 @@ namespace System.Collections.Concurrent
                                 bool valuesMatch = EqualityComparer<TValue>.Default.Equals(oldValue, curr._value);
                                 if (!valuesMatch)
                                 {
-                                    value = default!;
+                                    value = default;
                                     return false;
                                 }
                             }
index 5c77291..b24217c 100644 (file)
@@ -268,8 +268,7 @@ namespace System.Collections.Immutable
         public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> Create<TKey, TValue>() where TKey : notnull { throw null; }
         public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> Create<TKey, TValue>(System.Collections.Generic.IEqualityComparer<TKey>? keyComparer) where TKey : notnull { throw null; }
         public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> Create<TKey, TValue>(System.Collections.Generic.IEqualityComparer<TKey>? keyComparer, System.Collections.Generic.IEqualityComparer<TValue>? valueComparer) where TKey : notnull { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TValue GetValueOrDefault<TKey, TValue>(this System.Collections.Immutable.IImmutableDictionary<TKey, TValue> dictionary, TKey key) where TKey : notnull { throw null; }
+        public static TValue? GetValueOrDefault<TKey, TValue>(this System.Collections.Immutable.IImmutableDictionary<TKey, TValue> dictionary, TKey key) where TKey : notnull { throw null; }
         public static TValue GetValueOrDefault<TKey, TValue>(this System.Collections.Immutable.IImmutableDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue) where TKey : notnull { throw null; }
         public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TKey, TValue>(this System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> source) where TKey : notnull { throw null; }
         public static System.Collections.Immutable.ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TKey, TValue>(this System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>> source, System.Collections.Generic.IEqualityComparer<TKey>? keyComparer) where TKey : notnull { throw null; }
@@ -367,8 +366,7 @@ namespace System.Collections.Immutable
             public bool ContainsKey(TKey key) { throw null; }
             public bool ContainsValue(TValue value) { throw null; }
             public System.Collections.Immutable.ImmutableDictionary<TKey, TValue>.Enumerator GetEnumerator() { throw null; }
-            [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-            public TValue GetValueOrDefault(TKey key) { throw null; }
+            public TValue? GetValueOrDefault(TKey key) { throw null; }
             public TValue GetValueOrDefault(TKey key, TValue defaultValue) { throw null; }
             public bool Remove(System.Collections.Generic.KeyValuePair<TKey, TValue> item) { throw null; }
             public bool Remove(TKey key) { throw null; }
@@ -572,14 +570,12 @@ namespace System.Collections.Immutable
         public void CopyTo(T[] array) { }
         public void CopyTo(T[] array, int arrayIndex) { }
         public bool Exists(System.Predicate<T> match) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public T Find(System.Predicate<T> match) { throw null; }
+        public T? Find(System.Predicate<T> match) { throw null; }
         public System.Collections.Immutable.ImmutableList<T> FindAll(System.Predicate<T> match) { throw null; }
         public int FindIndex(int startIndex, int count, System.Predicate<T> match) { throw null; }
         public int FindIndex(int startIndex, System.Predicate<T> match) { throw null; }
         public int FindIndex(System.Predicate<T> match) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public T FindLast(System.Predicate<T> match) { throw null; }
+        public T? FindLast(System.Predicate<T> match) { throw null; }
         public int FindLastIndex(int startIndex, int count, System.Predicate<T> match) { throw null; }
         public int FindLastIndex(int startIndex, System.Predicate<T> match) { throw null; }
         public int FindLastIndex(System.Predicate<T> match) { throw null; }
@@ -662,14 +658,12 @@ namespace System.Collections.Immutable
             public void CopyTo(T[] array) { }
             public void CopyTo(T[] array, int arrayIndex) { }
             public bool Exists(System.Predicate<T> match) { throw null; }
-            [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-            public T Find(System.Predicate<T> match) { throw null; }
+            public T? Find(System.Predicate<T> match) { throw null; }
             public System.Collections.Immutable.ImmutableList<T> FindAll(System.Predicate<T> match) { throw null; }
             public int FindIndex(int startIndex, int count, System.Predicate<T> match) { throw null; }
             public int FindIndex(int startIndex, System.Predicate<T> match) { throw null; }
             public int FindIndex(System.Predicate<T> match) { throw null; }
-            [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-            public T FindLast(System.Predicate<T> match) { throw null; }
+            public T? FindLast(System.Predicate<T> match) { throw null; }
             public int FindLastIndex(int startIndex, int count, System.Predicate<T> match) { throw null; }
             public int FindLastIndex(int startIndex, System.Predicate<T> match) { throw null; }
             public int FindLastIndex(System.Predicate<T> match) { throw null; }
@@ -866,8 +860,7 @@ namespace System.Collections.Immutable
             public bool ContainsKey(TKey key) { throw null; }
             public bool ContainsValue(TValue value) { throw null; }
             public System.Collections.Immutable.ImmutableSortedDictionary<TKey, TValue>.Enumerator GetEnumerator() { throw null; }
-            [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-            public TValue GetValueOrDefault(TKey key) { throw null; }
+            public TValue? GetValueOrDefault(TKey key) { throw null; }
             public TValue GetValueOrDefault(TKey key, TValue defaultValue) { throw null; }
             public bool Remove(System.Collections.Generic.KeyValuePair<TKey, TValue> item) { throw null; }
             public bool Remove(TKey key) { throw null; }
@@ -928,10 +921,8 @@ namespace System.Collections.Immutable
         public bool IsEmpty { get { throw null; } }
         public T this[int index] { get { throw null; } }
         public System.Collections.Generic.IComparer<T> KeyComparer { get { throw null; } }
-        [System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public T Max { get { throw null; } }
-        [System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public T Min { get { throw null; } }
+        public T? Max { get { throw null; } }
+        public T? Min { get { throw null; } }
         bool System.Collections.Generic.ICollection<T>.IsReadOnly { get { throw null; } }
         T System.Collections.Generic.IList<T>.this[int index] { get { throw null; } set { } }
         bool System.Collections.ICollection.IsSynchronized { get { throw null; } }
@@ -996,10 +987,8 @@ namespace System.Collections.Immutable
             public int Count { get { throw null; } }
             public T this[int index] { get { throw null; } }
             public System.Collections.Generic.IComparer<T> KeyComparer { get { throw null; } set { } }
-            [System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-            public T Max { get { throw null; } }
-            [System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-            public T Min { get { throw null; } }
+            public T? Max { get { throw null; } }
+            public T? Min { get { throw null; } }
             bool System.Collections.Generic.ICollection<T>.IsReadOnly { get { throw null; } }
             bool System.Collections.ICollection.IsSynchronized { get { throw null; } }
             object System.Collections.ICollection.SyncRoot { get { throw null; } }
@@ -1083,32 +1072,24 @@ namespace System.Linq
 {
     public static partial class ImmutableArrayExtensions
     {
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static T Aggregate<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, T, T> func) { throw null; }
+        public static T? Aggregate<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, T, T> func) { throw null; }
         public static TAccumulate Aggregate<TAccumulate, T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, TAccumulate seed, System.Func<TAccumulate, T, TAccumulate> func) { throw null; }
         public static TResult Aggregate<TAccumulate, TResult, T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, TAccumulate seed, System.Func<TAccumulate, T, TAccumulate> func, System.Func<TAccumulate, TResult> resultSelector) { throw null; }
         public static bool All<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, bool> predicate) { throw null; }
         public static bool Any<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray) { throw null; }
         public static bool Any<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, bool> predicate) { throw null; }
         public static bool Any<T>(this System.Collections.Immutable.ImmutableArray<T>.Builder builder) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static T ElementAtOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, int index) { throw null; }
+        public static T? ElementAtOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, int index) { throw null; }
         public static T ElementAt<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, int index) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static T FirstOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static T FirstOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, bool> predicate) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static T FirstOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T>.Builder builder) { throw null; }
+        public static T? FirstOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray) { throw null; }
+        public static T? FirstOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, bool> predicate) { throw null; }
+        public static T? FirstOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T>.Builder builder) { throw null; }
         public static T First<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray) { throw null; }
         public static T First<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, bool> predicate) { throw null; }
         public static T First<T>(this System.Collections.Immutable.ImmutableArray<T>.Builder builder) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static T LastOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static T LastOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, bool> predicate) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static T LastOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T>.Builder builder) { throw null; }
+        public static T? LastOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray) { throw null; }
+        public static T? LastOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, bool> predicate) { throw null; }
+        public static T? LastOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T>.Builder builder) { throw null; }
         public static T Last<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray) { throw null; }
         public static T Last<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, bool> predicate) { throw null; }
         public static T Last<T>(this System.Collections.Immutable.ImmutableArray<T>.Builder builder) { throw null; }
@@ -1117,10 +1098,8 @@ namespace System.Linq
         public static bool SequenceEqual<TDerived, TBase>(this System.Collections.Immutable.ImmutableArray<TBase> immutableArray, System.Collections.Generic.IEnumerable<TDerived> items, System.Collections.Generic.IEqualityComparer<TBase>? comparer = null) where TDerived : TBase { throw null; }
         public static bool SequenceEqual<TDerived, TBase>(this System.Collections.Immutable.ImmutableArray<TBase> immutableArray, System.Collections.Immutable.ImmutableArray<TDerived> items, System.Collections.Generic.IEqualityComparer<TBase>? comparer = null) where TDerived : TBase { throw null; }
         public static bool SequenceEqual<TDerived, TBase>(this System.Collections.Immutable.ImmutableArray<TBase> immutableArray, System.Collections.Immutable.ImmutableArray<TDerived> items, System.Func<TBase, TBase, bool> predicate) where TDerived : TBase { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static T SingleOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static T SingleOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, bool> predicate) { throw null; }
+        public static T? SingleOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray) { throw null; }
+        public static T? SingleOrDefault<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, bool> predicate) { throw null; }
         public static T Single<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray) { throw null; }
         public static T Single<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray, System.Func<T, bool> predicate) { throw null; }
         public static T[] ToArray<T>(this System.Collections.Immutable.ImmutableArray<T> immutableArray) { throw null; }
index 3188fce..e441355 100644 (file)
@@ -31,7 +31,7 @@ namespace System.Collections.Immutable
                 return true;
             }
 
-            item = default(T)!;
+            item = default;
             return false;
         }
 
index d5decd8..cb19d18 100644 (file)
@@ -120,8 +120,7 @@ namespace System.Collections.Immutable
         /// The first element that matches the conditions defined by the specified predicate,
         /// if found; otherwise, the default value for type <typeparamref name="T"/>.
         /// </returns>
-        [return: MaybeNull]
-        T Find(Predicate<T> match);
+        T? Find(Predicate<T> match);
 
         /// <summary>
         /// Retrieves all the elements that match the conditions defined by the specified
@@ -194,8 +193,7 @@ namespace System.Collections.Immutable
         /// The last element that matches the conditions defined by the specified predicate,
         /// if found; otherwise, the default value for type <typeparamref name="T"/>.
         /// </returns>
-        [return: MaybeNull]
-        T FindLast(Predicate<T> match);
+        T? FindLast(Predicate<T> match);
 
         /// <summary>
         /// Searches for an element that matches the conditions defined by the specified
index 80d99d4..53e6a03 100644 (file)
@@ -290,8 +290,7 @@ namespace System.Collections.Immutable
         /// <param name="dictionary">The dictionary to retrieve the value from.</param>
         /// <param name="key">The key to search for.</param>
         /// <returns>The value for the key, or the default value of type <typeparamref name="TValue"/> if no matching key was found.</returns>
-        [return: MaybeNull]
-        public static TValue GetValueOrDefault<TKey, TValue>(this IImmutableDictionary<TKey, TValue> dictionary, TKey key) where TKey : notnull
+        public static TValue? GetValueOrDefault<TKey, TValue>(this IImmutableDictionary<TKey, TValue> dictionary, TKey key) where TKey : notnull
         {
             return GetValueOrDefault(dictionary, key, default(TValue)!);
         }
index a3c7662..eb94a5b 100644 (file)
@@ -466,8 +466,7 @@ namespace System.Collections.Immutable
             /// </summary>
             /// <param name="key">The key to search for.</param>
             /// <returns>The value for the key, or the default value of type <typeparamref name="TValue"/> if no matching key was found.</returns>
-            [return: MaybeNull]
-            public TValue GetValueOrDefault(TKey key)
+            public TValue? GetValueOrDefault(TKey key)
             {
                 return this.GetValueOrDefault(key, default(TValue)!);
             }
index 0f8e7ce..77e65ec 100644 (file)
@@ -263,7 +263,7 @@ namespace System.Collections.Immutable
             {
                 if (this.IsEmpty)
                 {
-                    value = default(TValue)!;
+                    value = default;
                     return false;
                 }
 
@@ -277,7 +277,7 @@ namespace System.Collections.Immutable
                 var index = _additionalElements.IndexOf(kv, comparers.KeyOnlyComparer);
                 if (index < 0)
                 {
-                    value = default(TValue)!;
+                    value = default;
                     return false;
                 }
 
index 504d120..346fdc1 100644 (file)
@@ -912,7 +912,7 @@ namespace System.Collections.Immutable
                 return bucket.TryGetValue(key, origin.Comparers, out value!);
             }
 
-            value = default(TValue)!;
+            value = default;
             return false;
         }
 
index f907de4..5f99c06 100644 (file)
@@ -525,7 +525,7 @@ namespace System.Collections.Immutable
 
                 if (priorCollection.IsEmpty)
                 {
-                    value = default(T)!;
+                    value = default;
                     return false;
                 }
 
@@ -580,7 +580,7 @@ namespace System.Collections.Immutable
 
                 if (priorCollection.IsEmpty)
                 {
-                    value = default(T)!;
+                    value = default;
                     return false;
                 }
 
index 7d5577d..ee6b888 100644 (file)
@@ -395,8 +395,7 @@ namespace System.Collections.Immutable
             /// The first element that matches the conditions defined by the specified predicate,
             /// if found; otherwise, the default value for type T.
             /// </returns>
-            [return: MaybeNull]
-            public T Find(Predicate<T> match) => _root.Find(match);
+            public T? Find(Predicate<T> match) => _root.Find(match);
 
             /// <summary>
             /// Retrieves all the elements that match the conditions defined by the specified
@@ -469,8 +468,7 @@ namespace System.Collections.Immutable
             /// The last element that matches the conditions defined by the specified predicate,
             /// if found; otherwise, the default value for type T.
             /// </returns>
-            [return: MaybeNull]
-            public T FindLast(Predicate<T> match) => _root.FindLast(match);
+            public T? FindLast(Predicate<T> match) => _root.FindLast(match);
 
             /// <summary>
             /// Searches for an element that matches the conditions defined by the specified
index 9c30a67..ef03813 100644 (file)
@@ -998,8 +998,7 @@ namespace System.Collections.Immutable
             /// The first element that matches the conditions defined by the specified predicate,
             /// if found; otherwise, the default value for type <typeparamref name="T"/>.
             /// </returns>
-            [return: MaybeNull]
-            internal T Find(Predicate<T> match)
+            internal T? Find(Predicate<T> match)
             {
                 Requires.NotNull(match, nameof(match));
 
@@ -1011,7 +1010,7 @@ namespace System.Collections.Immutable
                     }
                 }
 
-                return default(T)!;
+                return default;
             }
 
             /// <summary>
@@ -1144,8 +1143,7 @@ namespace System.Collections.Immutable
             /// The last element that matches the conditions defined by the specified predicate,
             /// if found; otherwise, the default value for type <typeparamref name="T"/>.
             /// </returns>
-            [return: MaybeNull]
-            internal T FindLast(Predicate<T> match)
+            internal T? FindLast(Predicate<T> match)
             {
                 Requires.NotNull(match, nameof(match));
 
@@ -1160,7 +1158,7 @@ namespace System.Collections.Immutable
                     }
                 }
 
-                return default(T)!;
+                return default;
             }
 
             /// <summary>
index e252d3c..9597b0a 100644 (file)
@@ -593,8 +593,7 @@ namespace System.Collections.Immutable
         /// The first element that matches the conditions defined by the specified predicate,
         /// if found; otherwise, the default value for type <typeparamref name="T"/>.
         /// </returns>
-        [return: MaybeNull]
-        public T Find(Predicate<T> match) => _root.Find(match);
+        public T? Find(Predicate<T> match) => _root.Find(match);
 
         /// <summary>
         /// Retrieves all the elements that match the conditions defined by the specified
@@ -667,8 +666,7 @@ namespace System.Collections.Immutable
         /// The last element that matches the conditions defined by the specified predicate,
         /// if found; otherwise, the default value for type <typeparamref name="T"/>.
         /// </returns>
-        [return: MaybeNull]
-        public T FindLast(Predicate<T> match) => _root.FindLast(match);
+        public T? FindLast(Predicate<T> match) => _root.FindLast(match);
 
         /// <summary>
         /// Searches for an element that matches the conditions defined by the specified
index 47da5f0..2f8fafe 100644 (file)
@@ -603,8 +603,7 @@ namespace System.Collections.Immutable
             /// </summary>
             /// <param name="key">The key to search for.</param>
             /// <returns>The value for the key, or the default value for type <typeparamref name="TValue"/> if no matching key was found.</returns>
-            [return: MaybeNull]
-            public TValue GetValueOrDefault(TKey key)
+            public TValue? GetValueOrDefault(TKey key)
             {
                 return this.GetValueOrDefault(key, default(TValue)!);
             }
index 353fb92..99173a5 100644 (file)
@@ -362,7 +362,7 @@ namespace System.Collections.Immutable
                 var match = this.Search(key, keyComparer);
                 if (match.IsEmpty)
                 {
-                    value = default(TValue)!;
+                    value = default;
                     return false;
                 }
                 else
index 3516981..2a1c606 100644 (file)
@@ -123,8 +123,7 @@ namespace System.Collections.Immutable
             /// Gets the maximum value in the collection, as defined by the comparer.
             /// </summary>
             /// <value>The maximum value in the set.</value>
-            [MaybeNull]
-            public T Max
+            public T? Max
             {
                 get { return _root.Max; }
             }
@@ -133,8 +132,7 @@ namespace System.Collections.Immutable
             /// Gets the minimum value in the collection, as defined by the comparer.
             /// </summary>
             /// <value>The minimum value in the set.</value>
-            [MaybeNull]
-            public T Min
+            public T? Min
             {
                 get { return _root.Min; }
             }
index 9ff2099..89b044c 100644 (file)
@@ -184,14 +184,13 @@ namespace System.Collections.Immutable
             /// Gets the maximum value in the collection, as defined by the comparer.
             /// </summary>
             /// <value>The maximum value in the set.</value>
-            [MaybeNull]
-            internal T Max
+            internal T? Max
             {
                 get
                 {
                     if (this.IsEmpty)
                     {
-                        return default(T)!;
+                        return default;
                     }
 
                     Node n = this;
@@ -208,14 +207,13 @@ namespace System.Collections.Immutable
             /// Gets the minimum value in the collection, as defined by the comparer.
             /// </summary>
             /// <value>The minimum value in the set.</value>
-            [MaybeNull]
-            internal T Min
+            internal T? Min
             {
                 get
                 {
                     if (this.IsEmpty)
                     {
-                        return default(T)!;
+                        return default;
                     }
 
                     Node n = this;
index c6b8a28..b74674d 100644 (file)
@@ -84,8 +84,7 @@ namespace System.Collections.Immutable
         /// Gets the maximum value in the collection, as defined by the comparer.
         /// </summary>
         /// <value>The maximum value in the set.</value>
-        [MaybeNull]
-        public T Max
+        public T? Max
         {
             get { return _root.Max; }
         }
@@ -94,8 +93,7 @@ namespace System.Collections.Immutable
         /// Gets the minimum value in the collection, as defined by the comparer.
         /// </summary>
         /// <value>The minimum value in the set.</value>
-        [MaybeNull]
-        public T Min
+        public T? Min
         {
             get { return _root.Min; }
         }
index 15b5fbd..f8b70a0 100644 (file)
@@ -27,8 +27,7 @@ namespace System.Collections.Immutable
         /// <summary>
         /// The element on the top of the stack.
         /// </summary>
-        [MaybeNull]
-        private readonly T _head = default!;
+        private readonly T? _head;
 
         /// <summary>
         /// A stack that contains the rest of the elements (under the top element).
index 8d3664f..6d194da 100644 (file)
@@ -124,7 +124,7 @@ namespace System.Collections.Immutable
             }
             else
             {
-                value = default(T)!;
+                value = default;
                 return false;
             }
         }
index 96ba562..25cc063 100644 (file)
@@ -34,8 +34,7 @@ namespace System.Collections.Immutable
         /// <summary>
         /// The value associated with this node.
         /// </summary>
-        [MaybeNull]
-        private readonly TValue _value = default!;
+        private readonly TValue? _value;
 
         /// <summary>
         /// A value indicating whether this node has been frozen (made immutable).
@@ -197,15 +196,14 @@ namespace System.Collections.Immutable
         /// </summary>
         /// <param name="key">The key.</param>
         /// <returns>The value.</returns>
-        [return: MaybeNull]
-        internal TValue GetValueOrDefault(int key)
+        internal TValue? GetValueOrDefault(int key)
         {
             SortedInt32KeyNode<TValue> node = this;
             while (true)
             {
                 if (node.IsEmpty)
                 {
-                    return default(TValue)!;
+                    return default;
                 }
 
                 if (key == node._key)
@@ -237,7 +235,7 @@ namespace System.Collections.Immutable
             {
                 if (node.IsEmpty)
                 {
-                    value = default(TValue)!;
+                    value = default;
                     return false;
                 }
 
index 13109d4..2850cc5 100644 (file)
@@ -253,14 +253,13 @@ namespace System.Linq
         /// Applies an accumulator function over a sequence.
         /// </summary>
         /// <typeparam name="T">The type of element contained by the collection.</typeparam>
-        [return: MaybeNull]
-        public static T Aggregate<T>(this ImmutableArray<T> immutableArray, Func<T, T, T> func)
+        public static T? Aggregate<T>(this ImmutableArray<T> immutableArray, Func<T, T, T> func)
         {
             Requires.NotNull(func, nameof(func));
 
             if (immutableArray.Length == 0)
             {
-                return default(T)!;
+                return default;
             }
 
             var result = immutableArray[0];
@@ -316,12 +315,11 @@ namespace System.Linq
         /// Returns the element at a specified index in a sequence or a default value if the index is out of range.
         /// </summary>
         /// <typeparam name="T">The type of element contained by the collection.</typeparam>
-        [return: MaybeNull]
-        public static T ElementAtOrDefault<T>(this ImmutableArray<T> immutableArray, int index)
+        public static T? ElementAtOrDefault<T>(this ImmutableArray<T> immutableArray, int index)
         {
             if (index < 0 || index >= immutableArray.Length)
             {
-                return default(T)!;
+                return default;
             }
 
             return immutableArray[index];
@@ -367,18 +365,16 @@ namespace System.Linq
         /// </summary>
         /// <typeparam name="T">The type of element contained by the collection.</typeparam>
         /// <param name="immutableArray"></param>
-        [return: MaybeNull]
-        public static T FirstOrDefault<T>(this ImmutableArray<T> immutableArray)
+        public static T? FirstOrDefault<T>(this ImmutableArray<T> immutableArray)
         {
-            return immutableArray.array!.Length > 0 ? immutableArray.array[0] : default(T)!;
+            return immutableArray.array!.Length > 0 ? immutableArray.array[0] : default;
         }
 
         /// <summary>
         /// Returns the first element of the sequence that satisfies a condition or a default value if no such element is found.
         /// </summary>
         /// <typeparam name="T">The type of element contained by the collection.</typeparam>
-        [return: MaybeNull]
-        public static T FirstOrDefault<T>(this ImmutableArray<T> immutableArray, Func<T, bool> predicate)
+        public static T? FirstOrDefault<T>(this ImmutableArray<T> immutableArray, Func<T, bool> predicate)
         {
             Requires.NotNull(predicate, nameof(predicate));
 
@@ -390,7 +386,7 @@ namespace System.Linq
                 }
             }
 
-            return default(T)!;
+            return default;
         }
 
         /// <summary>
@@ -432,8 +428,7 @@ namespace System.Linq
         /// </summary>
         /// <typeparam name="T">The type of element contained by the collection.</typeparam>
         /// <param name="immutableArray"></param>
-        [return: MaybeNull]
-        public static T LastOrDefault<T>(this ImmutableArray<T> immutableArray)
+        public static T? LastOrDefault<T>(this ImmutableArray<T> immutableArray)
         {
             immutableArray.ThrowNullRefIfNotInitialized();
             return immutableArray.array!.LastOrDefault()!;
@@ -443,8 +438,7 @@ namespace System.Linq
         /// Returns the last element of a sequence that satisfies a condition or a default value if no such element is found.
         /// </summary>
         /// <typeparam name="T">The type of element contained by the collection.</typeparam>
-        [return: MaybeNull]
-        public static T LastOrDefault<T>(this ImmutableArray<T> immutableArray, Func<T, bool> predicate)
+        public static T? LastOrDefault<T>(this ImmutableArray<T> immutableArray, Func<T, bool> predicate)
         {
             Requires.NotNull(predicate, nameof(predicate));
 
@@ -456,7 +450,7 @@ namespace System.Linq
                 }
             }
 
-            return default(T)!;
+            return default;
         }
 
         /// <summary>
@@ -478,8 +472,8 @@ namespace System.Linq
         {
             Requires.NotNull(predicate, nameof(predicate));
 
-            var first = true;
-            var result = default(T)!;
+            bool first = true;
+            T? result = default;
             foreach (var v in immutableArray.array!)
             {
                 if (predicate(v))
@@ -499,7 +493,7 @@ namespace System.Linq
                 Enumerable.Empty<T>().Single(); // throw the same exception as LINQ would
             }
 
-            return result;
+            return result!;
         }
 
         /// <summary>
@@ -507,8 +501,7 @@ namespace System.Linq
         /// </summary>
         /// <typeparam name="T">The type of element contained by the collection.</typeparam>
         /// <param name="immutableArray"></param>
-        [return: MaybeNull]
-        public static T SingleOrDefault<T>(this ImmutableArray<T> immutableArray)
+        public static T? SingleOrDefault<T>(this ImmutableArray<T> immutableArray)
         {
             immutableArray.ThrowNullRefIfNotInitialized();
             return immutableArray.array!.SingleOrDefault()!;
@@ -518,13 +511,12 @@ namespace System.Linq
         /// Returns the only element of a sequence that satisfies a specified condition or a default value if no such element exists; this method throws an exception if more than one element satisfies the condition.
         /// </summary>
         /// <typeparam name="T">The type of element contained by the collection.</typeparam>
-        [return: MaybeNull]
-        public static T SingleOrDefault<T>(this ImmutableArray<T> immutableArray, Func<T, bool> predicate)
+        public static T? SingleOrDefault<T>(this ImmutableArray<T> immutableArray, Func<T, bool> predicate)
         {
             Requires.NotNull(predicate, nameof(predicate));
 
-            var first = true;
-            var result = default(T)!;
+            bool first = true;
+            T? result = default;
             foreach (var v in immutableArray.array!)
             {
                 if (predicate(v))
@@ -657,12 +649,11 @@ namespace System.Linq
         /// <summary>
         /// Returns the first element in the collection, or the default value if the collection is empty.
         /// </summary>
-        [return: MaybeNull]
-        public static T FirstOrDefault<T>(this ImmutableArray<T>.Builder builder)
+        public static T? FirstOrDefault<T>(this ImmutableArray<T>.Builder builder)
         {
             Requires.NotNull(builder, nameof(builder));
 
-            return builder.Any() ? builder[0] : default(T)!;
+            return builder.Any() ? builder[0] : default;
         }
 
         /// <summary>
@@ -684,12 +675,11 @@ namespace System.Linq
         /// <summary>
         /// Returns the last element in the collection, or the default value if the collection is empty.
         /// </summary>
-        [return: MaybeNull]
-        public static T LastOrDefault<T>(this ImmutableArray<T>.Builder builder)
+        public static T? LastOrDefault<T>(this ImmutableArray<T>.Builder builder)
         {
             Requires.NotNull(builder, nameof(builder));
 
-            return builder.Any() ? builder[builder.Count - 1] : default(T)!;
+            return builder.Any() ? builder[builder.Count - 1] : default;
         }
 
         /// <summary>
index b0505e8..334a67a 100644 (file)
@@ -43,8 +43,7 @@ namespace System.Collections.Generic
 {
     public static partial class CollectionExtensions
     {
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TValue GetValueOrDefault<TKey, TValue>(this System.Collections.Generic.IReadOnlyDictionary<TKey, TValue> dictionary, TKey key) { throw null; }
+        public static TValue? GetValueOrDefault<TKey, TValue>(this System.Collections.Generic.IReadOnlyDictionary<TKey, TValue> dictionary, TKey key) { throw null; }
         public static TValue GetValueOrDefault<TKey, TValue>(this System.Collections.Generic.IReadOnlyDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue) { throw null; }
         public static bool Remove<TKey, TValue>(this System.Collections.Generic.IDictionary<TKey, TValue> dictionary, TKey key, [System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute(false)] out TValue value) { throw null; }
         public static bool TryAdd<TKey, TValue>(this System.Collections.Generic.IDictionary<TKey, TValue> dictionary, TKey key, TValue value) { throw null; }
@@ -53,7 +52,7 @@ namespace System.Collections.Generic
     {
         protected Comparer() { }
         public static System.Collections.Generic.Comparer<T> Default { get { throw null; } }
-        public abstract int Compare([System.Diagnostics.CodeAnalysis.AllowNullAttribute] T x, [System.Diagnostics.CodeAnalysis.AllowNullAttribute] T y);
+        public abstract int Compare(T? x, T? y);
         public static System.Collections.Generic.Comparer<T> Create(System.Comparison<T> comparison) { throw null; }
         int System.Collections.IComparer.Compare(object? x, object? y) { throw null; }
     }
@@ -184,7 +183,7 @@ namespace System.Collections.Generic
     {
         protected EqualityComparer() { }
         public static System.Collections.Generic.EqualityComparer<T> Default { get { throw null; } }
-        public abstract bool Equals([System.Diagnostics.CodeAnalysis.AllowNullAttribute] T x, [System.Diagnostics.CodeAnalysis.AllowNullAttribute] T y);
+        public abstract bool Equals(T? x, T? y);
         public abstract int GetHashCode([System.Diagnostics.CodeAnalysis.DisallowNullAttribute] T obj);
         bool System.Collections.IEqualityComparer.Equals(object? x, object? y) { throw null; }
         int System.Collections.IEqualityComparer.GetHashCode(object obj) { throw null; }
@@ -326,14 +325,12 @@ namespace System.Collections.Generic
         public void CopyTo(T[] array) { }
         public void CopyTo(T[] array, int arrayIndex) { }
         public bool Exists(System.Predicate<T> match) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public T Find(System.Predicate<T> match) { throw null; }
+        public T? Find(System.Predicate<T> match) { throw null; }
         public System.Collections.Generic.List<T> FindAll(System.Predicate<T> match) { throw null; }
         public int FindIndex(int startIndex, int count, System.Predicate<T> match) { throw null; }
         public int FindIndex(int startIndex, System.Predicate<T> match) { throw null; }
         public int FindIndex(System.Predicate<T> match) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public T FindLast(System.Predicate<T> match) { throw null; }
+        public T? FindLast(System.Predicate<T> match) { throw null; }
         public int FindLastIndex(int startIndex, int count, System.Predicate<T> match) { throw null; }
         public int FindLastIndex(int startIndex, System.Predicate<T> match) { throw null; }
         public int FindLastIndex(System.Predicate<T> match) { throw null; }
@@ -589,10 +586,8 @@ namespace System.Collections.Generic
         protected SortedSet(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
         public System.Collections.Generic.IComparer<T> Comparer { get { throw null; } }
         public int Count { get { throw null; } }
-        [System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public T Max { get { throw null; } }
-        [System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public T Min { get { throw null; } }
+        public T? Max { get { throw null; } }
+        public T? Min { get { throw null; } }
         bool System.Collections.Generic.ICollection<T>.IsReadOnly { get { throw null; } }
         bool System.Collections.ICollection.IsSynchronized { get { throw null; } }
         object System.Collections.ICollection.SyncRoot { get { throw null; } }
@@ -607,7 +602,7 @@ namespace System.Collections.Generic
         public void ExceptWith(System.Collections.Generic.IEnumerable<T> other) { }
         public System.Collections.Generic.SortedSet<T>.Enumerator GetEnumerator() { throw null; }
         protected virtual void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
-        public virtual System.Collections.Generic.SortedSet<T> GetViewBetween(T lowerValue, T upperValue) { throw null; }
+        public virtual System.Collections.Generic.SortedSet<T> GetViewBetween(T? lowerValue, T? upperValue) { throw null; }
         public virtual void IntersectWith(System.Collections.Generic.IEnumerable<T> other) { }
         public bool IsProperSubsetOf(System.Collections.Generic.IEnumerable<T> other) { throw null; }
         public bool IsProperSupersetOf(System.Collections.Generic.IEnumerable<T> other) { throw null; }
index 47de3ec..39158f2 100644 (file)
@@ -7,8 +7,7 @@ namespace System.Collections.Generic
 {
     public static class CollectionExtensions
     {
-        [return: MaybeNull]
-        public static TValue GetValueOrDefault<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary, TKey key)
+        public static TValue? GetValueOrDefault<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary, TKey key)
         {
             return dictionary.GetValueOrDefault(key, default!);
         }
@@ -53,7 +52,7 @@ namespace System.Collections.Generic
                 return true;
             }
 
-            value = default(TValue)!;
+            value = default;
             return false;
         }
     }
index 1694a7c..cd27186 100644 (file)
@@ -530,7 +530,7 @@ namespace System.Collections.Generic
             private readonly LinkedList<T> _list;
             private LinkedListNode<T>? _node;
             private readonly int _version;
-            [AllowNull] private T _current;
+            private T? _current;
             private int _index;
 
             internal Enumerator(LinkedList<T> list)
@@ -542,10 +542,7 @@ namespace System.Collections.Generic
                 _index = 0;
             }
 
-            public T Current
-            {
-                get { return _current; }
-            }
+            public T Current => _current!;
 
             object? IEnumerator.Current
             {
index efd2b1e..c468d16 100644 (file)
@@ -395,7 +395,7 @@ namespace System.Collections.Generic
             private readonly Queue<T> _q;
             private readonly int _version;
             private int _index;   // -1 = not started, -2 = ended/disposed
-            [AllowNull] private T _currentElement;
+            private T? _currentElement;
 
             internal Enumerator(Queue<T> q)
             {
@@ -457,7 +457,7 @@ namespace System.Collections.Generic
                 {
                     if (_index < 0)
                         ThrowEnumerationNotStartedOrEnded();
-                    return _currentElement;
+                    return _currentElement!;
                 }
             }
 
index 8bca75b..fd649d5 100644 (file)
@@ -288,7 +288,7 @@ namespace System.Collections.Generic
             TreeSet<KeyValuePair<TKey, TValue>>.Node? node = _set.FindNode(new KeyValuePair<TKey, TValue>(key, default(TValue)!));
             if (node == null)
             {
-                value = default(TValue)!;
+                value = default;
                 return false;
             }
             value = node.Item.Value;
index 1ce3cd9..220de76 100644 (file)
@@ -685,7 +685,7 @@ namespace System.Collections.Generic
                 return true;
             }
 
-            value = default(TValue)!;
+            value = default;
             return false;
         }
 
@@ -761,8 +761,8 @@ namespace System.Collections.Generic
         private struct Enumerator : IEnumerator<KeyValuePair<TKey, TValue>>, IDictionaryEnumerator
         {
             private readonly SortedList<TKey, TValue> _sortedList;
-            [AllowNull] private TKey _key;
-            [AllowNull] private TValue _value;
+            private TKey? _key;
+            private TValue? _value;
             private int _index;
             private readonly int _version;
             private readonly int _getEnumeratorRetType;  // What should Enumerator.Current return?
@@ -796,7 +796,7 @@ namespace System.Collections.Generic
                         throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen);
                     }
 
-                    return _key;
+                    return _key!;
                 }
             }
 
@@ -827,17 +827,11 @@ namespace System.Collections.Generic
                         throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen);
                     }
 
-                    return new DictionaryEntry(_key, _value);
+                    return new DictionaryEntry(_key!, _value);
                 }
             }
 
-            public KeyValuePair<TKey, TValue> Current
-            {
-                get
-                {
-                    return new KeyValuePair<TKey, TValue>(_key, _value);
-                }
-            }
+            public KeyValuePair<TKey, TValue> Current => new KeyValuePair<TKey, TValue>(_key!, _value!);
 
             object? IEnumerator.Current
             {
@@ -850,11 +844,11 @@ namespace System.Collections.Generic
 
                     if (_getEnumeratorRetType == DictEntry)
                     {
-                        return new DictionaryEntry(_key, _value);
+                        return new DictionaryEntry(_key!, _value);
                     }
                     else
                     {
-                        return new KeyValuePair<TKey, TValue>(_key, _value);
+                        return new KeyValuePair<TKey, TValue>(_key!, _value!);
                     }
                 }
             }
@@ -890,7 +884,7 @@ namespace System.Collections.Generic
             private readonly SortedList<TKey, TValue> _sortedList;
             private int _index;
             private readonly int _version;
-            [AllowNull] private TKey _currentKey = default!;
+            private TKey? _currentKey;
 
             internal SortedListKeyEnumerator(SortedList<TKey, TValue> sortedList)
             {
@@ -923,13 +917,7 @@ namespace System.Collections.Generic
                 return false;
             }
 
-            public TKey Current
-            {
-                get
-                {
-                    return _currentKey;
-                }
-            }
+            public TKey Current => _currentKey!;
 
             object? IEnumerator.Current
             {
@@ -960,7 +948,7 @@ namespace System.Collections.Generic
             private readonly SortedList<TKey, TValue> _sortedList;
             private int _index;
             private readonly int _version;
-            [AllowNull] private TValue _currentValue = default!;
+            private TValue? _currentValue;
 
             internal SortedListValueEnumerator(SortedList<TKey, TValue> sortedList)
             {
@@ -993,13 +981,7 @@ namespace System.Collections.Generic
                 return false;
             }
 
-            public TValue Current
-            {
-                get
-                {
-                    return _currentValue;
-                }
-            }
+            public TValue Current => _currentValue!;
 
             object? IEnumerator.Current
             {
index eb116ac..91745e2 100644 (file)
@@ -16,10 +16,8 @@ namespace System.Collections.Generic
         internal sealed class TreeSubSet : SortedSet<T>, ISerializable, IDeserializationCallback
         {
             private readonly SortedSet<T> _underlying;
-            [MaybeNull, AllowNull]
-            private readonly T _min;
-            [MaybeNull, AllowNull]
-            private readonly T _max;
+            private readonly T? _min;
+            private readonly T? _max;
             // keeps track of whether the count variable is up to date
             // up to date -> _countVersion = _underlying.version
             // not up to date -> _countVersion < _underlying.version
@@ -38,7 +36,7 @@ namespace System.Collections.Generic
             }
 #endif
 
-            public TreeSubSet(SortedSet<T> Underlying, [AllowNull] T Min, [AllowNull] T Max, bool lowerBoundActive, bool upperBoundActive)
+            public TreeSubSet(SortedSet<T> Underlying, T? Min, T? Max, bool lowerBoundActive, bool upperBoundActive)
                 : base(Underlying.Comparer)
             {
                 _underlying = Underlying;
@@ -129,7 +127,7 @@ namespace System.Collections.Generic
                 get
                 {
                     Node? current = root;
-                    T result = default(T)!;
+                    T? result = default;
 
                     while (current != null)
                     {
@@ -150,7 +148,7 @@ namespace System.Collections.Generic
                         }
                     }
 
-                    return result;
+                    return result!;
                 }
             }
 
@@ -159,7 +157,7 @@ namespace System.Collections.Generic
                 get
                 {
                     Node? current = root;
-                    T result = default(T)!;
+                    T? result = default;
 
                     while (current != null)
                     {
@@ -179,7 +177,7 @@ namespace System.Collections.Generic
                         }
                     }
 
-                    return result;
+                    return result!;
                 }
             }
 
@@ -340,7 +338,7 @@ namespace System.Collections.Generic
             // This passes functionality down to the underlying tree, clipping edges if necessary
             // There's nothing gained by having a nested subset. May as well draw it from the base
             // Cannot increase the bounds of the subset, can only decrease it
-            public override SortedSet<T> GetViewBetween([AllowNull] T lowerValue, [AllowNull] T upperValue)
+            public override SortedSet<T> GetViewBetween(T? lowerValue, T? upperValue)
             {
                 if (_lBoundActive && Comparer.Compare(_min, lowerValue) > 0)
                 {
index 3cc375c..3d2989a 100644 (file)
@@ -755,9 +755,9 @@ namespace System.Collections.Generic
             return -1;
         }
 
-        internal Node? FindRange([AllowNull] T from, [AllowNull]  T to) => FindRange(from, to, lowerBoundActive: true, upperBoundActive: true);
+        internal Node? FindRange(T? from, T? to) => FindRange(from, to, lowerBoundActive: true, upperBoundActive: true);
 
-        internal Node? FindRange([AllowNull] T from, [AllowNull] T to, bool lowerBoundActive, bool upperBoundActive)
+        internal Node? FindRange(T? from, T? to, bool lowerBoundActive, bool upperBoundActive)
         {
             Node? current = root;
             while (current != null)
@@ -1504,17 +1504,15 @@ namespace System.Collections.Generic
 
         #region ISorted members
 
-        [MaybeNull]
-        public T Min => MinInternal;
+        public T? Min => MinInternal;
 
-        [MaybeNull]
-        internal virtual T MinInternal
+        internal virtual T? MinInternal
         {
             get
             {
                 if (root == null)
                 {
-                    return default(T)!;
+                    return default;
                 }
 
                 Node current = root;
@@ -1527,17 +1525,15 @@ namespace System.Collections.Generic
             }
         }
 
-        [MaybeNull]
-        public T Max => MaxInternal;
+        public T? Max => MaxInternal;
 
-        [MaybeNull]
-        internal virtual T MaxInternal
+        internal virtual T? MaxInternal
         {
             get
             {
                 if (root == null)
                 {
-                    return default(T)!;
+                    return default;
                 }
 
                 Node current = root;
@@ -1559,7 +1555,7 @@ namespace System.Collections.Generic
             }
         }
 
-        public virtual SortedSet<T> GetViewBetween([AllowNull] T lowerValue, [AllowNull] T upperValue)
+        public virtual SortedSet<T> GetViewBetween(T? lowerValue, T? upperValue)
         {
             if (Comparer.Compare(lowerValue, upperValue) > 0)
             {
@@ -2074,7 +2070,7 @@ namespace System.Collections.Generic
                 actualValue = node.Item;
                 return true;
             }
-            actualValue = default(T)!;
+            actualValue = default;
             return false;
         }
 
index dbb4157..8f191ee 100644 (file)
@@ -315,7 +315,7 @@ namespace System.Collections.Generic
             private readonly Stack<T> _stack;
             private readonly int _version;
             private int _index;
-            [AllowNull] private T _currentElement;
+            private T? _currentElement;
 
             internal Enumerator(Stack<T> stack)
             {
@@ -361,7 +361,7 @@ namespace System.Collections.Generic
                 {
                     if (_index < 0)
                         ThrowEnumerationNotStartedOrEnded();
-                    return _currentElement;
+                    return _currentElement!;
                 }
             }
 
index 2b30949..f55f6b2 100644 (file)
@@ -415,16 +415,12 @@ namespace System.ComponentModel.Composition.Hosting
         protected ExportProvider() { }
         public event System.EventHandler<System.ComponentModel.Composition.Hosting.ExportsChangeEventArgs>? ExportsChanged { add { } remove { } }
         public event System.EventHandler<System.ComponentModel.Composition.Hosting.ExportsChangeEventArgs>? ExportsChanging { add { } remove { } }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public T GetExportedValueOrDefault<T>() { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public T GetExportedValueOrDefault<T>(string? contractName) { throw null; }
+        public T? GetExportedValueOrDefault<T>() { throw null; }
+        public T? GetExportedValueOrDefault<T>(string? contractName) { throw null; }
         public System.Collections.Generic.IEnumerable<T> GetExportedValues<T>() { throw null; }
         public System.Collections.Generic.IEnumerable<T> GetExportedValues<T>(string? contractName) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public T GetExportedValue<T>() { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public T GetExportedValue<T>(string? contractName) { throw null; }
+        public T? GetExportedValue<T>() { throw null; }
+        public T? GetExportedValue<T>(string? contractName) { throw null; }
         public System.Collections.Generic.IEnumerable<System.ComponentModel.Composition.Primitives.Export> GetExports(System.ComponentModel.Composition.Primitives.ImportDefinition definition) { throw null; }
         public System.Collections.Generic.IEnumerable<System.ComponentModel.Composition.Primitives.Export> GetExports(System.ComponentModel.Composition.Primitives.ImportDefinition definition, System.ComponentModel.Composition.Hosting.AtomicComposition? atomicComposition) { throw null; }
         public System.Collections.Generic.IEnumerable<System.Lazy<object, object>> GetExports(System.Type type, System.Type? metadataViewType, string? contractName) { throw null; }
index 380d202..9c66e18 100644 (file)
@@ -11,7 +11,7 @@ namespace System.ComponentModel.Composition
     internal struct CompositionResult<T>
     {
         private readonly IEnumerable<CompositionError>? _errors;
-        [AllowNull] private readonly T _value;
+        private readonly T? _value;
 
         public CompositionResult(T value)
             : this(value, null)
@@ -28,7 +28,7 @@ namespace System.ComponentModel.Composition
         {
         }
 
-        internal CompositionResult([AllowNull] T value, IEnumerable<CompositionError>? errors)
+        internal CompositionResult(T? value, IEnumerable<CompositionError>? errors)
         {
             _errors = errors;
             _value = value;
@@ -53,7 +53,7 @@ namespace System.ComponentModel.Composition
             {
                 ThrowOnErrors();
 
-                return _value;
+                return _value!;
             }
         }
 
index d20dac1..752d817 100644 (file)
@@ -295,7 +295,7 @@ namespace System.ComponentModel.Composition.Hosting
                 return _outerAtomicComposition.TryGetValueInternal<T>(key, localAtomicCompositionOnly, out value);
             }
 
-            value = default(T)!;
+            value = default;
             return false;
         }
 
index 12f0a6a..8ddbd6c 100644 (file)
@@ -473,8 +473,7 @@ namespace System.ComponentModel.Composition.Hosting
         ///     An error occurred during composition. <see cref="CompositionException.Errors"/> will
         ///     contain a collection of errors that occurred.
         /// </exception>
-        [return: MaybeNull]
-        public T GetExportedValue<T>()
+        public T? GetExportedValue<T>()
         {
             return GetExportedValue<T>((string?)null);
         }
@@ -524,8 +523,7 @@ namespace System.ComponentModel.Composition.Hosting
         ///     An error occurred during composition. <see cref="CompositionException.Errors"/> will
         ///     contain a collection of errors that occurred.
         /// </exception>
-        [return: MaybeNull]
-        public T GetExportedValue<T>(string? contractName)
+        public T? GetExportedValue<T>(string? contractName)
         {
             return GetExportedValueCore<T>(contractName, ImportCardinality.ExactlyOne);
         }
@@ -575,8 +573,7 @@ namespace System.ComponentModel.Composition.Hosting
         ///     An error occurred during composition. <see cref="CompositionException.Errors"/> will
         ///     contain a collection of errors that occurred.
         /// </exception>
-        [return: MaybeNull]
-        public T GetExportedValueOrDefault<T>()
+        public T? GetExportedValueOrDefault<T>()
         {
             return GetExportedValueOrDefault<T>((string?)null);
         }
@@ -626,8 +623,7 @@ namespace System.ComponentModel.Composition.Hosting
         ///     An error occurred during composition. <see cref="CompositionException.Errors"/> will
         ///     contain a collection of errors that occurred.
         /// </exception>
-        [return: MaybeNull]
-        public T GetExportedValueOrDefault<T>(string? contractName)
+        public T? GetExportedValueOrDefault<T>(string? contractName)
         {
             return GetExportedValueCore<T>(contractName, ImportCardinality.ZeroOrOne);
         }
@@ -724,8 +720,7 @@ namespace System.ComponentModel.Composition.Hosting
             return result;
         }
 
-        [return: MaybeNull]
-        private T GetExportedValueCore<T>(string? contractName, ImportCardinality cardinality)
+        private T? GetExportedValueCore<T>(string? contractName, ImportCardinality cardinality)
         {
             if (!cardinality.IsAtMostOne())
             {
@@ -734,7 +729,7 @@ namespace System.ComponentModel.Composition.Hosting
 
             Export? export = GetExportsCore(typeof(T), (Type?)null, contractName, cardinality).SingleOrDefault();
 
-            return (export != null) ? ExportServices.GetCastedExportedValue<T>(export) : default(T)!;
+            return (export != null) ? ExportServices.GetCastedExportedValue<T>(export) : default;
         }
 
         private IEnumerable<Lazy<T>> GetExportsCore<T>(string? contractName)
index b64f990..25d362e 100644 (file)
@@ -26,27 +26,19 @@ namespace System.ComponentModel.Composition
             return new ReadOnlyDictionary<string, object?>(metadata);
         }
 
-        [return: MaybeNull]
-        public static T GetValue<T>(this IDictionary<string, object?> metadata, string key)
+        public static T? GetValue<T>(this IDictionary<string, object?> metadata, string key)
         {
             if (metadata == null)
             {
                 throw new ArgumentNullException(nameof(metadata));
             }
 
-            if (!metadata.TryGetValue(key, out object? untypedValue))
+            if (metadata.TryGetValue(key, out object? untypedValue) && untypedValue is T t)
             {
-                return default(T)!;
+                return t;
             }
 
-            if (untypedValue is T)
-            {
-                return (T)untypedValue;
-            }
-            else
-            {
-                return default(T)!;
-            }
+            return default;
         }
     }
 }
index 983f25d..14124ff 100644 (file)
@@ -103,7 +103,7 @@ namespace System.ComponentModel.Composition.ReflectionModel
                 {
                     throw new Exception(SR.Diagnostic_InternalExceptionMessage);
                 }
-                return MemberType.GetHashCode() ^ _accessors[0]!.GetHashCode(); // TODO-NULLABLE https://github.com/dotnet/roslyn/issues/34644
+                return MemberType.GetHashCode() ^ _accessors[0]!.GetHashCode(); // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
             }
         }
 
index 24cdb3d..d9df3c0 100644 (file)
@@ -403,21 +403,15 @@ namespace System.Data
     }
     public static partial class DataRowExtensions
     {
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static T Field<T>(this System.Data.DataRow row, System.Data.DataColumn column) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static T Field<T>(this System.Data.DataRow row, System.Data.DataColumn column, System.Data.DataRowVersion version) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static T Field<T>(this System.Data.DataRow row, int columnIndex) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static T Field<T>(this System.Data.DataRow row, int columnIndex, System.Data.DataRowVersion version) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static T Field<T>(this System.Data.DataRow row, string columnName) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static T Field<T>(this System.Data.DataRow row, string columnName, System.Data.DataRowVersion version) { throw null; }
-        public static void SetField<T>(this System.Data.DataRow row, System.Data.DataColumn column, [System.Diagnostics.CodeAnalysis.AllowNullAttribute] T value) { }
-        public static void SetField<T>(this System.Data.DataRow row, int columnIndex, [System.Diagnostics.CodeAnalysis.AllowNullAttribute] T value) { }
-        public static void SetField<T>(this System.Data.DataRow row, string columnName, [System.Diagnostics.CodeAnalysis.AllowNullAttribute] T value) { }
+        public static T? Field<T>(this System.Data.DataRow row, System.Data.DataColumn column) { throw null; }
+        public static T? Field<T>(this System.Data.DataRow row, System.Data.DataColumn column, System.Data.DataRowVersion version) { throw null; }
+        public static T? Field<T>(this System.Data.DataRow row, int columnIndex) { throw null; }
+        public static T? Field<T>(this System.Data.DataRow row, int columnIndex, System.Data.DataRowVersion version) { throw null; }
+        public static T? Field<T>(this System.Data.DataRow row, string columnName) { throw null; }
+        public static T? Field<T>(this System.Data.DataRow row, string columnName, System.Data.DataRowVersion version) { throw null; }
+        public static void SetField<T>(this System.Data.DataRow row, System.Data.DataColumn column, T? value) { }
+        public static void SetField<T>(this System.Data.DataRow row, int columnIndex, T? value) { }
+        public static void SetField<T>(this System.Data.DataRow row, string columnName, T? value) { }
     }
     [System.FlagsAttribute]
     public enum DataRowState
@@ -1057,8 +1051,8 @@ namespace System.Data
         [System.ComponentModel.BrowsableAttribute(false)]
         public bool IsSynchronized { get { throw null; } }
         public virtual System.Data.DataViewSetting this[System.Data.DataTable table] { get { throw null; } set { } }
-        [System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public virtual System.Data.DataViewSetting this[int index] { get { throw null; } set { } }
+        [System.Diagnostics.CodeAnalysis.DisallowNullAttribute]
+        public virtual System.Data.DataViewSetting? this[int index] { get { throw null; } set { } }
         public virtual System.Data.DataViewSetting? this[string tableName] { get { throw null; } }
         [System.ComponentModel.BrowsableAttribute(false)]
         public object SyncRoot { get { throw null; } }
@@ -1563,8 +1557,7 @@ namespace System.Data
     public static partial class TypedTableBaseExtensions
     {
         public static System.Data.EnumerableRowCollection<TRow> AsEnumerable<TRow>(this System.Data.TypedTableBase<TRow> source) where TRow : System.Data.DataRow { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TRow ElementAtOrDefault<TRow>(this System.Data.TypedTableBase<TRow> source, int index) where TRow : System.Data.DataRow { throw null; }
+        public static TRow? ElementAtOrDefault<TRow>(this System.Data.TypedTableBase<TRow> source, int index) where TRow : System.Data.DataRow { throw null; }
         public static System.Data.OrderedEnumerableRowCollection<TRow> OrderByDescending<TRow, TKey>(this System.Data.TypedTableBase<TRow> source, System.Func<TRow, TKey> keySelector) where TRow : System.Data.DataRow { throw null; }
         public static System.Data.OrderedEnumerableRowCollection<TRow> OrderByDescending<TRow, TKey>(this System.Data.TypedTableBase<TRow> source, System.Func<TRow, TKey> keySelector, System.Collections.Generic.IComparer<TKey> comparer) where TRow : System.Data.DataRow { throw null; }
         public static System.Data.OrderedEnumerableRowCollection<TRow> OrderBy<TRow, TKey>(this System.Data.TypedTableBase<TRow> source, System.Func<TRow, TKey> keySelector) where TRow : System.Data.DataRow { throw null; }
index 97e0faf..8b85144 100644 (file)
@@ -30,7 +30,7 @@ namespace System.Data.Common
                 BaseSchemaName = GetDbColumnValue<string?>(SchemaTableColumn.BaseSchemaName);
                 BaseServerName = GetDbColumnValue<string?>(SchemaTableOptionalColumn.BaseServerName);
                 BaseTableName = GetDbColumnValue<string?>(SchemaTableColumn.BaseTableName);
-                ColumnName = GetDbColumnValue<string>(SchemaTableColumn.ColumnName);
+                ColumnName = GetDbColumnValue<string>(SchemaTableColumn.ColumnName)!;
                 ColumnOrdinal = GetDbColumnValue<int?>(SchemaTableColumn.ColumnOrdinal);
                 ColumnSize = GetDbColumnValue<int?>(SchemaTableColumn.ColumnSize);
                 IsAliased = GetDbColumnValue<bool?>(SchemaTableColumn.IsAliased);
@@ -49,8 +49,7 @@ namespace System.Data.Common
                 DataTypeName = GetDbColumnValue<string?>("DataTypeName");
             }
 
-            // The following may return null, but local methods can't be annotated for that yet ([MaybeNull])
-            private T GetDbColumnValue<T>(string columnName) => _schemaColumns.Contains(columnName) && _schemaRow[columnName] is T value ? value : default!;
+            private T? GetDbColumnValue<T>(string columnName) => _schemaColumns.Contains(columnName) && _schemaRow[columnName] is T value ? value : default;
         }
 
         public static ReadOnlyCollection<DbColumn> GetColumnSchema(this DbDataReader reader)
index 2c9fa58..e469f32 100644 (file)
@@ -12,7 +12,7 @@ namespace System.Data.Common
 {
     internal sealed class SqlInt64Storage : DataStorage
     {
-        private SqlInt64[] _values = default!;
+        private SqlInt64[] _values = default!; // Late-initialized
 
         public SqlInt64Storage(DataColumn column)
         : base(column, typeof(SqlInt64), SqlInt64.Null, SqlInt64.Null, StorageType.SqlInt64)
index afa65a3..3ebbdc1 100644 (file)
@@ -19,8 +19,7 @@ namespace System.Data
         /// <param name="row">The input DataRow</param>
         /// <param name="columnName">The input column name specifying which row value to retrieve.</param>
         /// <returns>The DataRow value for the column specified.</returns>
-        [return: MaybeNull]
-        public static T Field<T>(this DataRow row, string columnName)
+        public static T? Field<T>(this DataRow row, string columnName)
         {
             DataSetUtil.CheckArgumentNull(row, nameof(row));
             return UnboxT<T>.s_unbox(row[columnName]);
@@ -35,8 +34,7 @@ namespace System.Data
         /// <param name="row">The input DataRow</param>
         /// <param name="column">The input DataColumn specifying which row value to retrieve.</param>
         /// <returns>The DataRow value for the column specified.</returns>
-        [return: MaybeNull]
-        public static T Field<T>(this DataRow row, DataColumn column)
+        public static T? Field<T>(this DataRow row, DataColumn column)
         {
             DataSetUtil.CheckArgumentNull(row, nameof(row));
             return UnboxT<T>.s_unbox(row[column]);
@@ -51,8 +49,7 @@ namespace System.Data
         /// <param name="row">The input DataRow</param>
         /// <param name="columnIndex">The input ordinal specifying which row value to retrieve.</param>
         /// <returns>The DataRow value for the column specified.</returns>
-        [return: MaybeNull]
-        public static T Field<T>(this DataRow row, int columnIndex)
+        public static T? Field<T>(this DataRow row, int columnIndex)
         {
             DataSetUtil.CheckArgumentNull(row, nameof(row));
             return UnboxT<T>.s_unbox(row[columnIndex]);
@@ -68,8 +65,7 @@ namespace System.Data
         /// <param name="columnIndex">The input ordinal specifying which row value to retrieve.</param>
         /// <param name="version">The DataRow version for which row value to retrieve.</param>
         /// <returns>The DataRow value for the column specified.</returns>
-        [return: MaybeNull]
-        public static T Field<T>(this DataRow row, int columnIndex, DataRowVersion version)
+        public static T? Field<T>(this DataRow row, int columnIndex, DataRowVersion version)
         {
             DataSetUtil.CheckArgumentNull(row, nameof(row));
             return UnboxT<T>.s_unbox(row[columnIndex, version]);
@@ -85,8 +81,7 @@ namespace System.Data
         /// <param name="columnName">The input column name specifying which row value to retrieve.</param>
         /// <param name="version">The DataRow version for which row value to retrieve.</param>
         /// <returns>The DataRow value for the column specified.</returns>
-        [return: MaybeNull]
-        public static T Field<T>(this DataRow row, string columnName, DataRowVersion version)
+        public static T? Field<T>(this DataRow row, string columnName, DataRowVersion version)
         {
             DataSetUtil.CheckArgumentNull(row, nameof(row));
             return UnboxT<T>.s_unbox(row[columnName, version]);
@@ -102,8 +97,7 @@ namespace System.Data
         /// <param name="column">The input DataColumn specifying which row value to retrieve.</param>
         /// <param name="version">The DataRow version for which row value to retrieve.</param>
         /// <returns>The DataRow value for the column specified.</returns>
-        [return: MaybeNull]
-        public static T Field<T>(this DataRow row, DataColumn column, DataRowVersion version)
+        public static T? Field<T>(this DataRow row, DataColumn column, DataRowVersion version)
         {
             DataSetUtil.CheckArgumentNull(row, nameof(row));
             return UnboxT<T>.s_unbox(row[column, version]);
@@ -115,7 +109,7 @@ namespace System.Data
         /// <param name="row">The input DataRow.</param>
         /// <param name="columnIndex">The input ordinal specifying which row value to set.</param>
         /// <param name="value">The new row value for the specified column.</param>
-        public static void SetField<T>(this DataRow row, int columnIndex, [AllowNull] T value)
+        public static void SetField<T>(this DataRow row, int columnIndex, T? value)
         {
             DataSetUtil.CheckArgumentNull(row, nameof(row));
             row[columnIndex] = (object?)value ?? DBNull.Value;
@@ -127,7 +121,7 @@ namespace System.Data
         /// <param name="row">The input DataRow.</param>
         /// <param name="columnName">The input column name specifying which row value to retrieve.</param>
         /// <param name="value">The new row value for the specified column.</param>
-        public static void SetField<T>(this DataRow row, string columnName, [AllowNull] T value)
+        public static void SetField<T>(this DataRow row, string columnName, T? value)
         {
             DataSetUtil.CheckArgumentNull(row, nameof(row));
             row[columnName] = (object?)value ?? DBNull.Value;
@@ -139,7 +133,7 @@ namespace System.Data
         /// <param name="row">The input DataRow.</param>
         /// <param name="column">The input DataColumn specifying which row value to retrieve.</param>
         /// <param name="value">The new row value for the specified column.</param>
-        public static void SetField<T>(this DataRow row, DataColumn column, [AllowNull] T value)
+        public static void SetField<T>(this DataRow row, DataColumn column, T? value)
         {
             DataSetUtil.CheckArgumentNull(row, nameof(row));
             row[column] = (object?)value ?? DBNull.Value;
@@ -147,9 +141,9 @@ namespace System.Data
 
         private static class UnboxT<T>
         {
-            internal static readonly Converter<object, T> s_unbox = Create();
+            internal static readonly Converter<object, T?> s_unbox = Create();
 
-            private static Converter<object, T> Create()
+            private static Converter<object, T?> Create()
             {
                 if (typeof(T).IsValueType)
                 {
@@ -165,8 +159,7 @@ namespace System.Data
                 return ReferenceField;
             }
 
-            [return: MaybeNull]
-            private static T ReferenceField(object value)
+            private static T? ReferenceField(object value)
                 => value == DBNull.Value ? default : (T)value;
 
             private static T ValueField(object value)
@@ -174,7 +167,6 @@ namespace System.Data
                     ? throw DataSetUtil.InvalidCast(SR.Format(SR.DataSetLinq_NonNullableCast, typeof(T)))
                     : (T)value;
 
-            [return: MaybeNull]
             private static Nullable<TElem> NullableField<TElem>(object value) where TElem : struct
                 => value == DBNull.Value ? default : new Nullable<TElem>((TElem)value);
         }
index dc059c1..62b9fb6 100644 (file)
@@ -84,8 +84,8 @@ namespace System.Data
             }
         }
 
-        [MaybeNull]
-        public virtual DataViewSetting this[int index]
+        [DisallowNull]
+        public virtual DataViewSetting? this[int index]
         {
             get
             {
index 4c40476..a5f75b0 100644 (file)
@@ -96,8 +96,8 @@ namespace System.Data
         internal const int DefaultPageSize = 32; /* 512 = 2^9 32 million nodes*/
         internal const int NIL = 0;                  // 0th page, 0th slot for each tree till CLR static & generics issue is fixed
 
-        private TreePage?[] _pageTable = default!; // initial size 4, then doubles (grows) - it never shrinks. Late-initialized to non-null in InitTree.
-        private int[] _pageTableMap = default!; // Late-initialized to non-null in InitTree
+        private TreePage?[] _pageTable; // initial size 4, then doubles (grows) - it never shrinks.
+        private int[] _pageTableMap;
         private int _inUsePageCount;    // contains count of allocated pages per tree, its <= the capacity of  pageTable
         private int _nextFreePageLine;   // used for keeping track of position of last used free page in pageTable
         public int root;
@@ -107,8 +107,8 @@ namespace System.Data
         private int _inUseSatelliteTreeCount; // total number of satellite associated with this tree.
         private readonly TreeAccessMethod _accessMethod;
 
-        protected abstract int CompareNode([AllowNull] K record1, [AllowNull] K record2);
-        protected abstract int CompareSateliteTreeNode([AllowNull] K record1, [AllowNull] K record2);
+        protected abstract int CompareNode(K? record1, K? record2);
+        protected abstract int CompareSateliteTreeNode(K? record1, K? record2);
 
         protected RBTree(TreeAccessMethod accessMethod)
         {
@@ -116,6 +116,8 @@ namespace System.Data
             InitTree();
         }
 
+        [MemberNotNull(nameof(_pageTable))]
+        [MemberNotNull(nameof(_pageTableMap))]
         private void InitTree()
         {
             root = NIL;
@@ -337,7 +339,7 @@ namespace System.Data
          * Use bitmap associated with page to allocate a slot.
          * mark the slot as used and return its index.
          */
-        private int GetNewNode([AllowNull] K key)
+        private int GetNewNode(K? key)
         {
             // find page with free slots, if none, allocate a new page
             TreePage? page = null;
@@ -1205,7 +1207,7 @@ namespace System.Data
             return root_id;
         }
 
-        private int SearchSubTree(int root_id, [AllowNull] K key)
+        private int SearchSubTree(int root_id, K? key)
         {
             if (root_id != NIL && _accessMethod != TreeAccessMethod.KEY_SEARCH_AND_INDEX)
             {
@@ -1556,7 +1558,7 @@ namespace System.Data
 
         // Begin: List of methods for making it easy to work with ArrayList
 
-        public int Add([AllowNull] K item) //Insert (int record)
+        public int Add(K? item) //Insert (int record)
         {
             int nodeId = GetNewNode(item);
             RBInsert(NIL, nodeId, NIL, -1, false);
@@ -1875,8 +1877,7 @@ namespace System.Data
             internal int _parentId;
             internal int _nextId;      // multiple records associated with same key
             internal int _subTreeSize;     // number of nodes in subtree rooted at the current node
-            [AllowNull, MaybeNull]
-            internal K _keyOfNode;
+            internal K? _keyOfNode;
             internal NodeColor _nodeColor;
         }
 
@@ -2042,8 +2043,7 @@ namespace System.Data
             private readonly RBTree<K> _tree;
             private readonly int _version;
             private int _index, _mainTreeNodeId;
-            [AllowNull, MaybeNull]
-            private K _current;
+            private K? _current;
 
             internal RBTreeEnumerator(RBTree<K> tree)
             {
index 2889e24..c5304d9 100644 (file)
@@ -92,7 +92,7 @@ namespace System.Data
         /// Note: Comparison is done in the order it was Added.
         /// </summary>
         /// <returns>Comparison result of the combined Sort comparer expression</returns>
-        public int Compare([AllowNull] List<object> a, [AllowNull] List<object> b)
+        public int Compare(List<object>? a, List<object>? b)
         {
             Debug.Assert(a != null && b != null && a.Count == Count);
 
index 9153511..ccdd593 100644 (file)
@@ -92,8 +92,7 @@ namespace System.Data
             return new EnumerableRowCollection<TRow>(source as DataTable);
         }
 
-        [return: MaybeNull]
-        public static TRow ElementAtOrDefault<TRow>(this TypedTableBase<TRow> source, int index) where TRow : DataRow
+        public static TRow? ElementAtOrDefault<TRow>(this TypedTableBase<TRow> source, int index) where TRow : DataRow
         {
             if ((index >= 0) && (index < source.Rows.Count))
             {
index 959cebb..0d5f495 100644 (file)
@@ -6,6 +6,7 @@ using System.ComponentModel;
 using System.Data.SqlTypes;
 using System.Data.Common;
 using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
 using System.Globalization;
 using System.IO;
 using System.Text;
@@ -2250,7 +2251,7 @@ namespace System.Data
         internal XmlWriter _xmlw = default!; // Late-initialized
         private bool _fBefore;
         private bool _fErrors;
-        internal Hashtable _rowsOrder = default!; // Always initialized in DoAssignments
+        internal Hashtable _rowsOrder;
         private readonly ArrayList _tables = new ArrayList();
         private readonly bool _writeHierarchy;
 
@@ -2297,7 +2298,7 @@ namespace System.Data
             }
         }
 
-
+        [MemberNotNull(nameof(_rowsOrder))]
         private void DoAssignments(ArrayList tables)
         {
             int rows = 0;
index 8cf24c8..02e5266 100644 (file)
@@ -133,8 +133,7 @@ namespace System.Data.ProviderBase
             }
         }
 
-        [return: MaybeNull]
-        internal T FindItem<T>(int tag, Func<T, bool> filterMethod) where T : class
+        internal T? FindItem<T>(int tag, Func<T, bool> filterMethod) where T : class
         {
             bool lockObtained = false;
             try
index 029f9cd..95bb53f 100644 (file)
@@ -25,7 +25,7 @@ namespace System.IO.Enumeration
         private Queue<string>? _pending;
 
         private Interop.Sys.DirectoryEntry _entry;
-        private TResult _current = default!;
+        private TResult? _current;
 
         // Used for creating full paths
         private char[]? _pathBuffer;
index 69084ac..32fd206 100644 (file)
@@ -31,7 +31,7 @@ namespace System.IO.Enumeration
         private readonly object _lock = new object();
 
         private Interop.NtDll.FILE_FULL_DIR_INFORMATION* _entry;
-        private TResult _current = default!;
+        private TResult? _current;
 
         private IntPtr _buffer;
         private int _bufferLength;
index c3d4a97..b5168eb 100644 (file)
@@ -69,7 +69,7 @@ namespace System.IO.Enumeration
         /// <param name="error">The native error code.</param>
         protected virtual bool ContinueOnError(int error) => false;
 
-        public TResult Current => _current;
+        public TResult Current => _current!;
 
         object? IEnumerator.Current => Current;
 
index 49c4b4c..09bf15d 100644 (file)
@@ -14,18 +14,14 @@ namespace System.IO
     {
         private readonly int _threadId;
         internal int state;
-        [MaybeNull, AllowNull]
-        internal TSource current = default;
+        internal TSource? current;
 
         public Iterator()
         {
             _threadId = Environment.CurrentManagedThreadId;
         }
 
-        public TSource Current
-        {
-            get { return current!; }
-        }
+        public TSource Current => current!;
 
         protected abstract Iterator<TSource> Clone();
 
@@ -37,7 +33,7 @@ namespace System.IO
 
         protected virtual void Dispose(bool disposing)
         {
-            current = default(TSource)!;
+            current = default;
             state = -1;
         }
 
index 50b6cf2..9c9a3bd 100644 (file)
@@ -77,7 +77,7 @@ namespace System.Dynamic.Utils
                 return true;
             }
 
-            value = default(TValue)!;
+            value = default;
             return false;
         }
 
index 7365e10..c647214 100644 (file)
@@ -286,7 +286,7 @@ namespace System.Linq.Expressions.Compiler
             Debug.Assert(_method is DynamicMethod);
 #endif
             {
-                return Expression.Field(Expression.Constant(new StrongBox<T>(default(T)!)), "Value");
+                return Expression.Field(Expression.Constant(new StrongBox<T>()), "Value");
             }
 #if FEATURE_COMPILE_TO_METHODBUILDER
             else
index 6185577..7b757e9 100644 (file)
@@ -192,7 +192,7 @@ namespace System.Linq.Expressions.Interpreter
                     }
                 }
             }
-            value = default(TValue)!;
+            value = default;
             return false;
         }
 
index 837bf53..e8ab5c0 100644 (file)
@@ -61,8 +61,7 @@ namespace System.Linq
         public static System.Linq.ParallelQuery<TSource> DefaultIfEmpty<TSource>(this System.Linq.ParallelQuery<TSource> source, TSource defaultValue) { throw null; }
         public static System.Linq.ParallelQuery<TSource> Distinct<TSource>(this System.Linq.ParallelQuery<TSource> source) { throw null; }
         public static System.Linq.ParallelQuery<TSource> Distinct<TSource>(this System.Linq.ParallelQuery<TSource> source, System.Collections.Generic.IEqualityComparer<TSource>? comparer) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TSource ElementAtOrDefault<TSource>(this System.Linq.ParallelQuery<TSource> source, int index) { throw null; }
+        public static TSource? ElementAtOrDefault<TSource>(this System.Linq.ParallelQuery<TSource> source, int index) { throw null; }
         public static TSource ElementAt<TSource>(this System.Linq.ParallelQuery<TSource> source, int index) { throw null; }
         public static System.Linq.ParallelQuery<TResult> Empty<TResult>() { throw null; }
         [System.ObsoleteAttribute("The second data source of a binary operator must be of type System.Linq.ParallelQuery<T> rather than System.Collections.Generic.IEnumerable<T>. To fix this problem, use the AsParallel() extension method to convert the right data source to System.Linq.ParallelQuery<T>.")]
@@ -71,10 +70,8 @@ namespace System.Linq
         public static System.Linq.ParallelQuery<TSource> Except<TSource>(this System.Linq.ParallelQuery<TSource> first, System.Collections.Generic.IEnumerable<TSource> second, System.Collections.Generic.IEqualityComparer<TSource>? comparer) { throw null; }
         public static System.Linq.ParallelQuery<TSource> Except<TSource>(this System.Linq.ParallelQuery<TSource> first, System.Linq.ParallelQuery<TSource> second) { throw null; }
         public static System.Linq.ParallelQuery<TSource> Except<TSource>(this System.Linq.ParallelQuery<TSource> first, System.Linq.ParallelQuery<TSource> second, System.Collections.Generic.IEqualityComparer<TSource>? comparer) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TSource FirstOrDefault<TSource>(this System.Linq.ParallelQuery<TSource> source) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TSource FirstOrDefault<TSource>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, bool> predicate) { throw null; }
+        public static TSource? FirstOrDefault<TSource>(this System.Linq.ParallelQuery<TSource> source) { throw null; }
+        public static TSource? FirstOrDefault<TSource>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, bool> predicate) { throw null; }
         public static TSource First<TSource>(this System.Linq.ParallelQuery<TSource> source) { throw null; }
         public static TSource First<TSource>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, bool> predicate) { throw null; }
         public static void ForAll<TSource>(this System.Linq.ParallelQuery<TSource> source, System.Action<TSource> action) { }
@@ -104,10 +101,8 @@ namespace System.Linq
         public static System.Linq.ParallelQuery<TResult> Join<TOuter, TInner, TKey, TResult>(this System.Linq.ParallelQuery<TOuter> outer, System.Collections.Generic.IEnumerable<TInner> inner, System.Func<TOuter, TKey> outerKeySelector, System.Func<TInner, TKey> innerKeySelector, System.Func<TOuter, TInner, TResult> resultSelector, System.Collections.Generic.IEqualityComparer<TKey>? comparer) { throw null; }
         public static System.Linq.ParallelQuery<TResult> Join<TOuter, TInner, TKey, TResult>(this System.Linq.ParallelQuery<TOuter> outer, System.Linq.ParallelQuery<TInner> inner, System.Func<TOuter, TKey> outerKeySelector, System.Func<TInner, TKey> innerKeySelector, System.Func<TOuter, TInner, TResult> resultSelector) { throw null; }
         public static System.Linq.ParallelQuery<TResult> Join<TOuter, TInner, TKey, TResult>(this System.Linq.ParallelQuery<TOuter> outer, System.Linq.ParallelQuery<TInner> inner, System.Func<TOuter, TKey> outerKeySelector, System.Func<TInner, TKey> innerKeySelector, System.Func<TOuter, TInner, TResult> resultSelector, System.Collections.Generic.IEqualityComparer<TKey>? comparer) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TSource LastOrDefault<TSource>(this System.Linq.ParallelQuery<TSource> source) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TSource LastOrDefault<TSource>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, bool> predicate) { throw null; }
+        public static TSource? LastOrDefault<TSource>(this System.Linq.ParallelQuery<TSource> source) { throw null; }
+        public static TSource? LastOrDefault<TSource>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, bool> predicate) { throw null; }
         public static TSource Last<TSource>(this System.Linq.ParallelQuery<TSource> source) { throw null; }
         public static TSource Last<TSource>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, bool> predicate) { throw null; }
         public static long LongCount<TSource>(this System.Linq.ParallelQuery<TSource> source) { throw null; }
@@ -122,8 +117,7 @@ namespace System.Linq
         public static long? Max(this System.Linq.ParallelQuery<long?> source) { throw null; }
         public static float? Max(this System.Linq.ParallelQuery<float?> source) { throw null; }
         public static float Max(this System.Linq.ParallelQuery<float> source) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TSource Max<TSource>(this System.Linq.ParallelQuery<TSource> source) { throw null; }
+        public static TSource? Max<TSource>(this System.Linq.ParallelQuery<TSource> source) { throw null; }
         public static decimal Max<TSource>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, decimal> selector) { throw null; }
         public static double Max<TSource>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, double> selector) { throw null; }
         public static int Max<TSource>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, int> selector) { throw null; }
@@ -134,8 +128,7 @@ namespace System.Linq
         public static long? Max<TSource>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, long?> selector) { throw null; }
         public static float? Max<TSource>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, float?> selector) { throw null; }
         public static float Max<TSource>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, float> selector) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TResult Max<TSource, TResult>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, TResult> selector) { throw null; }
+        public static TResult? Max<TSource, TResult>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, TResult> selector) { throw null; }
         public static decimal Min(this System.Linq.ParallelQuery<decimal> source) { throw null; }
         public static double Min(this System.Linq.ParallelQuery<double> source) { throw null; }
         public static int Min(this System.Linq.ParallelQuery<int> source) { throw null; }
@@ -146,8 +139,7 @@ namespace System.Linq
         public static long? Min(this System.Linq.ParallelQuery<long?> source) { throw null; }
         public static float? Min(this System.Linq.ParallelQuery<float?> source) { throw null; }
         public static float Min(this System.Linq.ParallelQuery<float> source) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TSource Min<TSource>(this System.Linq.ParallelQuery<TSource> source) { throw null; }
+        public static TSource? Min<TSource>(this System.Linq.ParallelQuery<TSource> source) { throw null; }
         public static decimal Min<TSource>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, decimal> selector) { throw null; }
         public static double Min<TSource>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, double> selector) { throw null; }
         public static int Min<TSource>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, int> selector) { throw null; }
@@ -158,8 +150,7 @@ namespace System.Linq
         public static long? Min<TSource>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, long?> selector) { throw null; }
         public static float? Min<TSource>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, float?> selector) { throw null; }
         public static float Min<TSource>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, float> selector) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TResult Min<TSource, TResult>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, TResult> selector) { throw null; }
+        public static TResult? Min<TSource, TResult>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, TResult> selector) { throw null; }
         public static System.Linq.ParallelQuery<TResult> OfType<TResult>(this System.Linq.ParallelQuery source) { throw null; }
         public static System.Linq.OrderedParallelQuery<TSource> OrderByDescending<TSource, TKey>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, TKey> keySelector) { throw null; }
         public static System.Linq.OrderedParallelQuery<TSource> OrderByDescending<TSource, TKey>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, TKey> keySelector, System.Collections.Generic.IComparer<TKey>? comparer) { throw null; }
@@ -180,10 +171,8 @@ namespace System.Linq
         public static bool SequenceEqual<TSource>(this System.Linq.ParallelQuery<TSource> first, System.Collections.Generic.IEnumerable<TSource> second, System.Collections.Generic.IEqualityComparer<TSource>? comparer) { throw null; }
         public static bool SequenceEqual<TSource>(this System.Linq.ParallelQuery<TSource> first, System.Linq.ParallelQuery<TSource> second) { throw null; }
         public static bool SequenceEqual<TSource>(this System.Linq.ParallelQuery<TSource> first, System.Linq.ParallelQuery<TSource> second, System.Collections.Generic.IEqualityComparer<TSource>? comparer) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TSource SingleOrDefault<TSource>(this System.Linq.ParallelQuery<TSource> source) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TSource SingleOrDefault<TSource>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, bool> predicate) { throw null; }
+        public static TSource? SingleOrDefault<TSource>(this System.Linq.ParallelQuery<TSource> source) { throw null; }
+        public static TSource? SingleOrDefault<TSource>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, bool> predicate) { throw null; }
         public static TSource Single<TSource>(this System.Linq.ParallelQuery<TSource> source) { throw null; }
         public static TSource Single<TSource>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, bool> predicate) { throw null; }
         public static System.Linq.ParallelQuery<TSource> SkipWhile<TSource>(this System.Linq.ParallelQuery<TSource> source, System.Func<TSource, bool> predicate) { throw null; }
index 7a5fa88..746c1a5 100644 (file)
@@ -20,8 +20,7 @@ namespace System.Linq
         // Helper method to find the minimum or maximum element in the source.
         //
 
-        [return: MaybeNull]
-        private static T Reduce(IEnumerable<T> source, int sign)
+        private static T? Reduce(IEnumerable<T> source, int sign)
         {
             Debug.Assert(source != null);
             Debug.Assert(sign == -1 || sign == 1);
@@ -41,8 +40,7 @@ namespace System.Linq
         // Helper method to find the minimum element in the source.
         //
 
-        [return: MaybeNull]
-        internal static T ReduceMin(IEnumerable<T> source)
+        internal static T? ReduceMin(IEnumerable<T> source)
         {
             return Reduce(source, -1);
         }
@@ -51,8 +49,7 @@ namespace System.Linq
         // Helper method to find the maximum element in the source.
         //
 
-        [return: MaybeNull]
-        internal static T ReduceMax(IEnumerable<T> source)
+        internal static T? ReduceMax(IEnumerable<T> source)
         {
             return Reduce(source, 1);
         }
index 4ad52ac..d4e21e1 100644 (file)
@@ -56,7 +56,7 @@ namespace System.Linq.Parallel
         }
     }
 
-    internal class EmptyEnumerator<T> : QueryOperatorEnumerator<T, int>, IEnumerator<T>
+    internal sealed class EmptyEnumerator<T> : QueryOperatorEnumerator<T, int>, IEnumerator<T>
     {
         internal override bool MoveNext([MaybeNullWhen(false), AllowNull] ref T currentElement, ref int currentKey)
         {
index 746887d..5449425 100644 (file)
@@ -133,7 +133,7 @@ namespace System.Linq.Parallel
         {
             internal int hashCode;
             internal int next;
-            [MaybeNull, AllowNull] internal TElement value;
+            internal TElement? value;
         }
     }
 }
index e741ac5..3432a14 100644 (file)
@@ -32,7 +32,7 @@ namespace System.Linq.Parallel
         private IntValueEvent? _consumerEvent; // The consumer event.
         private readonly bool[] _done;       // Tracks which channels are done.
         private int _channelIndex;  // The next channel from which we'll dequeue.
-        [MaybeNull, AllowNull] private T _currentElement = default;  // The remembered element from the previous MoveNext.
+        private T? _currentElement;  // The remembered element from the previous MoveNext.
 
         //-----------------------------------------------------------------------------------
         // Allocates a new enumerator over a set of one-to-one channels.
index bb0c023..ba10ef6 100644 (file)
@@ -24,7 +24,7 @@ namespace System.Linq.Parallel
     {
         private readonly SynchronousChannel<T>[] _channels; // The channel array we will enumerate, from left-to-right.
         private int _channelIndex; // The current channel index. This moves through the array as we enumerate.
-        private T _currentElement = default!; // The last element remembered during enumeration.
+        private T? _currentElement; // The last element remembered during enumeration.
 
         //-----------------------------------------------------------------------------------
         // Instantiates a new enumerator for a set of channels.
@@ -61,7 +61,7 @@ namespace System.Linq.Parallel
                     throw new InvalidOperationException(SR.PLINQ_CommonEnumerator_Current_NotStarted);
                 }
 
-                return _currentElement;
+                return _currentElement!;
             }
         }
 
index faa7e1a..f6b4b72 100644 (file)
@@ -296,10 +296,8 @@ namespace System.Linq.Parallel
 
     internal struct ConcatKey<TLeftKey, TRightKey>
     {
-        [MaybeNull, AllowNull]
-        private readonly TLeftKey _leftKey;
-        [MaybeNull, AllowNull]
-        private readonly TRightKey _rightKey;
+        private readonly TLeftKey? _leftKey;
+        private readonly TRightKey? _rightKey;
         private readonly bool _isLeft;
 
         private ConcatKey([AllowNull] TLeftKey leftKey, [AllowNull] TRightKey rightKey, bool isLeft)
index f949814..229b524 100644 (file)
@@ -26,7 +26,7 @@ namespace System.Linq.Parallel
             _comparer = comparer;
         }
 
-        public int Compare([AllowNull] T x, [AllowNull] T y)
+        public int Compare(T? x, T? y)
         {
             return _comparer.Compare(y, x);
         }
index 17a378e..f4f870c 100644 (file)
@@ -2659,8 +2659,7 @@ namespace System.Linq
         /// <exception cref="System.OperationCanceledException">
         /// The query was canceled.
         /// </exception>
-        [return: MaybeNull]
-        public static TSource Min<TSource>(this ParallelQuery<TSource> source)
+        public static TSource? Min<TSource>(this ParallelQuery<TSource> source)
         {
             if (source == null) throw new ArgumentNullException(nameof(source));
             return AggregationMinMaxHelpers<TSource>.ReduceMin(source);
@@ -2922,8 +2921,7 @@ namespace System.Linq
         /// <exception cref="System.OperationCanceledException">
         /// The query was canceled.
         /// </exception>
-        [return: MaybeNull]
-        public static TResult Min<TSource, TResult>(this ParallelQuery<TSource> source, Func<TSource, TResult> selector)
+        public static TResult? Min<TSource, TResult>(this ParallelQuery<TSource> source, Func<TSource, TResult> selector)
         {
             return source.Select<TSource, TResult>(selector).Min<TResult>();
         }
@@ -3164,8 +3162,7 @@ namespace System.Linq
         /// <exception cref="System.OperationCanceledException">
         /// The query was canceled.
         /// </exception>
-        [return: MaybeNull]
-        public static TSource Max<TSource>(this ParallelQuery<TSource> source)
+        public static TSource? Max<TSource>(this ParallelQuery<TSource> source)
         {
             if (source == null) throw new ArgumentNullException(nameof(source));
             return AggregationMinMaxHelpers<TSource>.ReduceMax(source);
@@ -3427,8 +3424,7 @@ namespace System.Linq
         /// <exception cref="System.OperationCanceledException">
         /// The query was canceled.
         /// </exception>
-        [return: MaybeNull]
-        public static TResult Max<TSource, TResult>(this ParallelQuery<TSource> source, Func<TSource, TResult> selector)
+        public static TResult? Max<TSource, TResult>(this ParallelQuery<TSource> source, Func<TSource, TResult> selector)
         {
             return source.Select<TSource, TResult>(selector).Max<TResult>();
         }
@@ -5289,8 +5285,7 @@ namespace System.Linq
         //     defaultIfEmpty - whether to return a default value (true) or throw an
         //                      exception if the output of the query operator is empty
         //
-        [return: MaybeNull]
-        private static TSource GetOneWithPossibleDefault<TSource>(
+        private static TSource? GetOneWithPossibleDefault<TSource>(
             QueryOperator<TSource> queryOp, bool throwIfTwo, bool defaultIfEmpty)
         {
             Debug.Assert(queryOp != null, "expected query operator");
@@ -5321,7 +5316,7 @@ namespace System.Linq
 
             if (defaultIfEmpty)
             {
-                return default(TSource)!;
+                return default;
             }
             else
             {
@@ -5436,8 +5431,7 @@ namespace System.Linq
         /// <exception cref="System.OperationCanceledException">
         /// The query was canceled.
         /// </exception>
-        [return: MaybeNull]
-        public static TSource FirstOrDefault<TSource>(this ParallelQuery<TSource> source)
+        public static TSource? FirstOrDefault<TSource>(this ParallelQuery<TSource> source)
         {
             if (source == null) throw new ArgumentNullException(nameof(source));
 
@@ -5483,8 +5477,7 @@ namespace System.Linq
         /// <exception cref="System.OperationCanceledException">
         /// The query was canceled.
         /// </exception>
-        [return: MaybeNull]
-        public static TSource FirstOrDefault<TSource>(this ParallelQuery<TSource> source, Func<TSource, bool> predicate)
+        public static TSource? FirstOrDefault<TSource>(this ParallelQuery<TSource> source, Func<TSource, bool> predicate)
         {
             if (source == null) throw new ArgumentNullException(nameof(source));
             if (predicate == null) throw new ArgumentNullException(nameof(predicate));
@@ -5616,8 +5609,7 @@ namespace System.Linq
         /// <exception cref="System.OperationCanceledException">
         /// The query was canceled.
         /// </exception>
-        [return: MaybeNull]
-        public static TSource LastOrDefault<TSource>(this ParallelQuery<TSource> source)
+        public static TSource? LastOrDefault<TSource>(this ParallelQuery<TSource> source)
         {
             // @PERF: optimize for seekable data sources.  E.g. if an array, we can
             //     seek directly to the last element.
@@ -5659,8 +5651,7 @@ namespace System.Linq
         /// <exception cref="System.OperationCanceledException">
         /// The query was canceled.
         /// </exception>
-        [return: MaybeNull]
-        public static TSource LastOrDefault<TSource>(this ParallelQuery<TSource> source, Func<TSource, bool> predicate)
+        public static TSource? LastOrDefault<TSource>(this ParallelQuery<TSource> source, Func<TSource, bool> predicate)
         {
             if (source == null) throw new ArgumentNullException(nameof(source));
             if (predicate == null) throw new ArgumentNullException(nameof(predicate));
@@ -5764,8 +5755,7 @@ namespace System.Linq
         /// <exception cref="System.OperationCanceledException">
         /// The query was canceled.
         /// </exception>
-        [return: MaybeNull]
-        public static TSource SingleOrDefault<TSource>(this ParallelQuery<TSource> source)
+        public static TSource? SingleOrDefault<TSource>(this ParallelQuery<TSource> source)
         {
             // @PERF: optimize for ICollection-typed data sources, i.e. we can just
             //     check the Count property and avoid costly fork/join/synchronization.
@@ -5795,8 +5785,7 @@ namespace System.Linq
         /// <exception cref="System.OperationCanceledException">
         /// The query was canceled.
         /// </exception>
-        [return: MaybeNull]
-        public static TSource SingleOrDefault<TSource>(this ParallelQuery<TSource> source, Func<TSource, bool> predicate)
+        public static TSource? SingleOrDefault<TSource>(this ParallelQuery<TSource> source, Func<TSource, bool> predicate)
         {
             if (source == null) throw new ArgumentNullException(nameof(source));
             if (predicate == null) throw new ArgumentNullException(nameof(predicate));
@@ -5821,9 +5810,9 @@ namespace System.Linq
         /// <exception cref="System.ArgumentNullException">
         /// <paramref name="source"/> is a null reference (Nothing in Visual Basic).
         /// </exception>
-        public static ParallelQuery<TSource> DefaultIfEmpty<TSource>(this ParallelQuery<TSource> source)
+        public static ParallelQuery<TSource?> DefaultIfEmpty<TSource>(this ParallelQuery<TSource> source)
         {
-            return DefaultIfEmpty<TSource>(source, default!);
+            return DefaultIfEmpty<TSource>(source, default!)!;
         }
 
         /// <summary>
@@ -5909,8 +5898,7 @@ namespace System.Linq
         /// <exception cref="System.OperationCanceledException">
         /// The query was canceled.
         /// </exception>
-        [return: MaybeNull]
-        public static TSource ElementAtOrDefault<TSource>(this ParallelQuery<TSource> source, int index)
+        public static TSource? ElementAtOrDefault<TSource>(this ParallelQuery<TSource> source, int index)
         {
             if (source == null) throw new ArgumentNullException(nameof(source));
 
@@ -5928,7 +5916,7 @@ namespace System.Linq
                 }
             }
 
-            return default(TSource)!;
+            return default;
         }
     }
 }
index 91d264a..c3253aa 100644 (file)
@@ -74,15 +74,12 @@ namespace System.Linq
         public static System.Linq.IQueryable<TSource> DefaultIfEmpty<TSource>(this System.Linq.IQueryable<TSource> source, TSource defaultValue) { throw null; }
         public static System.Linq.IQueryable<TSource> Distinct<TSource>(this System.Linq.IQueryable<TSource> source) { throw null; }
         public static System.Linq.IQueryable<TSource> Distinct<TSource>(this System.Linq.IQueryable<TSource> source, System.Collections.Generic.IEqualityComparer<TSource>? comparer) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TSource ElementAtOrDefault<TSource>(this System.Linq.IQueryable<TSource> source, int index) { throw null; }
+        public static TSource? ElementAtOrDefault<TSource>(this System.Linq.IQueryable<TSource> source, int index) { throw null; }
         public static TSource ElementAt<TSource>(this System.Linq.IQueryable<TSource> source, int index) { throw null; }
         public static System.Linq.IQueryable<TSource> Except<TSource>(this System.Linq.IQueryable<TSource> source1, System.Collections.Generic.IEnumerable<TSource> source2) { throw null; }
         public static System.Linq.IQueryable<TSource> Except<TSource>(this System.Linq.IQueryable<TSource> source1, System.Collections.Generic.IEnumerable<TSource> source2, System.Collections.Generic.IEqualityComparer<TSource>? comparer) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TSource FirstOrDefault<TSource>(this System.Linq.IQueryable<TSource> source) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TSource FirstOrDefault<TSource>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<System.Func<TSource, bool>> predicate) { throw null; }
+        public static TSource? FirstOrDefault<TSource>(this System.Linq.IQueryable<TSource> source) { throw null; }
+        public static TSource? FirstOrDefault<TSource>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<System.Func<TSource, bool>> predicate) { throw null; }
         public static TSource First<TSource>(this System.Linq.IQueryable<TSource> source) { throw null; }
         public static TSource First<TSource>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<System.Func<TSource, bool>> predicate) { throw null; }
         public static System.Linq.IQueryable<System.Linq.IGrouping<TKey, TSource>> GroupBy<TSource, TKey>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<System.Func<TSource, TKey>> keySelector) { throw null; }
@@ -99,22 +96,16 @@ namespace System.Linq
         public static System.Linq.IQueryable<TSource> Intersect<TSource>(this System.Linq.IQueryable<TSource> source1, System.Collections.Generic.IEnumerable<TSource> source2, System.Collections.Generic.IEqualityComparer<TSource>? comparer) { throw null; }
         public static System.Linq.IQueryable<TResult> Join<TOuter, TInner, TKey, TResult>(this System.Linq.IQueryable<TOuter> outer, System.Collections.Generic.IEnumerable<TInner> inner, System.Linq.Expressions.Expression<System.Func<TOuter, TKey>> outerKeySelector, System.Linq.Expressions.Expression<System.Func<TInner, TKey>> innerKeySelector, System.Linq.Expressions.Expression<System.Func<TOuter, TInner, TResult>> resultSelector) { throw null; }
         public static System.Linq.IQueryable<TResult> Join<TOuter, TInner, TKey, TResult>(this System.Linq.IQueryable<TOuter> outer, System.Collections.Generic.IEnumerable<TInner> inner, System.Linq.Expressions.Expression<System.Func<TOuter, TKey>> outerKeySelector, System.Linq.Expressions.Expression<System.Func<TInner, TKey>> innerKeySelector, System.Linq.Expressions.Expression<System.Func<TOuter, TInner, TResult>> resultSelector, System.Collections.Generic.IEqualityComparer<TKey>? comparer) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TSource LastOrDefault<TSource>(this System.Linq.IQueryable<TSource> source) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TSource LastOrDefault<TSource>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<System.Func<TSource, bool>> predicate) { throw null; }
+        public static TSource? LastOrDefault<TSource>(this System.Linq.IQueryable<TSource> source) { throw null; }
+        public static TSource? LastOrDefault<TSource>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<System.Func<TSource, bool>> predicate) { throw null; }
         public static TSource Last<TSource>(this System.Linq.IQueryable<TSource> source) { throw null; }
         public static TSource Last<TSource>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<System.Func<TSource, bool>> predicate) { throw null; }
         public static long LongCount<TSource>(this System.Linq.IQueryable<TSource> source) { throw null; }
         public static long LongCount<TSource>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<System.Func<TSource, bool>> predicate) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TSource Max<TSource>(this System.Linq.IQueryable<TSource> source) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TResult Max<TSource, TResult>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<System.Func<TSource, TResult>> selector) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TSource Min<TSource>(this System.Linq.IQueryable<TSource> source) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TResult Min<TSource, TResult>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<System.Func<TSource, TResult>> selector) { throw null; }
+        public static TSource? Max<TSource>(this System.Linq.IQueryable<TSource> source) { throw null; }
+        public static TResult? Max<TSource, TResult>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<System.Func<TSource, TResult>> selector) { throw null; }
+        public static TSource? Min<TSource>(this System.Linq.IQueryable<TSource> source) { throw null; }
+        public static TResult? Min<TSource, TResult>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<System.Func<TSource, TResult>> selector) { throw null; }
         public static System.Linq.IQueryable<TResult> OfType<TResult>(this System.Linq.IQueryable source) { throw null; }
         public static System.Linq.IOrderedQueryable<TSource> OrderByDescending<TSource, TKey>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<System.Func<TSource, TKey>> keySelector) { throw null; }
         public static System.Linq.IOrderedQueryable<TSource> OrderByDescending<TSource, TKey>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<System.Func<TSource, TKey>> keySelector, System.Collections.Generic.IComparer<TKey>? comparer) { throw null; }
@@ -130,10 +121,8 @@ namespace System.Linq
         public static System.Linq.IQueryable<TResult> Select<TSource, TResult>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<System.Func<TSource, TResult>> selector) { throw null; }
         public static bool SequenceEqual<TSource>(this System.Linq.IQueryable<TSource> source1, System.Collections.Generic.IEnumerable<TSource> source2) { throw null; }
         public static bool SequenceEqual<TSource>(this System.Linq.IQueryable<TSource> source1, System.Collections.Generic.IEnumerable<TSource> source2, System.Collections.Generic.IEqualityComparer<TSource>? comparer) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TSource SingleOrDefault<TSource>(this System.Linq.IQueryable<TSource> source) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TSource SingleOrDefault<TSource>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<System.Func<TSource, bool>> predicate) { throw null; }
+        public static TSource? SingleOrDefault<TSource>(this System.Linq.IQueryable<TSource> source) { throw null; }
+        public static TSource? SingleOrDefault<TSource>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<System.Func<TSource, bool>> predicate) { throw null; }
         public static TSource Single<TSource>(this System.Linq.IQueryable<TSource> source) { throw null; }
         public static TSource Single<TSource>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<System.Func<TSource, bool>> predicate) { throw null; }
         public static System.Linq.IQueryable<TSource> SkipLast<TSource>(this System.Linq.IQueryable<TSource> source, int count) { throw null; }
index 91e37ff..8f345d0 100644 (file)
@@ -262,7 +262,7 @@ namespace System.Linq
 
         public static MethodInfo ElementAtOrDefault_TSource_2(Type TSource) =>
              (s_ElementAtOrDefault_TSource_2 ??
-             (s_ElementAtOrDefault_TSource_2 = new Func<IQueryable<object>, int, object>(Queryable.ElementAtOrDefault).GetMethodInfo().GetGenericMethodDefinition()))
+             (s_ElementAtOrDefault_TSource_2 = new Func<IQueryable<object>, int, object?>(Queryable.ElementAtOrDefault).GetMethodInfo().GetGenericMethodDefinition()))
               .MakeGenericMethod(TSource);
 
         private static MethodInfo? s_Except_TSource_2;
@@ -297,14 +297,14 @@ namespace System.Linq
 
         public static MethodInfo FirstOrDefault_TSource_1(Type TSource) =>
              (s_FirstOrDefault_TSource_1 ??
-             (s_FirstOrDefault_TSource_1 = new Func<IQueryable<object>, object>(Queryable.FirstOrDefault).GetMethodInfo().GetGenericMethodDefinition()))
+             (s_FirstOrDefault_TSource_1 = new Func<IQueryable<object>, object?>(Queryable.FirstOrDefault).GetMethodInfo().GetGenericMethodDefinition()))
               .MakeGenericMethod(TSource);
 
         private static MethodInfo? s_FirstOrDefault_TSource_2;
 
         public static MethodInfo FirstOrDefault_TSource_2(Type TSource) =>
              (s_FirstOrDefault_TSource_2 ??
-             (s_FirstOrDefault_TSource_2 = new Func<IQueryable<object>, Expression<Func<object, bool>>, object>(Queryable.FirstOrDefault).GetMethodInfo().GetGenericMethodDefinition()))
+             (s_FirstOrDefault_TSource_2 = new Func<IQueryable<object>, Expression<Func<object, bool>>, object?>(Queryable.FirstOrDefault).GetMethodInfo().GetGenericMethodDefinition()))
               .MakeGenericMethod(TSource);
 
         private static MethodInfo? s_GroupBy_TSource_TKey_2;
@@ -423,14 +423,14 @@ namespace System.Linq
 
         public static MethodInfo LastOrDefault_TSource_1(Type TSource) =>
              (s_LastOrDefault_TSource_1 ??
-             (s_LastOrDefault_TSource_1 = new Func<IQueryable<object>, object>(Queryable.LastOrDefault).GetMethodInfo().GetGenericMethodDefinition()))
+             (s_LastOrDefault_TSource_1 = new Func<IQueryable<object>, object?>(Queryable.LastOrDefault).GetMethodInfo().GetGenericMethodDefinition()))
               .MakeGenericMethod(TSource);
 
         private static MethodInfo? s_LastOrDefault_TSource_2;
 
         public static MethodInfo LastOrDefault_TSource_2(Type TSource) =>
              (s_LastOrDefault_TSource_2 ??
-             (s_LastOrDefault_TSource_2 = new Func<IQueryable<object>, Expression<Func<object, bool>>, object>(Queryable.LastOrDefault).GetMethodInfo().GetGenericMethodDefinition()))
+             (s_LastOrDefault_TSource_2 = new Func<IQueryable<object>, Expression<Func<object, bool>>, object?>(Queryable.LastOrDefault).GetMethodInfo().GetGenericMethodDefinition()))
               .MakeGenericMethod(TSource);
 
         private static MethodInfo? s_LongCount_TSource_1;
@@ -451,28 +451,28 @@ namespace System.Linq
 
         public static MethodInfo Max_TSource_1(Type TSource) =>
              (s_Max_TSource_1 ??
-             (s_Max_TSource_1 = new Func<IQueryable<object>, object>(Queryable.Max).GetMethodInfo().GetGenericMethodDefinition()))
+             (s_Max_TSource_1 = new Func<IQueryable<object>, object?>(Queryable.Max).GetMethodInfo().GetGenericMethodDefinition()))
               .MakeGenericMethod(TSource);
 
         private static MethodInfo? s_Max_TSource_TResult_2;
 
         public static MethodInfo Max_TSource_TResult_2(Type TSource, Type TResult) =>
              (s_Max_TSource_TResult_2 ??
-             (s_Max_TSource_TResult_2 = new Func<IQueryable<object>, Expression<Func<object, object>>, object>(Queryable.Max).GetMethodInfo().GetGenericMethodDefinition()))
+             (s_Max_TSource_TResult_2 = new Func<IQueryable<object>, Expression<Func<object, object>>, object?>(Queryable.Max).GetMethodInfo().GetGenericMethodDefinition()))
               .MakeGenericMethod(TSource, TResult);
 
         private static MethodInfo? s_Min_TSource_1;
 
         public static MethodInfo Min_TSource_1(Type TSource) =>
              (s_Min_TSource_1 ??
-             (s_Min_TSource_1 = new Func<IQueryable<object>, object>(Queryable.Min).GetMethodInfo().GetGenericMethodDefinition()))
+             (s_Min_TSource_1 = new Func<IQueryable<object>, object?>(Queryable.Min).GetMethodInfo().GetGenericMethodDefinition()))
               .MakeGenericMethod(TSource);
 
         private static MethodInfo? s_Min_TSource_TResult_2;
 
         public static MethodInfo Min_TSource_TResult_2(Type TSource, Type TResult) =>
              (s_Min_TSource_TResult_2 ??
-             (s_Min_TSource_TResult_2 = new Func<IQueryable<object>, Expression<Func<object, object>>, object>(Queryable.Min).GetMethodInfo().GetGenericMethodDefinition()))
+             (s_Min_TSource_TResult_2 = new Func<IQueryable<object>, Expression<Func<object, object>>, object?>(Queryable.Min).GetMethodInfo().GetGenericMethodDefinition()))
               .MakeGenericMethod(TSource, TResult);
 
         private static MethodInfo? s_OfType_TResult_1;
@@ -591,14 +591,14 @@ namespace System.Linq
 
         public static MethodInfo SingleOrDefault_TSource_1(Type TSource) =>
              (s_SingleOrDefault_TSource_1 ??
-             (s_SingleOrDefault_TSource_1 = new Func<IQueryable<object>, object>(Queryable.SingleOrDefault).GetMethodInfo().GetGenericMethodDefinition()))
+             (s_SingleOrDefault_TSource_1 = new Func<IQueryable<object>, object?>(Queryable.SingleOrDefault).GetMethodInfo().GetGenericMethodDefinition()))
               .MakeGenericMethod(TSource);
 
         private static MethodInfo? s_SingleOrDefault_TSource_2;
 
         public static MethodInfo SingleOrDefault_TSource_2(Type TSource) =>
              (s_SingleOrDefault_TSource_2 ??
-             (s_SingleOrDefault_TSource_2 = new Func<IQueryable<object>, Expression<Func<object, bool>>, object>(Queryable.SingleOrDefault).GetMethodInfo().GetGenericMethodDefinition()))
+             (s_SingleOrDefault_TSource_2 = new Func<IQueryable<object>, Expression<Func<object, bool>>, object?>(Queryable.SingleOrDefault).GetMethodInfo().GetGenericMethodDefinition()))
               .MakeGenericMethod(TSource);
 
         private static MethodInfo? s_Skip_TSource_2;
index e3ed64c..902474b 100644 (file)
@@ -740,8 +740,7 @@ namespace System.Linq
                     ));
         }
 
-        [return: MaybeNull]
-        public static TSource FirstOrDefault<TSource>(this IQueryable<TSource> source)
+        public static TSource? FirstOrDefault<TSource>(this IQueryable<TSource> source)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -751,8 +750,7 @@ namespace System.Linq
                     CachedReflectionInfo.FirstOrDefault_TSource_1(typeof(TSource)), source.Expression));
         }
 
-        [return: MaybeNull]
-        public static TSource FirstOrDefault<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
+        public static TSource? FirstOrDefault<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -790,8 +788,7 @@ namespace System.Linq
                     ));
         }
 
-        [return: MaybeNull]
-        public static TSource LastOrDefault<TSource>(this IQueryable<TSource> source)
+        public static TSource? LastOrDefault<TSource>(this IQueryable<TSource> source)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -801,8 +798,7 @@ namespace System.Linq
                     CachedReflectionInfo.LastOrDefault_TSource_1(typeof(TSource)), source.Expression));
         }
 
-        [return: MaybeNull]
-        public static TSource LastOrDefault<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
+        public static TSource? LastOrDefault<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -840,8 +836,7 @@ namespace System.Linq
                     ));
         }
 
-        [return: MaybeNull]
-        public static TSource SingleOrDefault<TSource>(this IQueryable<TSource> source)
+        public static TSource? SingleOrDefault<TSource>(this IQueryable<TSource> source)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -851,8 +846,7 @@ namespace System.Linq
                     CachedReflectionInfo.SingleOrDefault_TSource_1(typeof(TSource)), source.Expression));
         }
 
-        [return: MaybeNull]
-        public static TSource SingleOrDefault<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
+        public static TSource? SingleOrDefault<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -880,8 +874,7 @@ namespace System.Linq
                     ));
         }
 
-        [return: MaybeNull]
-        public static TSource ElementAtOrDefault<TSource>(this IQueryable<TSource> source, int index)
+        public static TSource? ElementAtOrDefault<TSource>(this IQueryable<TSource> source, int index)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -1065,8 +1058,7 @@ namespace System.Linq
                     ));
         }
 
-        [return: MaybeNull]
-        public static TSource Min<TSource>(this IQueryable<TSource> source)
+        public static TSource? Min<TSource>(this IQueryable<TSource> source)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -1076,8 +1068,7 @@ namespace System.Linq
                     CachedReflectionInfo.Min_TSource_1(typeof(TSource)), source.Expression));
         }
 
-        [return: MaybeNull]
-        public static TResult Min<TSource, TResult>(this IQueryable<TSource> source, Expression<Func<TSource, TResult>> selector)
+        public static TResult? Min<TSource, TResult>(this IQueryable<TSource> source, Expression<Func<TSource, TResult>> selector)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -1091,8 +1082,7 @@ namespace System.Linq
                     ));
         }
 
-        [return: MaybeNull]
-        public static TSource Max<TSource>(this IQueryable<TSource> source)
+        public static TSource? Max<TSource>(this IQueryable<TSource> source)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
@@ -1102,8 +1092,7 @@ namespace System.Linq
                     CachedReflectionInfo.Max_TSource_1(typeof(TSource)), source.Expression));
         }
 
-        [return: MaybeNull]
-        public static TResult Max<TSource, TResult>(this IQueryable<TSource> source, Expression<Func<TSource, TResult>> selector)
+        public static TResult? Max<TSource, TResult>(this IQueryable<TSource> source, Expression<Func<TSource, TResult>> selector)
         {
             if (source == null)
                 throw Error.ArgumentNull(nameof(source));
index bf41a28..91d5432 100644 (file)
@@ -42,17 +42,17 @@ namespace System.Linq
         public static bool Contains<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, TSource value, System.Collections.Generic.IEqualityComparer<TSource>? comparer) { throw null; }
         public static int Count<TSource>(this System.Collections.Generic.IEnumerable<TSource> source) { throw null; }
         public static int Count<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, bool> predicate) { throw null; }
-        public static System.Collections.Generic.IEnumerable<TSource> DefaultIfEmpty<TSource>(this System.Collections.Generic.IEnumerable<TSource> source) { throw null; }
+        public static System.Collections.Generic.IEnumerable<TSource?> DefaultIfEmpty<TSource>(this System.Collections.Generic.IEnumerable<TSource> source) { throw null; }
         public static System.Collections.Generic.IEnumerable<TSource> DefaultIfEmpty<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, TSource defaultValue) { throw null; }
         public static System.Collections.Generic.IEnumerable<TSource> Distinct<TSource>(this System.Collections.Generic.IEnumerable<TSource> source) { throw null; }
         public static System.Collections.Generic.IEnumerable<TSource> Distinct<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Collections.Generic.IEqualityComparer<TSource>? comparer) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public static TSource ElementAtOrDefault<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, int index) { throw null; }
+        public static TSource? ElementAtOrDefault<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, int index) { throw null; }
         public static TSource ElementAt<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, int index) { throw null; }
         public static System.Collections.Generic.IEnumerable<TResult> Empty<TResult>() { throw null; }
         public static System.Collections.Generic.IEnumerable<TSource> Except<TSource>(this System.Collections.Generic.IEnumerable<TSource> first, System.Collections.Generic.IEnumerable<TSource> second) { throw null; }
         public static System.Collections.Generic.IEnumerable<TSource> Except<TSource>(this System.Collections.Generic.IEnumerable<TSource> first, System.Collections.Generic.IEnumerable<TSource> second, System.Collections.Generic.IEqualityComparer<TSource>? comparer) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public static TSource FirstOrDefault<TSource>(this System.Collections.Generic.IEnumerable<TSource> source) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public static TSource FirstOrDefault<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, bool> predicate) { throw null; }
+        public static TSource? FirstOrDefault<TSource>(this System.Collections.Generic.IEnumerable<TSource> source) { throw null; }
+        public static TSource? FirstOrDefault<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, bool> predicate) { throw null; }
         public static TSource First<TSource>(this System.Collections.Generic.IEnumerable<TSource> source) { throw null; }
         public static TSource First<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, bool> predicate) { throw null; }
         public static System.Collections.Generic.IEnumerable<System.Linq.IGrouping<TKey, TSource>> GroupBy<TSource, TKey>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TKey> keySelector) { throw null; }
@@ -69,8 +69,8 @@ namespace System.Linq
         public static System.Collections.Generic.IEnumerable<TSource> Intersect<TSource>(this System.Collections.Generic.IEnumerable<TSource> first, System.Collections.Generic.IEnumerable<TSource> second, System.Collections.Generic.IEqualityComparer<TSource>? comparer) { throw null; }
         public static System.Collections.Generic.IEnumerable<TResult> Join<TOuter, TInner, TKey, TResult>(this System.Collections.Generic.IEnumerable<TOuter> outer, System.Collections.Generic.IEnumerable<TInner> inner, System.Func<TOuter, TKey> outerKeySelector, System.Func<TInner, TKey> innerKeySelector, System.Func<TOuter, TInner, TResult> resultSelector) { throw null; }
         public static System.Collections.Generic.IEnumerable<TResult> Join<TOuter, TInner, TKey, TResult>(this System.Collections.Generic.IEnumerable<TOuter> outer, System.Collections.Generic.IEnumerable<TInner> inner, System.Func<TOuter, TKey> outerKeySelector, System.Func<TInner, TKey> innerKeySelector, System.Func<TOuter, TInner, TResult> resultSelector, System.Collections.Generic.IEqualityComparer<TKey>? comparer) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public static TSource LastOrDefault<TSource>(this System.Collections.Generic.IEnumerable<TSource> source) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public static TSource LastOrDefault<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, bool> predicate) { throw null; }
+        public static TSource? LastOrDefault<TSource>(this System.Collections.Generic.IEnumerable<TSource> source) { throw null; }
+        public static TSource? LastOrDefault<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, bool> predicate) { throw null; }
         public static TSource Last<TSource>(this System.Collections.Generic.IEnumerable<TSource> source) { throw null; }
         public static TSource Last<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, bool> predicate) { throw null; }
         public static long LongCount<TSource>(this System.Collections.Generic.IEnumerable<TSource> source) { throw null; }
@@ -85,7 +85,7 @@ namespace System.Linq
         public static long? Max(this System.Collections.Generic.IEnumerable<long?> source) { throw null; }
         public static float? Max(this System.Collections.Generic.IEnumerable<float?> source) { throw null; }
         public static float Max(this System.Collections.Generic.IEnumerable<float> source) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public static TSource Max<TSource>(this System.Collections.Generic.IEnumerable<TSource> source) { throw null; }
+        public static TSource? Max<TSource>(this System.Collections.Generic.IEnumerable<TSource> source) { throw null; }
         public static decimal Max<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, decimal> selector) { throw null; }
         public static double Max<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, double> selector) { throw null; }
         public static int Max<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, int> selector) { throw null; }
@@ -96,7 +96,7 @@ namespace System.Linq
         public static long? Max<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, long?> selector) { throw null; }
         public static float? Max<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, float?> selector) { throw null; }
         public static float Max<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, float> selector) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public static TResult Max<TSource, TResult>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TResult> selector) { throw null; }
+        public static TResult? Max<TSource, TResult>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TResult> selector) { throw null; }
         public static decimal Min(this System.Collections.Generic.IEnumerable<decimal> source) { throw null; }
         public static double Min(this System.Collections.Generic.IEnumerable<double> source) { throw null; }
         public static int Min(this System.Collections.Generic.IEnumerable<int> source) { throw null; }
@@ -107,7 +107,7 @@ namespace System.Linq
         public static long? Min(this System.Collections.Generic.IEnumerable<long?> source) { throw null; }
         public static float? Min(this System.Collections.Generic.IEnumerable<float?> source) { throw null; }
         public static float Min(this System.Collections.Generic.IEnumerable<float> source) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public static TSource Min<TSource>(this System.Collections.Generic.IEnumerable<TSource> source) { throw null; }
+        public static TSource? Min<TSource>(this System.Collections.Generic.IEnumerable<TSource> source) { throw null; }
         public static decimal Min<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, decimal> selector) { throw null; }
         public static double Min<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, double> selector) { throw null; }
         public static int Min<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, int> selector) { throw null; }
@@ -118,7 +118,7 @@ namespace System.Linq
         public static long? Min<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, long?> selector) { throw null; }
         public static float? Min<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, float?> selector) { throw null; }
         public static float Min<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, float> selector) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public static TResult Min<TSource, TResult>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TResult> selector) { throw null; }
+        public static TResult? Min<TSource, TResult>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TResult> selector) { throw null; }
         public static System.Collections.Generic.IEnumerable<TResult> OfType<TResult>(this System.Collections.IEnumerable source) { throw null; }
         public static System.Linq.IOrderedEnumerable<TSource> OrderByDescending<TSource, TKey>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TKey> keySelector) { throw null; }
         public static System.Linq.IOrderedEnumerable<TSource> OrderByDescending<TSource, TKey>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TKey> keySelector, System.Collections.Generic.IComparer<TKey>? comparer) { throw null; }
@@ -136,8 +136,8 @@ namespace System.Linq
         public static System.Collections.Generic.IEnumerable<TResult> Select<TSource, TResult>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, TResult> selector) { throw null; }
         public static bool SequenceEqual<TSource>(this System.Collections.Generic.IEnumerable<TSource> first, System.Collections.Generic.IEnumerable<TSource> second) { throw null; }
         public static bool SequenceEqual<TSource>(this System.Collections.Generic.IEnumerable<TSource> first, System.Collections.Generic.IEnumerable<TSource> second, System.Collections.Generic.IEqualityComparer<TSource>? comparer) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public static TSource SingleOrDefault<TSource>(this System.Collections.Generic.IEnumerable<TSource> source) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute] public static TSource SingleOrDefault<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, bool> predicate) { throw null; }
+        public static TSource? SingleOrDefault<TSource>(this System.Collections.Generic.IEnumerable<TSource> source) { throw null; }
+        public static TSource? SingleOrDefault<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, bool> predicate) { throw null; }
         public static TSource Single<TSource>(this System.Collections.Generic.IEnumerable<TSource> source) { throw null; }
         public static TSource Single<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, bool> predicate) { throw null; }
         public static System.Collections.Generic.IEnumerable<TSource> SkipLast<TSource>(this System.Collections.Generic.IEnumerable<TSource> source, int count) { throw null; }
index e358538..a513a6e 100644 (file)
@@ -8,7 +8,7 @@ namespace System.Linq
 {
     public static partial class Enumerable
     {
-        public static IEnumerable<TSource> DefaultIfEmpty<TSource>(this IEnumerable<TSource> source) =>
+        public static IEnumerable<TSource?> DefaultIfEmpty<TSource>(this IEnumerable<TSource> source) =>
             DefaultIfEmpty(source, default!);
 
         public static IEnumerable<TSource> DefaultIfEmpty<TSource>(this IEnumerable<TSource> source, TSource defaultValue)
index a857819..da8dc8f 100644 (file)
@@ -51,8 +51,7 @@ namespace System.Linq
             return default;
         }
 
-        [return: MaybeNull]
-        public static TSource ElementAtOrDefault<TSource>(this IEnumerable<TSource> source, int index)
+        public static TSource? ElementAtOrDefault<TSource>(this IEnumerable<TSource> source, int index)
         {
             if (source == null)
             {
@@ -90,7 +89,7 @@ namespace System.Linq
                 }
             }
 
-            return default!;
+            return default;
         }
     }
 }
index 6ebeb80..295acb5 100644 (file)
@@ -30,16 +30,13 @@ namespace System.Linq
             return first!;
         }
 
-        [return: MaybeNull]
-        public static TSource FirstOrDefault<TSource>(this IEnumerable<TSource> source) =>
+        public static TSource? FirstOrDefault<TSource>(this IEnumerable<TSource> source) =>
             source.TryGetFirst(out bool _);
 
-        [return: MaybeNull]
-        public static TSource FirstOrDefault<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) =>
+        public static TSource? FirstOrDefault<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) =>
             source.TryGetFirst(predicate, out bool _);
 
-        [return: MaybeNull]
-        private static TSource TryGetFirst<TSource>(this IEnumerable<TSource> source, out bool found)
+        private static TSource? TryGetFirst<TSource>(this IEnumerable<TSource> source, out bool found)
         {
             if (source == null)
             {
@@ -72,11 +69,10 @@ namespace System.Linq
             }
 
             found = false;
-            return default!;
+            return default;
         }
 
-        [return: MaybeNull]
-        private static TSource TryGetFirst<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate, out bool found)
+        private static TSource? TryGetFirst<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate, out bool found)
         {
             if (source == null)
             {
@@ -98,7 +94,7 @@ namespace System.Linq
             }
 
             found = false;
-            return default!;
+            return default;
         }
     }
 }
index d1c5e2e..68b676f 100644 (file)
@@ -30,23 +30,20 @@ namespace System.Linq
         /// <param name="index">The 0-based index to access.</param>
         /// <param name="found"><c>true</c> if the sequence contains an element at that index, <c>false</c> otherwise.</param>
         /// <returns>The element if <paramref name="found"/> is <c>true</c>, otherwise, the default value of <typeparamref name="TElement"/>.</returns>
-        [return: MaybeNull]
-        TElement TryGetElementAt(int index, out bool found);
+        TElement? TryGetElementAt(int index, out bool found);
 
         /// <summary>
         /// Gets the first item in this sequence.
         /// </summary>
         /// <param name="found"><c>true</c> if the sequence contains an element, <c>false</c> otherwise.</param>
         /// <returns>The element if <paramref name="found"/> is <c>true</c>, otherwise, the default value of <typeparamref name="TElement"/>.</returns>
-        [return: MaybeNull]
-        TElement TryGetFirst(out bool found);
+        TElement? TryGetFirst(out bool found);
 
         /// <summary>
         /// Gets the last item in this sequence.
         /// </summary>
         /// <param name="found"><c>true</c> if the sequence contains an element, <c>false</c> otherwise.</param>
         /// <returns>The element if <paramref name="found"/> is <c>true</c>, otherwise, the default value of <typeparamref name="TElement"/>.</returns>
-        [return: MaybeNull]
-        TElement TryGetLast(out bool found);
+        TElement? TryGetLast(out bool found);
     }
 }
index d08bbf9..d781961 100644 (file)
@@ -30,16 +30,13 @@ namespace System.Linq
             return last!;
         }
 
-        [return: MaybeNull]
-        public static TSource LastOrDefault<TSource>(this IEnumerable<TSource> source) =>
+        public static TSource? LastOrDefault<TSource>(this IEnumerable<TSource> source) =>
             source.TryGetLast(out bool _);
 
-        [return: MaybeNull]
-        public static TSource LastOrDefault<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) =>
+        public static TSource? LastOrDefault<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) =>
             source.TryGetLast(predicate, out bool _);
 
-        [return: MaybeNull]
-        private static TSource TryGetLast<TSource>(this IEnumerable<TSource> source, out bool found)
+        private static TSource? TryGetLast<TSource>(this IEnumerable<TSource> source, out bool found)
         {
             if (source == null)
             {
@@ -80,11 +77,10 @@ namespace System.Linq
             }
 
             found = false;
-            return default!;
+            return default;
         }
 
-        [return: MaybeNull]
-        private static TSource TryGetLast<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate, out bool found)
+        private static TSource? TryGetLast<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate, out bool found)
         {
             if (source == null)
             {
@@ -139,7 +135,7 @@ namespace System.Linq
             }
 
             found = false;
-            return default!;
+            return default;
         }
     }
 }
index 21e1f8d..9dc4c92 100644 (file)
@@ -441,8 +441,7 @@ namespace System.Linq
             return value;
         }
 
-        [return: MaybeNull]
-        public static TSource Max<TSource>(this IEnumerable<TSource> source)
+        public static TSource? Max<TSource>(this IEnumerable<TSource> source)
         {
             if (source == null)
             {
@@ -450,7 +449,7 @@ namespace System.Linq
             }
 
             Comparer<TSource> comparer = Comparer<TSource>.Default;
-            TSource value = default!;
+            TSource? value = default;
             if (value == null)
             {
                 using (IEnumerator<TSource> e = source.GetEnumerator())
@@ -983,8 +982,7 @@ namespace System.Linq
             return value;
         }
 
-        [return: MaybeNull]
-        public static TResult Max<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector)
+        public static TResult? Max<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector)
         {
             if (source == null)
             {
@@ -997,7 +995,7 @@ namespace System.Linq
             }
 
             Comparer<TResult> comparer = Comparer<TResult>.Default;
-            TResult value = default!;
+            TResult? value = default;
             if (value == null)
             {
                 using (IEnumerator<TSource> e = source.GetEnumerator())
index b3a7e62..9958c84 100644 (file)
@@ -399,8 +399,7 @@ namespace System.Linq
             return value;
         }
 
-        [return: MaybeNull]
-        public static TSource Min<TSource>(this IEnumerable<TSource> source)
+        public static TSource? Min<TSource>(this IEnumerable<TSource> source)
         {
             if (source == null)
             {
@@ -408,7 +407,7 @@ namespace System.Linq
             }
 
             Comparer<TSource> comparer = Comparer<TSource>.Default;
-            TSource value = default!;
+            TSource? value = default;
             if (value == null)
             {
                 using (IEnumerator<TSource> e = source.GetEnumerator())
@@ -899,8 +898,7 @@ namespace System.Linq
             return value;
         }
 
-        [return: MaybeNull]
-        public static TResult Min<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector)
+        public static TResult? Min<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector)
         {
             if (source == null)
             {
@@ -913,7 +911,7 @@ namespace System.Linq
             }
 
             Comparer<TResult> comparer = Comparer<TResult>.Default;
-            TResult value = default!;
+            TResult? value = default;
             if (value == null)
             {
                 using (IEnumerator<TSource> e = source.GetEnumerator())
index 5d3946e..b90dbf2 100644 (file)
@@ -138,8 +138,7 @@ namespace System.Linq
 
         public IPartition<TElement> Take(int count) => new OrderedPartition<TElement>(this, 0, count - 1);
 
-        [return: MaybeNull]
-        public TElement TryGetElementAt(int index, out bool found)
+        public TElement? TryGetElementAt(int index, out bool found)
         {
             if (index == 0)
             {
@@ -158,11 +157,10 @@ namespace System.Linq
             }
 
             found = false;
-            return default!;
+            return default;
         }
 
-        [return: MaybeNull]
-        public TElement TryGetFirst(out bool found)
+        public TElement? TryGetFirst(out bool found)
         {
             CachingComparer<TElement> comparer = GetComparer();
             using (IEnumerator<TElement> e = _source.GetEnumerator())
@@ -170,7 +168,7 @@ namespace System.Linq
                 if (!e.MoveNext())
                 {
                     found = false;
-                    return default!;
+                    return default;
                 }
 
                 TElement value = e.Current;
@@ -189,15 +187,14 @@ namespace System.Linq
             }
         }
 
-        [return: MaybeNull]
-        public TElement TryGetLast(out bool found)
+        public TElement? TryGetLast(out bool found)
         {
             using (IEnumerator<TElement> e = _source.GetEnumerator())
             {
                 if (!e.MoveNext())
                 {
                     found = false;
-                    return default!;
+                    return default;
                 }
 
                 CachingComparer<TElement> comparer = GetComparer();
@@ -217,15 +214,14 @@ namespace System.Linq
             }
         }
 
-        [return: MaybeNull]
-        public TElement TryGetLast(int minIdx, int maxIdx, out bool found)
+        public TElement? TryGetLast(int minIdx, int maxIdx, out bool found)
         {
             Buffer<TElement> buffer = new Buffer<TElement>(_source);
             int count = buffer._count;
             if (minIdx >= count)
             {
                 found = false;
-                return default!;
+                return default;
             }
 
             found = true;
index 8f985a4..2c8cf01 100644 (file)
@@ -72,8 +72,7 @@ namespace System.Linq
         IOrderedEnumerable<TElement> IOrderedEnumerable<TElement>.CreateOrderedEnumerable<TKey>(Func<TElement, TKey> keySelector, IComparer<TKey>? comparer, bool descending) =>
             new OrderedEnumerable<TElement, TKey>(_source, keySelector, comparer, @descending, this);
 
-        [return: MaybeNull]
-        public TElement TryGetLast(Func<TElement, bool> predicate, out bool found)
+        public TElement? TryGetLast(Func<TElement, bool> predicate, out bool found)
         {
             CachingComparer<TElement> comparer = GetComparer();
             using (IEnumerator<TElement> e = _source.GetEnumerator())
@@ -84,7 +83,7 @@ namespace System.Linq
                     if (!e.MoveNext())
                     {
                         found = false;
-                        return default!;
+                        return default;
                     }
 
                     value = e.Current;
@@ -176,7 +175,7 @@ namespace System.Linq
         protected readonly Func<TElement, TKey> _keySelector;
         protected readonly IComparer<TKey> _comparer;
         protected readonly bool _descending;
-        [MaybeNull] protected TKey _lastKey = default!;
+        protected TKey? _lastKey;
 
         public CachingComparer(Func<TElement, TKey> keySelector, IComparer<TKey> comparer, bool descending)
         {
index f2f39c0..c46465f 100644 (file)
@@ -38,7 +38,6 @@ namespace System.Linq
         public TElement Current => default!;
 
         [ExcludeFromCodeCoverage(Justification = "Shouldn't be called, and as undefined can return or throw anything anyway")]
-        [MaybeNull]
         object IEnumerator.Current => default!;
 
         void IEnumerator.Reset()
@@ -55,25 +54,22 @@ namespace System.Linq
 
         public IPartition<TElement> Take(int count) => this;
 
-        [return: MaybeNull]
-        public TElement TryGetElementAt(int index, out bool found)
+        public TElement? TryGetElementAt(int index, out bool found)
         {
             found = false;
-            return default!;
+            return default;
         }
 
-        [return: MaybeNull]
-        public TElement TryGetFirst(out bool found)
+        public TElement? TryGetFirst(out bool found)
         {
             found = false;
-            return default!;
+            return default;
         }
 
-        [return: MaybeNull]
-        public TElement TryGetLast(out bool found)
+        public TElement? TryGetLast(out bool found)
         {
             found = false;
-            return default!;
+            return default;
         }
 
         public TElement[] ToArray() => Array.Empty<TElement>();
@@ -117,8 +113,7 @@ namespace System.Linq
             return new OrderedPartition<TElement>(_source, _minIndexInclusive, maxIndex);
         }
 
-        [return: MaybeNull]
-        public TElement TryGetElementAt(int index, out bool found)
+        public TElement? TryGetElementAt(int index, out bool found)
         {
             if (unchecked((uint)index <= (uint)(_maxIndexInclusive - _minIndexInclusive)))
             {
@@ -126,14 +121,12 @@ namespace System.Linq
             }
 
             found = false;
-            return default!;
+            return default;
         }
 
-        [return: MaybeNull]
-        public TElement TryGetFirst(out bool found) => _source.TryGetElementAt(_minIndexInclusive, out found);
+        public TElement? TryGetFirst(out bool found) => _source.TryGetElementAt(_minIndexInclusive, out found);
 
-        [return: MaybeNull]
-        public TElement TryGetLast(out bool found) =>
+        public TElement? TryGetLast(out bool found) =>
             _source.TryGetLast(_minIndexInclusive, _maxIndexInclusive, out found);
 
         public TElement[] ToArray() => _source.ToArray(_minIndexInclusive, _maxIndexInclusive);
@@ -201,8 +194,7 @@ namespace System.Linq
                 return unchecked((uint)maxIndex >= (uint)_maxIndexInclusive) ? this : new ListPartition<TSource>(_source, _minIndexInclusive, maxIndex);
             }
 
-            [return: MaybeNull]
-            public TSource TryGetElementAt(int index, out bool found)
+            public TSource? TryGetElementAt(int index, out bool found)
             {
                 if (unchecked((uint)index <= (uint)(_maxIndexInclusive - _minIndexInclusive) && index < _source.Count - _minIndexInclusive))
                 {
@@ -211,11 +203,10 @@ namespace System.Linq
                 }
 
                 found = false;
-                return default!;
+                return default;
             }
 
-            [return: MaybeNull]
-            public TSource TryGetFirst(out bool found)
+            public TSource? TryGetFirst(out bool found)
             {
                 if (_source.Count > _minIndexInclusive)
                 {
@@ -224,11 +215,10 @@ namespace System.Linq
                 }
 
                 found = false;
-                return default!;
+                return default;
             }
 
-            [return: MaybeNull]
-            public TSource TryGetLast(out bool found)
+            public TSource? TryGetLast(out bool found)
             {
                 int lastIndex = _source.Count - 1;
                 if (lastIndex >= _minIndexInclusive)
@@ -238,7 +228,7 @@ namespace System.Linq
                 }
 
                 found = false;
-                return default!;
+                return default;
             }
 
             private int Count
@@ -480,8 +470,7 @@ namespace System.Linq
                 return new EnumerablePartition<TSource>(_source, _minIndexInclusive, maxIndex);
             }
 
-            [return: MaybeNull]
-            public TSource TryGetElementAt(int index, out bool found)
+            public TSource? TryGetElementAt(int index, out bool found)
             {
                 // If the index is negative or >= our max count, return early.
                 if (index >= 0 && (!HasLimit || index < Limit))
@@ -499,11 +488,10 @@ namespace System.Linq
                 }
 
                 found = false;
-                return default!;
+                return default;
             }
 
-            [return: MaybeNull]
-            public TSource TryGetFirst(out bool found)
+            public TSource? TryGetFirst(out bool found)
             {
                 using (IEnumerator<TSource> en = _source.GetEnumerator())
                 {
@@ -515,11 +503,10 @@ namespace System.Linq
                 }
 
                 found = false;
-                return default!;
+                return default;
             }
 
-            [return: MaybeNull]
-            public TSource TryGetLast(out bool found)
+            public TSource? TryGetLast(out bool found)
             {
                 using (IEnumerator<TSource> en = _source.GetEnumerator())
                 {
@@ -542,7 +529,7 @@ namespace System.Linq
                 }
 
                 found = false;
-                return default!;
+                return default;
             }
 
             public TSource[] ToArray()
index 7cc12d6..3840acd 100644 (file)
@@ -62,8 +62,7 @@ namespace System.Linq
                 return new RepeatIterator<TResult>(_current, count);
             }
 
-            [return: MaybeNull]
-            public TResult TryGetElementAt(int index, out bool found)
+            public TResult? TryGetElementAt(int index, out bool found)
             {
                 if ((uint)index < (uint)_count)
                 {
@@ -72,7 +71,7 @@ namespace System.Linq
                 }
 
                 found = false;
-                return default!;
+                return default;
             }
 
             public TResult TryGetFirst(out bool found)
index 530f92b..e23cbd4 100644 (file)
@@ -133,8 +133,7 @@ namespace System.Linq
                     new SelectListPartitionIterator<TSource, TResult>(_source, _selector, 0, count - 1);
             }
 
-            [return: MaybeNull]
-            public TResult TryGetElementAt(int index, out bool found)
+            public TResult? TryGetElementAt(int index, out bool found)
             {
                 if (unchecked((uint)index < (uint)_source.Length))
                 {
@@ -143,7 +142,7 @@ namespace System.Linq
                 }
 
                 found = false;
-                return default!;
+                return default;
             }
 
             public TResult TryGetFirst(out bool found)
@@ -262,8 +261,7 @@ namespace System.Linq
                 return new SelectRangeIterator<TResult>(_start, _start + count, _selector);
             }
 
-            [return: MaybeNull]
-            public TResult TryGetElementAt(int index, out bool found)
+            public TResult? TryGetElementAt(int index, out bool found)
             {
                 if ((uint)index < (uint)(_end - _start))
                 {
@@ -272,7 +270,7 @@ namespace System.Linq
                 }
 
                 found = false;
-                return default!;
+                return default;
             }
 
             public TResult TryGetFirst(out bool found)
@@ -351,8 +349,7 @@ namespace System.Linq
                 return new SelectListPartitionIterator<TSource, TResult>(_source, _selector, 0, count - 1);
             }
 
-            [return: MaybeNull]
-            public TResult TryGetElementAt(int index, out bool found)
+            public TResult? TryGetElementAt(int index, out bool found)
             {
                 if (unchecked((uint)index < (uint)_source.Count))
                 {
@@ -361,11 +358,10 @@ namespace System.Linq
                 }
 
                 found = false;
-                return default!;
+                return default;
             }
 
-            [return: MaybeNull]
-            public TResult TryGetFirst(out bool found)
+            public TResult? TryGetFirst(out bool found)
             {
                 if (_source.Count != 0)
                 {
@@ -374,11 +370,10 @@ namespace System.Linq
                 }
 
                 found = false;
-                return default!;
+                return default;
             }
 
-            [return: MaybeNull]
-            public TResult TryGetLast(out bool found)
+            public TResult? TryGetLast(out bool found)
             {
                 int len = _source.Count;
                 if (len != 0)
@@ -388,7 +383,7 @@ namespace System.Linq
                 }
 
                 found = false;
-                return default!;
+                return default;
             }
         }
 
@@ -453,8 +448,7 @@ namespace System.Linq
                 return new SelectListPartitionIterator<TSource, TResult>(_source, _selector, 0, count - 1);
             }
 
-            [return: MaybeNull]
-            public TResult TryGetElementAt(int index, out bool found)
+            public TResult? TryGetElementAt(int index, out bool found)
             {
                 if (unchecked((uint)index < (uint)_source.Count))
                 {
@@ -463,11 +457,10 @@ namespace System.Linq
                 }
 
                 found = false;
-                return default!;
+                return default;
             }
 
-            [return: MaybeNull]
-            public TResult TryGetFirst(out bool found)
+            public TResult? TryGetFirst(out bool found)
             {
                 if (_source.Count != 0)
                 {
@@ -476,11 +469,10 @@ namespace System.Linq
                 }
 
                 found = false;
-                return default!;
+                return default;
             }
 
-            [return: MaybeNull]
-            public TResult TryGetLast(out bool found)
+            public TResult? TryGetLast(out bool found)
             {
                 int len = _source.Count;
                 if (len != 0)
@@ -490,7 +482,7 @@ namespace System.Linq
                 }
 
                 found = false;
-                return default!;
+                return default;
             }
         }
 
@@ -565,8 +557,7 @@ namespace System.Linq
                 return new SelectIPartitionIterator<TSource, TResult>(_source.Take(count), _selector);
             }
 
-            [return: MaybeNull]
-            public TResult TryGetElementAt(int index, out bool found)
+            public TResult? TryGetElementAt(int index, out bool found)
             {
                 bool sourceFound;
                 TSource input = _source.TryGetElementAt(index, out sourceFound);
@@ -574,8 +565,7 @@ namespace System.Linq
                 return sourceFound ? _selector(input!) : default!;
             }
 
-            [return: MaybeNull]
-            public TResult TryGetFirst(out bool found)
+            public TResult? TryGetFirst(out bool found)
             {
                 bool sourceFound;
                 TSource input = _source.TryGetFirst(out sourceFound);
@@ -583,8 +573,7 @@ namespace System.Linq
                 return sourceFound ? _selector(input!) : default!;
             }
 
-            [return: MaybeNull]
-            public TResult TryGetLast(out bool found)
+            public TResult? TryGetLast(out bool found)
             {
                 bool sourceFound;
                 TSource input = _source.TryGetLast(out sourceFound);
@@ -739,8 +728,7 @@ namespace System.Linq
                 return (uint)maxIndex >= (uint)_maxIndexInclusive ? this : new SelectListPartitionIterator<TSource, TResult>(_source, _selector, _minIndexInclusive, maxIndex);
             }
 
-            [return: MaybeNull]
-            public TResult TryGetElementAt(int index, out bool found)
+            public TResult? TryGetElementAt(int index, out bool found)
             {
                 if ((uint)index <= (uint)(_maxIndexInclusive - _minIndexInclusive) && index < _source.Count - _minIndexInclusive)
                 {
@@ -749,11 +737,10 @@ namespace System.Linq
                 }
 
                 found = false;
-                return default!;
+                return default;
             }
 
-            [return: MaybeNull]
-            public TResult TryGetFirst(out bool found)
+            public TResult? TryGetFirst(out bool found)
             {
                 if (_source.Count > _minIndexInclusive)
                 {
@@ -762,11 +749,10 @@ namespace System.Linq
                 }
 
                 found = false;
-                return default!;
+                return default;
             }
 
-            [return: MaybeNull]
-            public TResult TryGetLast(out bool found)
+            public TResult? TryGetLast(out bool found)
             {
                 int lastIndex = _source.Count - 1;
                 if (lastIndex >= _minIndexInclusive)
@@ -776,7 +762,7 @@ namespace System.Linq
                 }
 
                 found = false;
-                return default!;
+                return default;
             }
 
             private int Count
index 7640bc7..913405d 100644 (file)
@@ -83,8 +83,7 @@ namespace System.Linq
             return default;
         }
 
-        [return: MaybeNull]
-        public static TSource SingleOrDefault<TSource>(this IEnumerable<TSource> source)
+        public static TSource? SingleOrDefault<TSource>(this IEnumerable<TSource> source)
         {
             if (source == null)
             {
@@ -96,7 +95,7 @@ namespace System.Linq
                 switch (list.Count)
                 {
                     case 0:
-                        return default!;
+                        return default;
                     case 1:
                         return list[0];
                 }
@@ -107,7 +106,7 @@ namespace System.Linq
                 {
                     if (!e.MoveNext())
                     {
-                        return default!;
+                        return default;
                     }
 
                     TSource result = e.Current;
@@ -122,8 +121,7 @@ namespace System.Linq
             return default;
         }
 
-        [return: MaybeNull]
-        public static TSource SingleOrDefault<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
+        public static TSource? SingleOrDefault<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
         {
             if (source == null)
             {
@@ -155,7 +153,7 @@ namespace System.Linq
                 }
             }
 
-            return default!;
+            return default;
         }
     }
 }
index 273a970..7fd6b13 100644 (file)
@@ -17,8 +17,8 @@ namespace System.Buffers
     public readonly partial struct ReadOnlySequence<T>
     {
         // The data is essentially two SequencePositions, however the Start and End SequencePositions are deconstructed to improve packing.
-        [AllowNull] private readonly object? _startObject;
-        [AllowNull] private readonly object? _endObject;
+        private readonly object? _startObject;
+        private readonly object? _endObject;
         private readonly int _startInteger;
         private readonly int _endInteger;
 
index c8d7a3c..34e35f7 100644 (file)
@@ -12,10 +12,10 @@ namespace System.Net.Http.Json
         public static System.Threading.Tasks.Task<object?> GetFromJsonAsync(this System.Net.Http.HttpClient client, string? requestUri, System.Type type, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
         public static System.Threading.Tasks.Task<object?> GetFromJsonAsync(this System.Net.Http.HttpClient client, System.Uri? requestUri, System.Type type, System.Text.Json.JsonSerializerOptions? options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
         public static System.Threading.Tasks.Task<object?> GetFromJsonAsync(this System.Net.Http.HttpClient client, System.Uri? requestUri, System.Type type, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
-        public static System.Threading.Tasks.Task<TValue> GetFromJsonAsync<TValue>(this System.Net.Http.HttpClient client, string? requestUri, System.Text.Json.JsonSerializerOptions? options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
-        public static System.Threading.Tasks.Task<TValue> GetFromJsonAsync<TValue>(this System.Net.Http.HttpClient client, string? requestUri, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
-        public static System.Threading.Tasks.Task<TValue> GetFromJsonAsync<TValue>(this System.Net.Http.HttpClient client, System.Uri? requestUri, System.Text.Json.JsonSerializerOptions? options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
-        public static System.Threading.Tasks.Task<TValue> GetFromJsonAsync<TValue>(this System.Net.Http.HttpClient client, System.Uri? requestUri, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
+        public static System.Threading.Tasks.Task<TValue?> GetFromJsonAsync<TValue>(this System.Net.Http.HttpClient client, string? requestUri, System.Text.Json.JsonSerializerOptions? options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
+        public static System.Threading.Tasks.Task<TValue?> GetFromJsonAsync<TValue>(this System.Net.Http.HttpClient client, string? requestUri, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
+        public static System.Threading.Tasks.Task<TValue?> GetFromJsonAsync<TValue>(this System.Net.Http.HttpClient client, System.Uri? requestUri, System.Text.Json.JsonSerializerOptions? options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
+        public static System.Threading.Tasks.Task<TValue?> GetFromJsonAsync<TValue>(this System.Net.Http.HttpClient client, System.Uri? requestUri, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
         public static System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> PostAsJsonAsync<TValue>(this System.Net.Http.HttpClient client, string? requestUri, TValue value, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
         public static System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> PostAsJsonAsync<TValue>(this System.Net.Http.HttpClient client, string? requestUri, TValue value, System.Threading.CancellationToken cancellationToken) { throw null; }
         public static System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> PostAsJsonAsync<TValue>(this System.Net.Http.HttpClient client, System.Uri? requestUri, TValue value, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
@@ -28,7 +28,7 @@ namespace System.Net.Http.Json
     public static partial class HttpContentJsonExtensions
     {
         public static System.Threading.Tasks.Task<object?> ReadFromJsonAsync(this System.Net.Http.HttpContent content, System.Type type, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
-        public static System.Threading.Tasks.Task<T> ReadFromJsonAsync<T>(this System.Net.Http.HttpContent content, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
+        public static System.Threading.Tasks.Task<T?> ReadFromJsonAsync<T>(this System.Net.Http.HttpContent content, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
     }
     public sealed partial class JsonContent : System.Net.Http.HttpContent
     {
index dd50490..908b5bc 100644 (file)
@@ -34,7 +34,7 @@ namespace System.Net.Http.Json
             return GetFromJsonAsyncCore(taskResponse, type, options, cancellationToken);
         }
 
-        public static Task<TValue> GetFromJsonAsync<TValue>(this HttpClient client, string? requestUri, JsonSerializerOptions? options, CancellationToken cancellationToken = default)
+        public static Task<TValue?> GetFromJsonAsync<TValue>(this HttpClient client, string? requestUri, JsonSerializerOptions? options, CancellationToken cancellationToken = default)
         {
             if (client == null)
             {
@@ -45,7 +45,7 @@ namespace System.Net.Http.Json
             return GetFromJsonAsyncCore<TValue>(taskResponse, options, cancellationToken);
         }
 
-        public static Task<TValue> GetFromJsonAsync<TValue>(this HttpClient client, Uri? requestUri, JsonSerializerOptions? options, CancellationToken cancellationToken = default)
+        public static Task<TValue?> GetFromJsonAsync<TValue>(this HttpClient client, Uri? requestUri, JsonSerializerOptions? options, CancellationToken cancellationToken = default)
         {
             if (client == null)
             {
@@ -62,10 +62,10 @@ namespace System.Net.Http.Json
         public static Task<object?> GetFromJsonAsync(this HttpClient client, Uri? requestUri, Type type, CancellationToken cancellationToken = default)
             => client.GetFromJsonAsync(requestUri, type, options: null, cancellationToken);
 
-        public static Task<TValue> GetFromJsonAsync<TValue>(this HttpClient client, string? requestUri, CancellationToken cancellationToken = default)
+        public static Task<TValue?> GetFromJsonAsync<TValue>(this HttpClient client, string? requestUri, CancellationToken cancellationToken = default)
             => client.GetFromJsonAsync<TValue>(requestUri, options: null, cancellationToken);
 
-        public static Task<TValue> GetFromJsonAsync<TValue>(this HttpClient client, Uri? requestUri, CancellationToken cancellationToken = default)
+        public static Task<TValue?> GetFromJsonAsync<TValue>(this HttpClient client, Uri? requestUri, CancellationToken cancellationToken = default)
             => client.GetFromJsonAsync<TValue>(requestUri, options: null, cancellationToken);
 
         private static async Task<object?> GetFromJsonAsyncCore(Task<HttpResponseMessage> taskResponse, Type type, JsonSerializerOptions? options, CancellationToken cancellationToken)
@@ -80,7 +80,7 @@ namespace System.Net.Http.Json
             }
         }
 
-        private static async Task<T> GetFromJsonAsyncCore<T>(Task<HttpResponseMessage> taskResponse, JsonSerializerOptions? options, CancellationToken cancellationToken)
+        private static async Task<T?> GetFromJsonAsyncCore<T>(Task<HttpResponseMessage> taskResponse, JsonSerializerOptions? options, CancellationToken cancellationToken)
         {
             using (HttpResponseMessage response = await taskResponse.ConfigureAwait(false))
             {
index 753c031..e73c6fb 100644 (file)
@@ -21,7 +21,7 @@ namespace System.Net.Http.Json
             return ReadFromJsonAsyncCore(content, type, sourceEncoding, options, cancellationToken);
         }
 
-        public static Task<T> ReadFromJsonAsync<T>(this HttpContent content, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default)
+        public static Task<T?> ReadFromJsonAsync<T>(this HttpContent content, JsonSerializerOptions? options = null, CancellationToken cancellationToken = default)
         {
             ValidateContent(content);
             Debug.Assert(content.Headers.ContentType != null);
@@ -46,7 +46,7 @@ namespace System.Net.Http.Json
             }
         }
 
-        private static async Task<T> ReadFromJsonAsyncCore<T>(HttpContent content, Encoding? sourceEncoding, JsonSerializerOptions? options, CancellationToken cancellationToken)
+        private static async Task<T?> ReadFromJsonAsyncCore<T>(HttpContent content, Encoding? sourceEncoding, JsonSerializerOptions? options, CancellationToken cancellationToken)
         {
             Stream contentStream = await ReadHttpContentStreamAsync(content, cancellationToken).ConfigureAwait(false);
 
index 415ccbd..9e1b3a3 100644 (file)
@@ -452,7 +452,7 @@ namespace HttpStress
 
         private class StructuralEqualityComparer<T> : IEqualityComparer<T> where T : IStructuralEquatable
         {
-            public bool Equals([AllowNull] T left, [AllowNull] T right) => left != null && left.Equals(right, StructuralComparisons.StructuralEqualityComparer);
+            public bool Equals(T? left, T? right) => left != null && left.Equals(right, StructuralComparisons.StructuralEqualityComparer);
             public int GetHashCode(T value) => value.GetHashCode(StructuralComparisons.StructuralEqualityComparer);
         }
     }
index 7bfa4f7..8797f31 100644 (file)
@@ -133,7 +133,7 @@ namespace System.Security.Authentication.ExtendedProtection
         /// <summary>
         /// Normalize, check for duplicates, and add if the value is unique.
         /// </summary>
-        private void AddIfNew([MaybeNull]string serviceName)
+        private void AddIfNew(string serviceName)
         {
             if (string.IsNullOrEmpty(serviceName))
             {
@@ -164,6 +164,7 @@ namespace System.Security.Authentication.ExtendedProtection
         // prefix/host:port
         // prefix/host/DistinguishedName
         // prefix/host:port/DistinguishedName
+        [return: NotNullIfNotNull("inputServiceName")]
         private static string? NormalizeServiceName(string? inputServiceName)
         {
             if (string.IsNullOrWhiteSpace(inputServiceName))
index 93cd10b..3c0c0a4 100644 (file)
@@ -114,7 +114,7 @@ namespace System.Collections.ObjectModel
                 }
             }
 
-            item = default(TItem)!;
+            item = default;
             return false;
         }
 
index 539e5fd..dacc4fa 100644 (file)
@@ -23,7 +23,10 @@ namespace System
     public delegate void Action<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, in T10, in T11, in T12, in T13, in T14, in T15>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15);
     public delegate void Action<in T1, in T2, in T3, in T4, in T5, in T6, in T7, in T8, in T9, in T10, in T11, in T12, in T13, in T14, in T15, in T16>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16);
 
-    public delegate int Comparison<in T>([AllowNull] T x, [AllowNull] T y);
+    // This should probably technically be T? rather than T to match `IComparer<T>`.  However, the use cases are generally different,
+    // with Comparison<T> typically being used via a lambda, with the T inferred from the type of the collection being sorted,
+    // and forcing nullable warnings onto all such usage leads to many spurious warnings.
+    public delegate int Comparison<in T>(T x, T y);
 
     public delegate TOutput Converter<in TInput, out TOutput>(TInput input);
 
index 030e8e2..1e0fca6 100644 (file)
@@ -752,8 +752,7 @@ namespace System
             }
         }
 
-        [return: MaybeNull]
-        public static T Find<T>(T[] array, Predicate<T> match)
+        public static T? Find<T>(T[] array, Predicate<T> match)
         {
             if (array == null)
             {
@@ -772,7 +771,7 @@ namespace System
                     return array[i];
                 }
             }
-            return default!;
+            return default;
         }
 
         public static T[] FindAll<T>(T[] array, Predicate<T> match)
@@ -849,8 +848,7 @@ namespace System
             return -1;
         }
 
-        [return: MaybeNull]
-        public static T FindLast<T>(T[] array, Predicate<T> match)
+        public static T? FindLast<T>(T[] array, Predicate<T> match)
         {
             if (array == null)
             {
@@ -869,7 +867,7 @@ namespace System
                     return array[i];
                 }
             }
-            return default!;
+            return default;
         }
 
         public static int FindLastIndex<T>(T[] array, Predicate<T> match)
index 76f0ea2..08eb093 100644 (file)
@@ -689,7 +689,7 @@ namespace System.Collections.Concurrent
                 // check and this check, another item could have arrived).
                 if (head._nextSegment == null)
                 {
-                    item = default!;
+                    item = default;
                     return false;
                 }
 
@@ -783,7 +783,7 @@ namespace System.Collections.Concurrent
                 // and we'll traverse to that segment.
             }
 
-            result = default!;
+            result = default;
             return false;
         }
 
index 56a758e..1cd8235 100644 (file)
@@ -173,7 +173,7 @@ namespace System.Collections.Concurrent
                     int currentTail = Volatile.Read(ref _headAndTail.Tail);
                     if (currentTail - currentHead <= 0 || (frozen && (currentTail - FreezeOffset - currentHead <= 0)))
                     {
-                        item = default!;
+                        item = default;
                         return false;
                     }
 
@@ -234,7 +234,7 @@ namespace System.Collections.Concurrent
                     int currentTail = Volatile.Read(ref _headAndTail.Tail);
                     if (currentTail - currentHead <= 0 || (frozen && (currentTail - FreezeOffset - currentHead <= 0)))
                     {
-                        result = default!;
+                        result = default;
                         return false;
                     }
 
@@ -311,7 +311,7 @@ namespace System.Collections.Concurrent
         internal struct Slot
         {
             /// <summary>The item.</summary>
-            [AllowNull, MaybeNull] public T Item; // SOS's ThreadPool command depends on this being at the beginning of the struct when T is a reference type
+            public T? Item; // SOS's ThreadPool command depends on this being at the beginning of the struct when T is a reference type
             /// <summary>The sequence number for this slot, used to synchronize between enqueuers and dequeuers.</summary>
             public int SequenceNumber;
         }
index 0b4f12d..2ee414a 100644 (file)
@@ -21,7 +21,7 @@ namespace System.Collections.Generic
             return new ComparisonComparer<T>(comparison);
         }
 
-        public abstract int Compare([AllowNull] T x, [AllowNull] T y);
+        public abstract int Compare(T? x, T? y);
 
         int IComparer.Compare(object? x, object? y)
         {
@@ -42,10 +42,7 @@ namespace System.Collections.Generic
             _comparison = comparison;
         }
 
-        public override int Compare([AllowNull] T x, [AllowNull] T y)
-        {
-            return _comparison(x, y);
-        }
+        public override int Compare(T? x, T? y) => _comparison(x!, y!);
     }
 
     // Note: although there is a lot of shared code in the following
@@ -58,7 +55,7 @@ namespace System.Collections.Generic
     // Needs to be public to support binary serialization compatibility
     public sealed partial class GenericComparer<T> : Comparer<T> where T : IComparable<T>
     {
-        public override int Compare([AllowNull] T x, [AllowNull] T y)
+        public override int Compare(T? x, T? y)
         {
             if (x != null)
             {
@@ -106,7 +103,7 @@ namespace System.Collections.Generic
     // Needs to be public to support binary serialization compatibility
     public sealed partial class ObjectComparer<T> : Comparer<T>
     {
-        public override int Compare([AllowNull] T x, [AllowNull] T y)
+        public override int Compare(T? x, T? y)
         {
             return System.Collections.Comparer.Default.Compare(x, y);
         }
index 6c5682e..39245df 100644 (file)
@@ -1461,7 +1461,7 @@ namespace System.Collections.Generic
                 private readonly Dictionary<TKey, TValue> _dictionary;
                 private int _index;
                 private readonly int _version;
-                [AllowNull, MaybeNull] private TKey _currentKey;
+                private TKey? _currentKey;
 
                 internal Enumerator(Dictionary<TKey, TValue> dictionary)
                 {
@@ -1653,7 +1653,7 @@ namespace System.Collections.Generic
                 private readonly Dictionary<TKey, TValue> _dictionary;
                 private int _index;
                 private readonly int _version;
-                [AllowNull, MaybeNull] private TValue _currentValue;
+                private TValue? _currentValue;
 
                 internal Enumerator(Dictionary<TKey, TValue> dictionary)
                 {
index 6b6830e..180bea6 100644 (file)
@@ -13,7 +13,7 @@ namespace System.Collections.Generic
     {
         // public static EqualityComparer<T> Default is runtime-specific
 
-        public abstract bool Equals([AllowNull] T x, [AllowNull] T y);
+        public abstract bool Equals(T? x, T? y);
         public abstract int GetHashCode([DisallowNull] T obj);
 
         int IEqualityComparer.GetHashCode(object? obj)
@@ -42,7 +42,7 @@ namespace System.Collections.Generic
     public sealed partial class GenericEqualityComparer<T> : EqualityComparer<T> where T : IEquatable<T>
     {
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public override bool Equals([AllowNull] T x, [AllowNull] T y)
+        public override bool Equals(T? x, T? y)
         {
             if (x != null)
             {
@@ -100,7 +100,7 @@ namespace System.Collections.Generic
     public sealed partial class ObjectEqualityComparer<T> : EqualityComparer<T>
     {
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public override bool Equals([AllowNull] T x, [AllowNull] T y)
+        public override bool Equals(T? x, T? y)
         {
             if (x != null)
             {
index 82394ef..59a9b90 100644 (file)
@@ -14,6 +14,6 @@ namespace System.Collections.Generic
         // value less than zero if x is less than y, zero if x is equal to y, or a
         // value greater than zero if x is greater than y.
         //
-        int Compare([AllowNull] T x, [AllowNull] T y);
+        int Compare(T? x, T? y);
     }
 }
index b83b54e..19545c6 100644 (file)
@@ -10,7 +10,7 @@ namespace System.Collections.Generic
     // It is used in Dictionary class.
     public interface IEqualityComparer<in T>
     {
-        bool Equals([AllowNull] T x, [AllowNull] T y);
+        bool Equals(T? x, T? y);
         int GetHashCode([DisallowNull] T obj);
     }
 }
index 13ab166..6da36e0 100644 (file)
@@ -412,8 +412,7 @@ namespace System.Collections.Generic
         public bool Exists(Predicate<T> match)
             => FindIndex(match) != -1;
 
-        [return: MaybeNull]
-        public T Find(Predicate<T> match)
+        public T? Find(Predicate<T> match)
         {
             if (match == null)
             {
@@ -427,7 +426,7 @@ namespace System.Collections.Generic
                     return _items[i];
                 }
             }
-            return default!;
+            return default;
         }
 
         public List<T> FindAll(Predicate<T> match)
@@ -479,8 +478,7 @@ namespace System.Collections.Generic
             return -1;
         }
 
-        [return: MaybeNull]
-        public T FindLast(Predicate<T> match)
+        public T? FindLast(Predicate<T> match)
         {
             if (match == null)
             {
@@ -494,7 +492,7 @@ namespace System.Collections.Generic
                     return _items[i];
                 }
             }
-            return default!;
+            return default;
         }
 
         public int FindLastIndex(Predicate<T> match)
@@ -1077,7 +1075,7 @@ namespace System.Collections.Generic
             private readonly List<T> _list;
             private int _index;
             private readonly int _version;
-            [AllowNull, MaybeNull] private T _current;
+            private T? _current;
 
             internal Enumerator(List<T> list)
             {
index 2f2676a..fcafafe 100644 (file)
@@ -244,7 +244,7 @@ namespace System.Collections.ObjectModel
             {
                 ThrowHelper.IfNullAndNullsAreIllegalThenThrow<T>(value, ExceptionArgument.value);
 
-                T item = default!;
+                T? item = default;
 
                 try
                 {
@@ -285,7 +285,7 @@ namespace System.Collections.ObjectModel
             }
             ThrowHelper.IfNullAndNullsAreIllegalThenThrow<T>(value, ExceptionArgument.value);
 
-            T item = default!;
+            T? item = default;
 
             try
             {
@@ -327,7 +327,7 @@ namespace System.Collections.ObjectModel
             }
             ThrowHelper.IfNullAndNullsAreIllegalThenThrow<T>(value, ExceptionArgument.value);
 
-            T item = default!;
+            T? item = default;
 
             try
             {
index 6c6e22b..6085322 100644 (file)
@@ -1363,14 +1363,14 @@ namespace System.Diagnostics.Tracing
                 if (m_etwProvider != null)
                 {
                     m_etwProvider.Dispose();
-                    m_etwProvider = null!; // TODO-NULLABLE: Avoid nulling out in Dispose
+                    m_etwProvider = null!;
                 }
 #endif
 #if FEATURE_PERFTRACING
                 if (m_eventPipeProvider != null)
                 {
                     m_eventPipeProvider.Dispose();
-                    m_eventPipeProvider = null!; // TODO-NULLABLE: Avoid nulling out in Dispose
+                    m_eventPipeProvider = null!;
                 }
 #endif
             }
index 3c0f50b..3599bbd 100644 (file)
@@ -33,6 +33,6 @@ namespace System
         // if this is equal to object, or a value greater than zero
         // if this is greater than object.
         //
-        int CompareTo([AllowNull] T other);
+        int CompareTo(T? other);
     }
 }
index 1edba44..89f0771 100644 (file)
@@ -7,6 +7,6 @@ namespace System
 {
     public interface IEquatable<T> // invariant due to questionable semantics around equality and inheritance
     {
-        bool Equals([AllowNull] T other);
+        bool Equals(T? other);
     }
 }
index 4fcfbc9..ac676de 100644 (file)
@@ -195,7 +195,7 @@ namespace System
         private Func<T>? _factory;
 
         // _value eventually stores the lazily created value. It is valid when _state = null.
-        private T _value = default!;
+        private T? _value;
 
         /// <summary>
         /// Initializes a new instance of the <see cref="System.Lazy{T}"/> class that
@@ -447,14 +447,13 @@ namespace System
         }
 
         /// <summary>Gets the value of the Lazy&lt;T&gt; for debugging display purposes.</summary>
-        [MaybeNull]
-        internal T ValueForDebugDisplay
+        internal T? ValueForDebugDisplay
         {
             get
             {
                 if (!IsValueCreated)
                 {
-                    return default!;
+                    return default;
                 }
                 return _value;
             }
@@ -503,7 +502,7 @@ namespace System
         /// from initialization delegate.
         /// </remarks>
         [DebuggerBrowsable(DebuggerBrowsableState.Never)]
-        public T Value => _state == null ? _value : CreateValue();
+        public T Value => _state == null ? _value! : CreateValue();
     }
 
     /// <summary>A debugger view of the Lazy&lt;T&gt; to surface additional debugging properties and
@@ -524,8 +523,7 @@ namespace System
         public bool IsValueCreated => _lazy.IsValueCreated;
 
         /// <summary>Returns the value of the Lazy object.</summary>
-        [MaybeNull]
-        public T Value => _lazy.ValueForDebugDisplay;
+        public T? Value => _lazy.ValueForDebugDisplay;
 
         /// <summary>Returns the execution mode of the Lazy object</summary>
         public LazyThreadSafetyMode? Mode => _lazy.Mode;
index baf733b..c43899c 100644 (file)
@@ -157,11 +157,11 @@ namespace System.Resources
                     // Close the stream in a thread-safe way.  This fix means
                     // that we may call Close n times, but that's safe.
                     BinaryReader copyOfStore = _store;
-                    _store = null!; // TODO-NULLABLE: Avoid nulling out in Dispose
+                    _store = null!;
                     if (copyOfStore != null)
                         copyOfStore.Close();
                 }
-                _store = null!; // TODO-NULLABLE: Avoid nulling out in Dispose
+                _store = null!;
                 _namePositions = null;
                 _nameHashes = null;
                 _ums = null;
index dbb3342..6ad05b6 100644 (file)
@@ -29,7 +29,7 @@ namespace System.Resources
     public class ResourceSet : IDisposable, IEnumerable
     {
         protected IResourceReader Reader = null!;
-        internal Hashtable? Table; // TODO-NULLABLE: Avoid nulling out in Dispose
+        internal Hashtable? Table;
 
         private Hashtable? _caseInsensitiveTable;  // For case-insensitive lookups.
 
@@ -90,11 +90,11 @@ namespace System.Resources
             {
                 // Close the Reader in a thread-safe way.
                 IResourceReader? copyOfReader = Reader;
-                Reader = null!; // TODO-NULLABLE: Avoid nulling out in Dispose
+                Reader = null!;
                 if (copyOfReader != null)
                     copyOfReader.Close();
             }
-            Reader = null!; // TODO-NULLABLE: Avoid nulling out in Dispose
+            Reader = null!;
             _caseInsensitiveTable = null;
             Table = null;
         }
index c00ebb2..f6de75e 100644 (file)
@@ -175,12 +175,12 @@ namespace System.Resources
         // for arbitrarily long times, since the object is usually a string
         // literal that will live for the lifetime of the appdomain.  The
         // value is a ResourceLocator instance, which might cache the object.
-        private Dictionary<string, ResourceLocator>? _resCache; // TODO-NULLABLE: Avoid nulling out in Dispose
+        private Dictionary<string, ResourceLocator>? _resCache;
 
 
         // For our special load-on-demand reader, cache the cast.  The
         // RuntimeResourceSet's implementation knows how to treat this reader specially.
-        private ResourceReader? _defaultReader; // TODO-NULLABLE: Avoid nulling out in Dispose
+        private ResourceReader? _defaultReader;
 
         // This is a lookup table for case-insensitive lookups, and may be null.
         // Consider always using a case-insensitive resource cache, as we don't
index 363371f..1c654cd 100644 (file)
@@ -45,7 +45,7 @@ namespace System.Runtime.CompilerServices
         /// <typeparam name="TResult">Specifies the result type.</typeparam>
         /// <param name="result">The result for the task.</param>
         /// <returns>The cacheable task.</returns>
-        internal static Task<TResult> CreateCacheableTask<TResult>([AllowNull] TResult result) =>
+        internal static Task<TResult> CreateCacheableTask<TResult>(TResult? result) =>
             new Task<TResult>(false, result, (TaskCreationOptions)InternalTaskOptions.DoNotDispose, default);
 
         /// <summary>Creates an array of cached tasks for the values in the range [INCLUSIVE_MIN,EXCLUSIVE_MAX).</summary>
index 4a3d1df..70ac433 100644 (file)
@@ -292,8 +292,7 @@ namespace System.Runtime.CompilerServices
             /// <summary>A delegate to the <see cref="MoveNext()"/> method.</summary>
             private Action? _moveNextAction;
             /// <summary>The state machine itself.</summary>
-            [AllowNull, MaybeNull]
-            public TStateMachine StateMachine = default; // mutable struct; do not make this readonly. SOS DumpAsync command depends on this name.
+            public TStateMachine? StateMachine; // mutable struct; do not make this readonly. SOS DumpAsync command depends on this name.
             /// <summary>Captured ExecutionContext with which to invoke <see cref="MoveNextAction"/>; may be null.</summary>
             public ExecutionContext? Context;
 
@@ -428,7 +427,7 @@ namespace System.Runtime.CompilerServices
         /// <summary>Completes the already initialized task with the specified result.</summary>
         /// <param name="result">The result to use to complete the task.</param>
         /// <param name="task">The task to complete.</param>
-        internal static void SetExistingTaskResult(Task<TResult> task, [AllowNull] TResult result)
+        internal static void SetExistingTaskResult(Task<TResult> task, TResult? result)
         {
             Debug.Assert(task != null, "Expected non-null task");
 
index 1c88475..846c649 100644 (file)
@@ -364,8 +364,7 @@ namespace System.Runtime.CompilerServices
             /// <summary>If this box is stored in the cache, the next box in the cache.</summary>
             private StateMachineBox<TStateMachine>? _next;
             /// <summary>The state machine itself.</summary>
-            [AllowNull, MaybeNull]
-            public TStateMachine StateMachine = default;
+            public TStateMachine? StateMachine;
 
             /// <summary>Gets a box object to use for an operation.  This may be a reused, pooled object, or it may be new.</summary>
             [MethodImpl(MethodImplOptions.AggressiveInlining)] // only one caller
index 8d3b9ad..d5caca5 100644 (file)
@@ -552,7 +552,7 @@ namespace System.Runtime.CompilerServices
                 }
 
                 key = default;
-                value = default!;
+                value = default;
                 return false;
             }
 
index 477717e..ed7d492 100644 (file)
@@ -52,7 +52,7 @@ namespace System.Runtime.InteropServices
         }
 
         [SupportedOSPlatform("windows")]
-        public static TWrapper CreateWrapperOfType<T, TWrapper>([AllowNull] T o)
+        public static TWrapper CreateWrapperOfType<T, TWrapper>(T? o)
         {
             throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
         }
@@ -122,7 +122,7 @@ namespace System.Runtime.InteropServices
         }
 
         [SupportedOSPlatform("windows")]
-        public static void GetNativeVariantForObject<T>([AllowNull] T obj, IntPtr pDstNativeVariant)
+        public static void GetNativeVariantForObject<T>(T? obj, IntPtr pDstNativeVariant)
         {
             throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
         }
@@ -146,8 +146,7 @@ namespace System.Runtime.InteropServices
         }
 
         [SupportedOSPlatform("windows")]
-        [return: MaybeNull]
-        public static T GetObjectForNativeVariant<T>(IntPtr pSrcNativeVariant)
+        public static T? GetObjectForNativeVariant<T>(IntPtr pSrcNativeVariant)
         {
             throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
         }
index 40c0396..7a2e976 100644 (file)
@@ -572,8 +572,7 @@ namespace System.Runtime.InteropServices
             PtrToStructure(ptr, (object)structure!);
         }
 
-        [return: MaybeNull]
-        public static T PtrToStructure<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]T>(IntPtr ptr) => (T)PtrToStructure(ptr, typeof(T))!;
+        public static T? PtrToStructure<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]T>(IntPtr ptr) => (T)PtrToStructure(ptr, typeof(T))!;
 
         public static void DestroyStructure<T>(IntPtr ptr) => DestroyStructure(ptr, typeof(T));
 
index 2da00f9..4b8c912 100644 (file)
@@ -75,7 +75,7 @@ namespace System
             }
 
             [MethodImpl(MethodImplOptions.AggressiveInlining)]
-            public int CompareTo([AllowNull] T other) => _comparer.Compare(_value, other);
+            public int CompareTo(T? other) => _comparer.Compare(_value, other);
         }
     }
 }
index 1a81b1d..288ffbd 100644 (file)
@@ -86,8 +86,8 @@ namespace System.Threading
 
     public readonly struct AsyncLocalValueChangedArgs<T>
     {
-        [MaybeNull] public T PreviousValue { get; }
-        [MaybeNull] public T CurrentValue { get; }
+        public T? PreviousValue { get; }
+        public T? CurrentValue { get; }
 
         //
         // If the value changed because we changed to a different ExecutionContext, this is true.  If it changed
@@ -95,7 +95,7 @@ namespace System.Threading
         //
         public bool ThreadContextChanged { get; }
 
-        internal AsyncLocalValueChangedArgs([AllowNull] T previousValue, [AllowNull] T currentValue, bool contextChanged)
+        internal AsyncLocalValueChangedArgs(T? previousValue, T? currentValue, bool contextChanged)
         {
             PreviousValue = previousValue!;
             CurrentValue = currentValue!;
index b993f26..32dceb9 100644 (file)
@@ -59,7 +59,7 @@ namespace System.Threading.Tasks
     public class Task<TResult> : Task
     {
         // The value itself, if set.
-        [MaybeNull, AllowNull] internal TResult m_result = default!;
+        internal TResult? m_result;
 
         private static readonly TaskFactory<TResult> s_Factory = new TaskFactory<TResult>();
 
@@ -93,7 +93,7 @@ namespace System.Threading.Tasks
             m_result = result;
         }
 
-        internal Task(bool canceled, [AllowNull] TResult result, TaskCreationOptions creationOptions, CancellationToken ct)
+        internal Task(bool canceled, TResult? result, TaskCreationOptions creationOptions, CancellationToken ct)
             : base(canceled, creationOptions, ct)
         {
             if (!canceled)
@@ -364,7 +364,7 @@ namespace System.Threading.Tasks
 
 
         // internal helper function breaks out logic used by TaskCompletionSource
-        internal bool TrySetResult([AllowNull] TResult result)
+        internal bool TrySetResult(TResult? result)
         {
             Debug.Assert(m_action == null, "Task<T>.TrySetResult(): non-null m_action");
 
@@ -1357,7 +1357,7 @@ namespace System.Threading.Tasks
             m_task = task;
         }
 
-        [MaybeNull] public TResult Result => m_task.Status == TaskStatus.RanToCompletion ? m_task.Result : default!;
+        public TResult? Result => m_task.Status == TaskStatus.RanToCompletion ? m_task.Result : default;
         public object? AsyncState => m_task.AsyncState;
         public TaskCreationOptions CreationOptions => m_task.CreationOptions;
         public Exception? Exception => m_task.Exception;
index f067ffd..b1ef1c1 100644 (file)
@@ -239,7 +239,7 @@ namespace System.Threading.Tasks
 
             if (first == segment.m_state.m_last)
             {
-                result = default!;
+                result = default;
                 return false;
             }
 
index 8a4a2db..b9caa53 100644 (file)
@@ -31,7 +31,7 @@ namespace System.Threading.Tasks.Sources
         /// <summary>Whether the current operation has completed.</summary>
         private bool _completed;
         /// <summary>The result with which the operation succeeded, or the default value if it hasn't yet completed or failed.</summary>
-        [AllowNull, MaybeNull] private TResult _result;
+        private TResult? _result;
         /// <summary>The exception with which the operation failed, or null if it hasn't yet completed or completed successfully.</summary>
         private ExceptionDispatchInfo? _error;
         /// <summary>The current version of this value, used to help prevent misuse.</summary>
@@ -98,7 +98,7 @@ namespace System.Threading.Tasks.Sources
             }
 
             _error?.Throw();
-            return _result;
+            return _result!;
         }
 
         /// <summary>Schedules the continuation action for this operation.</summary>
index 7a04c04..afc8f5a 100644 (file)
@@ -445,7 +445,7 @@ namespace System.Threading.Tasks
         /// <summary>null if <see cref="_result"/> has the result, otherwise a <see cref="Task{TResult}"/> or a <see cref="IValueTaskSource{TResult}"/>.</summary>
         internal readonly object? _obj;
         /// <summary>The result to be used if the operation completed successfully synchronously.</summary>
-        [AllowNull] internal readonly TResult _result;
+        internal readonly TResult? _result;
         /// <summary>Opaque value passed through to the <see cref="IValueTaskSource{TResult}"/>.</summary>
         internal readonly short _token;
         /// <summary>true to continue on the captured context; otherwise, false.</summary>
@@ -508,7 +508,7 @@ namespace System.Threading.Tasks
         /// <param name="token">The token.</param>
         /// <param name="continueOnCapturedContext">true to continue on captured context; otherwise, false.</param>
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        private ValueTask(object? obj, TResult result, short token, bool continueOnCapturedContext)
+        private ValueTask(object? obj, TResult? result, short token, bool continueOnCapturedContext)
         {
             _obj = obj;
             _result = result;
@@ -556,7 +556,7 @@ namespace System.Threading.Tasks
 
             if (obj == null)
             {
-                return AsyncTaskMethodBuilder<TResult>.GetTaskForResult(_result);
+                return AsyncTaskMethodBuilder<TResult>.GetTaskForResult(_result!);
             }
 
             if (obj is Task<TResult> t)
@@ -781,7 +781,7 @@ namespace System.Threading.Tasks
 
                 if (obj == null)
                 {
-                    return _result;
+                    return _result!;
                 }
 
                 if (obj is Task<TResult> t)
index 2d0c67c..4d7188e 100644 (file)
@@ -305,8 +305,7 @@ namespace System.Threading
             }
         }
 
-        [return: MaybeNull]
-        private T GetValueSlow()
+        private T? GetValueSlow()
         {
             // If the object has been disposed, the id will be -1.
             int id = ~_idComplement;
@@ -538,8 +537,7 @@ namespace System.Threading
 
         /// <summary>Gets the value of the ThreadLocal&lt;T&gt; for debugging display purposes. It takes care of getting
         /// the value for the current thread in the ThreadLocal mode.</summary>
-        [MaybeNull]
-        internal T ValueForDebugDisplay
+        internal T? ValueForDebugDisplay
         {
             get
             {
@@ -548,7 +546,7 @@ namespace System.Threading
 
                 LinkedSlot? slot;
                 if (slotArray == null || id >= slotArray.Length || (slot = slotArray[id].Value) == null || !_initialized)
-                    return default!;
+                    return default;
                 return slot._value;
             }
         }
@@ -672,7 +670,7 @@ namespace System.Threading
             internal volatile LinkedSlotVolatile[]? _slotArray;
 
             // The value for this slot.
-            [AllowNull, MaybeNull] internal T _value = default;
+            internal T? _value;
         }
 
         /// <summary>
@@ -804,8 +802,7 @@ namespace System.Threading
         public bool IsValueCreated => _tlocal.IsValueCreated;
 
         /// <summary>Returns the value of the ThreadLocal object.</summary>
-        [MaybeNull]
-        public T Value => _tlocal.ValueForDebugDisplay;
+        public T? Value => _tlocal.ValueForDebugDisplay;
 
         /// <summary>Return all values for all threads that have accessed this instance.</summary>
         public List<T>? Values => _tlocal.ValuesForDebugDisplay;
index 491f7ac..d28dcd8 100644 (file)
@@ -304,7 +304,7 @@ namespace System
             {
                 for (i = 0; i < e.Length; i++)
                     if (e[i] != null)
-                        ret[cnt++] = e[i]!;  // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
+                        ret[cnt++] = e[i]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
             }
 
             // Copy the Types
@@ -312,7 +312,7 @@ namespace System
             {
                 for (i = 0; i < t.Length; i++)
                     if (t[i] != null)
-                        ret[cnt++] = t[i]!;  // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
+                        ret[cnt++] = t[i]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
             }
 
             return ret;
index aaec606..99545a0 100644 (file)
@@ -13,8 +13,7 @@ namespace System.Reflection.Internal
     /// </summary>
     internal static class EnumerableExtensions
     {
-        [return: MaybeNull]
-        public static T FirstOrDefault<T>(this ImmutableArray<T> collection, Func<T, bool> predicate)
+        public static T? FirstOrDefault<T>(this ImmutableArray<T> collection, Func<T, bool> predicate)
         {
             foreach (var item in collection)
             {
@@ -24,7 +23,7 @@ namespace System.Reflection.Internal
                 }
             }
 
-            return default!;
+            return default;
         }
 
         // used only in debugger display so we needn't get fancy with optimizations.
index 7c9d4fc..f495874 100644 (file)
@@ -17,10 +17,9 @@ namespace System.Runtime.CompilerServices
         public unsafe static ref T AsRef<T>(void* source) { throw null; }
         public static ref T AsRef<T>(in T source) { throw null; }
 #if NETSTANDARD2_1
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
         [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull("o")]
 #endif
-        public static T As<T>(object? o) where T : class? { throw null; }
+        public static T? As<T>(object? o) where T : class? { throw null; }
         public static ref TTo As<TFrom, TTo>(ref TFrom source) { throw null; }
         public static System.IntPtr ByteOffset<T>(ref T origin, ref T target) { throw null; }
         public static void CopyBlock(ref byte destination, ref byte source, uint byteCount) { }
index 67b487c..7bc7065 100644 (file)
@@ -500,7 +500,7 @@ namespace System.Runtime.InteropServices
         [return: System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute("o")]
         public static object? CreateWrapperOfType(object? o, System.Type t) { throw null; }
         [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
-        public static TWrapper CreateWrapperOfType<T, TWrapper>([System.Diagnostics.CodeAnalysis.AllowNullAttribute] T o) { throw null; }
+        public static TWrapper CreateWrapperOfType<T, TWrapper>(T? o) { throw null; }
         [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
         public static void DestroyStructure(System.IntPtr ptr, System.Type structuretype) { }
         public static void DestroyStructure<T>(System.IntPtr ptr) { }
@@ -548,7 +548,7 @@ namespace System.Runtime.InteropServices
         public static void GetNativeVariantForObject(object? obj, System.IntPtr pDstNativeVariant) { }
         [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
         [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
-        public static void GetNativeVariantForObject<T>([System.Diagnostics.CodeAnalysis.AllowNullAttribute] T obj, System.IntPtr pDstNativeVariant) { }
+        public static void GetNativeVariantForObject<T>(T? obj, System.IntPtr pDstNativeVariant) { }
         [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
         public static object GetObjectForIUnknown(System.IntPtr pUnk) { throw null; }
         [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
@@ -556,8 +556,7 @@ namespace System.Runtime.InteropServices
         public static object? GetObjectForNativeVariant(System.IntPtr pSrcNativeVariant) { throw null; }
         [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
         [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static T GetObjectForNativeVariant<T>(System.IntPtr pSrcNativeVariant) { throw null; }
+        public static T? GetObjectForNativeVariant<T>(System.IntPtr pSrcNativeVariant) { throw null; }
         [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
         [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
         public static object?[] GetObjectsForNativeVariants(System.IntPtr aSrcNativeVariant, int cVars) { throw null; }
@@ -594,8 +593,7 @@ namespace System.Runtime.InteropServices
         public static void PtrToStructure(System.IntPtr ptr, object structure) { }
         [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
         public static object? PtrToStructure(System.IntPtr ptr, System.Type structureType) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static T PtrToStructure<T>(System.IntPtr ptr) { throw null; }
+        public static T? PtrToStructure<T>(System.IntPtr ptr) { throw null; }
         public static void PtrToStructure<T>(System.IntPtr ptr, [System.Diagnostics.CodeAnalysis.DisallowNullAttribute] T structure) { }
         [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
         public static int QueryInterface(System.IntPtr pUnk, ref System.Guid iid, out System.IntPtr ppv) { throw null; }
index 8ecc282..d4207fb 100644 (file)
@@ -159,7 +159,7 @@ namespace System.Runtime.Serialization.Formatters.Binary
                     {
                         Type type =
                             memberTypes[i] != null ? memberTypes[i] :
-                            memberData[i] != null ? GetType(memberData[i]!) : // TODO-NULLABLE https://github.com/dotnet/roslyn/issues/34644
+                            memberData[i] != null ? GetType(memberData[i]!) : // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
                             Converter.s_typeofObject;
 
                         InternalPrimitiveTypeE code = ToCode(type);
@@ -170,7 +170,7 @@ namespace System.Runtime.Serialization.Formatters.Binary
                             if (memberData[i] != null)
                             {
                                 memberObjectInfos[i] = WriteObjectInfo.Serialize(
-                                    memberData[i]!, // TODO-NULLABLE https://github.com/dotnet/roslyn/issues/34644
+                                    memberData[i]!, // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644)
                                     _surrogates,
                                     _context,
                                     _serObjectInfoInit,
index aaaf4da..8ebce34 100644 (file)
@@ -343,10 +343,8 @@ namespace System
         public static int FindLastIndex<T>(T[] array, int startIndex, int count, System.Predicate<T> match) { throw null; }
         public static int FindLastIndex<T>(T[] array, int startIndex, System.Predicate<T> match) { throw null; }
         public static int FindLastIndex<T>(T[] array, System.Predicate<T> match) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static T FindLast<T>(T[] array, System.Predicate<T> match) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static T Find<T>(T[] array, System.Predicate<T> match) { throw null; }
+        public static T? FindLast<T>(T[] array, System.Predicate<T> match) { throw null; }
+        public static T? Find<T>(T[] array, System.Predicate<T> match) { throw null; }
         public static void ForEach<T>(T[] array, System.Action<T> action) { }
         public System.Collections.IEnumerator GetEnumerator() { throw null; }
         public int GetLength(int dimension) { throw null; }
@@ -816,7 +814,7 @@ namespace System
         public CLSCompliantAttribute(bool isCompliant) { }
         public bool IsCompliant { get { throw null; } }
     }
-    public delegate int Comparison<in T>([System.Diagnostics.CodeAnalysis.AllowNullAttribute] T x, [System.Diagnostics.CodeAnalysis.AllowNullAttribute] T y);
+    public delegate int Comparison<in T>(T x, T y);
     public abstract partial class ContextBoundObject : System.MarshalByRefObject
     {
         protected ContextBoundObject() { }
@@ -2298,7 +2296,7 @@ namespace System
     }
     public partial interface IComparable<in T>
     {
-        int CompareTo([System.Diagnostics.CodeAnalysis.AllowNullAttribute] T other);
+        int CompareTo(T? other);
     }
     [System.CLSCompliantAttribute(false)]
     public partial interface IConvertible
@@ -2331,7 +2329,7 @@ namespace System
     }
     public partial interface IEquatable<T>
     {
-        bool Equals([System.Diagnostics.CodeAnalysis.AllowNullAttribute] T other);
+        bool Equals(T? other);
     }
     public partial interface IFormatProvider
     {
@@ -5375,7 +5373,7 @@ namespace System.Collections.Generic
     }
     public partial interface IComparer<in T>
     {
-        int Compare([System.Diagnostics.CodeAnalysis.AllowNullAttribute] T x, [System.Diagnostics.CodeAnalysis.AllowNullAttribute] T y);
+        int Compare(T? x, T? y);
     }
     public partial interface IDictionary<TKey, TValue> : System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.IEnumerable
     {
@@ -5397,7 +5395,7 @@ namespace System.Collections.Generic
     }
     public partial interface IEqualityComparer<in T>
     {
-        bool Equals([System.Diagnostics.CodeAnalysis.AllowNullAttribute] T x, [System.Diagnostics.CodeAnalysis.AllowNullAttribute] T y);
+        bool Equals(T? x, T? y);
         int GetHashCode([System.Diagnostics.CodeAnalysis.DisallowNullAttribute] T obj);
     }
     public partial interface IList<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.IEnumerable
index 9fb5bee..97fbd6c 100644 (file)
@@ -169,7 +169,6 @@ namespace System.Security.Cryptography
         public System.Security.Cryptography.CngKeyUsages? KeyUsage { get { throw null; } set { } }
         public System.Security.Cryptography.CngPropertyCollection Parameters { get { throw null; } }
         public System.IntPtr ParentWindowHandle { get { throw null; } set { } }
-        [System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
         public System.Security.Cryptography.CngProvider Provider { get { throw null; } set { } }
         public System.Security.Cryptography.CngUIPolicy? UIPolicy { get { throw null; } set { } }
     }
index 13c292f..2850885 100644 (file)
@@ -98,8 +98,8 @@ namespace Microsoft.Win32.SafeHandles
         /// <summary>
         ///     Wrapper for the _holder field which ensures that we're in a consistent state
         /// </summary>
-        [MaybeNull]
-        private SafeNCryptHandle Holder
+        [DisallowNull]
+        private SafeNCryptHandle? Holder
         {
             get
             {
index d9c9f46..94e8c46 100644 (file)
@@ -67,14 +67,12 @@ namespace Internal.Cryptography.Pal.AnyOS
             }
         }
 
-        [return: MaybeNull]
-        public override T GetPrivateKeyForSigning<T>(X509Certificate2 certificate, bool silent)
+        public override T? GetPrivateKeyForSigning<T>(X509Certificate2 certificate, bool silent) where T : class
         {
             return GetPrivateKey<T>(certificate);
         }
 
-        [return: MaybeNull]
-        public override T GetPrivateKeyForDecryption<T>(X509Certificate2 certificate, bool silent)
+        public override T? GetPrivateKeyForDecryption<T>(X509Certificate2 certificate, bool silent) where T : class
         {
             return GetPrivateKey<T>(certificate);
         }
index 414f222..a720ce0 100644 (file)
@@ -91,14 +91,12 @@ namespace Internal.Cryptography.Pal.Windows
             }
         }
 
-        [return: MaybeNull]
-        public override T GetPrivateKeyForSigning<T>(X509Certificate2 certificate, bool silent)
+        public override T? GetPrivateKeyForSigning<T>(X509Certificate2 certificate, bool silent) where T : class
         {
             return GetPrivateKey<T>(certificate, silent, preferNCrypt: true);
         }
 
-        [return: MaybeNull]
-        public override T GetPrivateKeyForDecryption<T>(X509Certificate2 certificate, bool silent)
+        public override T? GetPrivateKeyForDecryption<T>(X509Certificate2 certificate, bool silent) where T : class
         {
             return GetPrivateKey<T>(certificate, silent, preferNCrypt: false);
         }
index 533f4f4..4184827 100644 (file)
@@ -191,13 +191,10 @@ namespace System.Text.Json
         public static object? Deserialize(string json, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnRead)] System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
         public static object? Deserialize(ref System.Text.Json.Utf8JsonReader reader, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnRead)] System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
         public static System.Threading.Tasks.ValueTask<object?> DeserializeAsync(System.IO.Stream utf8Json, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnRead)] System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
-        public static System.Threading.Tasks.ValueTask<TValue> DeserializeAsync<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnRead)] TValue>(System.IO.Stream utf8Json, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TValue Deserialize<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnRead)] TValue>(System.ReadOnlySpan<byte> utf8Json, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TValue Deserialize<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnRead)] TValue>(string json, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TValue Deserialize<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnRead)] TValue>(ref System.Text.Json.Utf8JsonReader reader, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
+        public static System.Threading.Tasks.ValueTask<TValue?> DeserializeAsync<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnRead)] TValue>(System.IO.Stream utf8Json, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
+        public static TValue? Deserialize<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnRead)] TValue>(System.ReadOnlySpan<byte> utf8Json, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
+        public static TValue? Deserialize<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnRead)] TValue>(string json, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
+        public static TValue? Deserialize<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnRead)] TValue>(ref System.Text.Json.Utf8JsonReader reader, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
         public static string Serialize(object? value, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnWrite)] System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
         public static void Serialize(System.Text.Json.Utf8JsonWriter writer, object? value, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnWrite)] System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null) { }
         public static System.Threading.Tasks.Task SerializeAsync(System.IO.Stream utf8Json, object? value, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(MembersAccessedOnWrite)] System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
@@ -211,13 +208,10 @@ namespace System.Text.Json
         public static object? Deserialize(string json, System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
         public static object? Deserialize(ref System.Text.Json.Utf8JsonReader reader, System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
         public static System.Threading.Tasks.ValueTask<object?> DeserializeAsync(System.IO.Stream utf8Json, System.Type returnType, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
-        public static System.Threading.Tasks.ValueTask<TValue> DeserializeAsync<TValue>(System.IO.Stream utf8Json, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TValue Deserialize<TValue>(System.ReadOnlySpan<byte> utf8Json, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TValue Deserialize<TValue>(string json, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public static TValue Deserialize<TValue>(ref System.Text.Json.Utf8JsonReader reader, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
+        public static System.Threading.Tasks.ValueTask<TValue?> DeserializeAsync<TValue>(System.IO.Stream utf8Json, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
+        public static TValue? Deserialize<TValue>(System.ReadOnlySpan<byte> utf8Json, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
+        public static TValue? Deserialize<TValue>(string json, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
+        public static TValue? Deserialize<TValue>(ref System.Text.Json.Utf8JsonReader reader, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
         public static string Serialize(object? value, System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
         public static void Serialize(System.Text.Json.Utf8JsonWriter writer, object? value, System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null) { }
         public static System.Threading.Tasks.Task SerializeAsync(System.IO.Stream utf8Json, object? value, System.Type inputType, System.Text.Json.JsonSerializerOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
@@ -533,8 +527,7 @@ namespace System.Text.Json.Serialization
         protected internal JsonConverter() { }
         public override bool CanConvert(System.Type typeToConvert) { throw null; }
         public virtual bool HandleNull { get { throw null; } }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public abstract T Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options);
+        public abstract T? Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options);
         public abstract void Write(System.Text.Json.Utf8JsonWriter writer, T value, System.Text.Json.JsonSerializerOptions options);
     }
     [System.AttributeUsageAttribute(System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Property | System.AttributeTargets.Field, AllowMultiple = false)]
index cd6c39c..57dfef6 100644 (file)
@@ -15,8 +15,7 @@ namespace System.Text.Json.Serialization
             return ReadCore(ref reader, options, ref state);
         }
 
-        [return: MaybeNull]
-        internal T ReadCore(
+        internal T? ReadCore(
             ref Utf8JsonReader reader,
             JsonSerializerOptions options,
             ref ReadStack state)
@@ -35,7 +34,7 @@ namespace System.Text.Json.Serialization
                             if (state.Current.ReturnValue == null)
                             {
                                 // Avoid returning null for value types.
-                                return default!;
+                                return default;
                             }
 
                             return (T)state.Current.ReturnValue!;
@@ -44,7 +43,7 @@ namespace System.Text.Json.Serialization
                         {
                             // Read more data until we have the full element.
                             state.BytesConsumed += reader.BytesConsumed;
-                            return default!;
+                            return default;
                         }
                     }
                 }
@@ -55,7 +54,7 @@ namespace System.Text.Json.Serialization
                     if (!SingleValueReadWithReadAhead(ClassType.Value, ref reader, ref state))
                     {
                         state.BytesConsumed += reader.BytesConsumed;
-                        return default!;
+                        return default;
                     }
                 }
 
index dfd81ff..e6f7d84 100644 (file)
@@ -83,7 +83,7 @@ namespace System.Text.Json.Serialization
         }
 
         // Provide a default implementation for value converters.
-        internal virtual bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, ref ReadStack state, [MaybeNull] out T value)
+        internal virtual bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, ref ReadStack state, out T? value)
         {
             value = Read(ref reader, typeToConvert, options);
             return true;
@@ -99,10 +99,9 @@ namespace System.Text.Json.Serialization
         /// <param name="typeToConvert">The <see cref="Type"/> being converted.</param>
         /// <param name="options">The <see cref="JsonSerializerOptions"/> being used.</param>
         /// <returns>The value that was converted.</returns>
-        [return: MaybeNull]
-        public abstract T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options);
+        public abstract T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options);
 
-        internal bool TryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, ref ReadStack state, [MaybeNull] out T value)
+        internal bool TryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, ref ReadStack state, out T? value)
         {
             if (ClassType == ClassType.Value)
             {
index 85962cd..9e24e25 100644 (file)
@@ -249,7 +249,7 @@ namespace System.Text.Json
                     ThrowHelper.ThrowJsonException_DeserializeUnableToConvertValue(Converter.TypeToConvert);
                 }
 
-                value = default(T)!;
+                value = default(T);
                 success = true;
             }
             else
index fc0ce66..fbe746d 100644 (file)
@@ -12,8 +12,7 @@ namespace System.Text.Json.Serialization
     /// <typeparam name="T"></typeparam>
     internal abstract class JsonResumableConverter<T> : JsonConverter<T>
     {
-        [return: MaybeNull]
-        public sealed override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+        public sealed override T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
         {
             // Bridge from resumable to value converters.
             if (options == null)
index 4e79468..76dd25b 100644 (file)
@@ -12,8 +12,7 @@ namespace System.Text.Json
         // Members accessed by the serializer when deserializing.
         private const DynamicallyAccessedMemberTypes MembersAccessedOnRead = DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.PublicProperties;
 
-        [return: MaybeNull]
-        private static TValue ReadCore<TValue>(ref Utf8JsonReader reader, Type returnType, JsonSerializerOptions options)
+        private static TValue? ReadCore<TValue>(ref Utf8JsonReader reader, Type returnType, JsonSerializerOptions options)
         {
             ReadStack state = default;
             state.Initialize(returnType, options, supportContinuation: false);
@@ -21,8 +20,7 @@ namespace System.Text.Json
             return ReadCore<TValue>(jsonConverter, ref reader, options, ref state);
         }
 
-        [return: MaybeNull]
-        private static TValue ReadCore<TValue>(JsonConverter jsonConverter, ref Utf8JsonReader reader, JsonSerializerOptions options, ref ReadStack state)
+        private static TValue? ReadCore<TValue>(JsonConverter jsonConverter, ref Utf8JsonReader reader, JsonSerializerOptions options, ref ReadStack state)
         {
             if (jsonConverter is JsonConverter<TValue> converter)
             {
index 974ed2a..af9dd0e 100644 (file)
@@ -22,8 +22,7 @@ namespace System.Text.Json
         /// There is no compatible <see cref="System.Text.Json.Serialization.JsonConverter"/>
         /// for <typeparamref name="TValue"/> or its serializable members.
         /// </exception>
-        [return: MaybeNull]
-        public static TValue Deserialize<[DynamicallyAccessedMembers(MembersAccessedOnRead)] TValue>(ReadOnlySpan<byte> utf8Json, JsonSerializerOptions? options = null)
+        public static TValue? Deserialize<[DynamicallyAccessedMembers(MembersAccessedOnRead)] TValue>(ReadOnlySpan<byte> utf8Json, JsonSerializerOptions? options = null)
         {
             if (options == null)
             {
index 24d1421..b0c471c 100644 (file)
@@ -35,7 +35,7 @@ namespace System.Text.Json
         /// There is no compatible <see cref="System.Text.Json.Serialization.JsonConverter"/>
         /// for <typeparamref name="TValue"/> or its serializable members.
         /// </exception>
-        public static ValueTask<TValue> DeserializeAsync<[DynamicallyAccessedMembers(MembersAccessedOnRead)] TValue>(
+        public static ValueTask<TValue?> DeserializeAsync<[DynamicallyAccessedMembers(MembersAccessedOnRead)] TValue>(
             Stream utf8Json,
             JsonSerializerOptions? options = null,
             CancellationToken cancellationToken = default)
@@ -86,7 +86,7 @@ namespace System.Text.Json
             return ReadAsync<object?>(utf8Json, returnType, options, cancellationToken);
         }
 
-        private static async ValueTask<TValue> ReadAsync<TValue>(
+        private static async ValueTask<TValue?> ReadAsync<TValue>(
             Stream utf8Json,
             Type returnType,
             JsonSerializerOptions? options,
index bd9edb8..af1f35d 100644 (file)
@@ -34,8 +34,7 @@ namespace System.Text.Json
         /// <remarks>Using a <see cref="string"/> is not as efficient as using the
         /// UTF-8 methods since the implementation natively uses UTF-8.
         /// </remarks>
-        [return: MaybeNull]
-        public static TValue Deserialize<[DynamicallyAccessedMembers(MembersAccessedOnRead)] TValue>(string json, JsonSerializerOptions? options = null)
+        public static TValue? Deserialize<[DynamicallyAccessedMembers(MembersAccessedOnRead)] TValue>(string json, JsonSerializerOptions? options = null)
         {
             if (json == null)
             {
@@ -84,8 +83,7 @@ namespace System.Text.Json
             return value;
         }
 
-        [return: MaybeNull]
-        private static TValue Deserialize<TValue>(string json, Type returnType, JsonSerializerOptions? options)
+        private static TValue? Deserialize<TValue>(string json, Type returnType, JsonSerializerOptions? options)
         {
             const long ArrayPoolMaxSizeBeforeUsingNormalAlloc = 1024 * 1024;
 
index 9daac01..4b42458 100644 (file)
@@ -52,8 +52,7 @@ namespace System.Text.Json
         ///     Hence, <see cref="JsonReaderOptions.AllowTrailingCommas"/>, <see cref="JsonReaderOptions.MaxDepth"/>, <see cref="JsonReaderOptions.CommentHandling"/> are used while reading.
         ///   </para>
         /// </remarks>
-        [return: MaybeNull]
-        public static TValue Deserialize<[DynamicallyAccessedMembers(MembersAccessedOnRead)] TValue>(ref Utf8JsonReader reader, JsonSerializerOptions? options = null)
+        public static TValue? Deserialize<[DynamicallyAccessedMembers(MembersAccessedOnRead)] TValue>(ref Utf8JsonReader reader, JsonSerializerOptions? options = null)
         {
             if (options == null)
             {
@@ -137,8 +136,7 @@ namespace System.Text.Json
             }
         }
 
-        [return: MaybeNull]
-        private static TValue ReadValueCore<TValue>(JsonSerializerOptions options, ref Utf8JsonReader reader, ref ReadStack state)
+        private static TValue? ReadValueCore<TValue>(JsonSerializerOptions options, ref Utf8JsonReader reader, ref ReadStack state)
         {
             JsonReaderState readerState = reader.CurrentState;
             CheckSupportedOptions(readerState.Options, nameof(reader));
index e45e584..0df0e57 100644 (file)
@@ -7,14 +7,15 @@ namespace System.Collections
 {
     internal static class HashtableExtensions
     {
-        public static bool TryGetValue<T>(this Hashtable table, object key, [MaybeNull] out T value)
+        public static bool TryGetValue<T>(this Hashtable table, object key, out T? value)
         {
             if (table.ContainsKey(key))
             {
                 value = (T)table[key]!;
                 return true;
             }
-            value = default!;
+
+            value = default;
             return false;
         }
     }
index 67106d3..9412cc2 100644 (file)
@@ -51,8 +51,7 @@ namespace System.Threading.Channels
         /// <summary>Only relevant to cancelable operations; 0 if the operation hasn't had completion reserved, 1 if it has.</summary>
         private volatile int _completionReserved;
         /// <summary>The result of the operation.</summary>
-        [MaybeNull, AllowNull]
-        private TResult _result = default;
+        private TResult? _result;
         /// <summary>Any error that occurred during the operation.</summary>
         private ExceptionDispatchInfo? _error;
         /// <summary>The continuation callback.</summary>
@@ -454,7 +453,6 @@ namespace System.Threading.Channels
         }
 
         /// <summary>The item being written.</summary>
-        [MaybeNull, AllowNull]
-        public TData Item { get; set; } = default!;
+        public TData? Item { get; set; }
     }
 }
index be088c5..cec397b 100644 (file)
@@ -105,7 +105,7 @@ namespace System.Threading.Channels
                     }
                 }
 
-                item = default!;
+                item = default;
                 return false;
             }
 
index 6ac25fb..612d6b5 100644 (file)
@@ -119,7 +119,7 @@ namespace System.Threading.Channels
                     return true;
                 }
 
-                item = default!;
+                item = default;
                 return false;
             }
 
index e860e69..4931e85 100644 (file)
@@ -30,8 +30,7 @@ namespace System.Threading.Tasks.Dataflow
         public void Complete() { }
         public System.IDisposable LinkTo(System.Threading.Tasks.Dataflow.ITargetBlock<T[]> target, System.Threading.Tasks.Dataflow.DataflowLinkOptions linkOptions) { throw null; }
         void System.Threading.Tasks.Dataflow.IDataflowBlock.Fault(System.Exception exception) { }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        T[] System.Threading.Tasks.Dataflow.ISourceBlock<T[]>.ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<T[]> target, out bool messageConsumed) { throw null; }
+        T[]? System.Threading.Tasks.Dataflow.ISourceBlock<T[]>.ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<T[]> target, out bool messageConsumed) { throw null; }
         void System.Threading.Tasks.Dataflow.ISourceBlock<T[]>.ReleaseReservation(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<T[]> target) { }
         bool System.Threading.Tasks.Dataflow.ISourceBlock<T[]>.ReserveMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<T[]> target) { throw null; }
         System.Threading.Tasks.Dataflow.DataflowMessageStatus System.Threading.Tasks.Dataflow.ITargetBlock<T>.OfferMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, T messageValue, System.Threading.Tasks.Dataflow.ISourceBlock<T>? source, bool consumeToAccept) { throw null; }
@@ -88,8 +87,7 @@ namespace System.Threading.Tasks.Dataflow
         public System.IDisposable LinkTo(System.Threading.Tasks.Dataflow.ITargetBlock<T> target, System.Threading.Tasks.Dataflow.DataflowLinkOptions linkOptions) { throw null; }
         void System.Threading.Tasks.Dataflow.IDataflowBlock.Fault(System.Exception exception) { }
         bool System.Threading.Tasks.Dataflow.IReceivableSourceBlock<T>.TryReceiveAll([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Collections.Generic.IList<T>? items) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        T System.Threading.Tasks.Dataflow.ISourceBlock<T>.ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<T> target, out bool messageConsumed) { throw null; }
+        T? System.Threading.Tasks.Dataflow.ISourceBlock<T>.ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<T> target, out bool messageConsumed) { throw null; }
         void System.Threading.Tasks.Dataflow.ISourceBlock<T>.ReleaseReservation(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<T> target) { }
         bool System.Threading.Tasks.Dataflow.ISourceBlock<T>.ReserveMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<T> target) { throw null; }
         System.Threading.Tasks.Dataflow.DataflowMessageStatus System.Threading.Tasks.Dataflow.ITargetBlock<T>.OfferMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, T messageValue, System.Threading.Tasks.Dataflow.ISourceBlock<T>? source, bool consumeToAccept) { throw null; }
@@ -105,8 +103,7 @@ namespace System.Threading.Tasks.Dataflow
         public void Complete() { }
         public System.IDisposable LinkTo(System.Threading.Tasks.Dataflow.ITargetBlock<T> target, System.Threading.Tasks.Dataflow.DataflowLinkOptions linkOptions) { throw null; }
         void System.Threading.Tasks.Dataflow.IDataflowBlock.Fault(System.Exception exception) { }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        T System.Threading.Tasks.Dataflow.ISourceBlock<T>.ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<T> target, out bool messageConsumed) { throw null; }
+        T? System.Threading.Tasks.Dataflow.ISourceBlock<T>.ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<T> target, out bool messageConsumed) { throw null; }
         void System.Threading.Tasks.Dataflow.ISourceBlock<T>.ReleaseReservation(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<T> target) { }
         bool System.Threading.Tasks.Dataflow.ISourceBlock<T>.ReserveMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<T> target) { throw null; }
         System.Threading.Tasks.Dataflow.DataflowMessageStatus System.Threading.Tasks.Dataflow.ITargetBlock<T>.OfferMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, T messageValue, System.Threading.Tasks.Dataflow.ISourceBlock<T>? source, bool consumeToAccept) { throw null; }
@@ -208,8 +205,7 @@ namespace System.Threading.Tasks.Dataflow
     }
     public partial interface ISourceBlock<out TOutput> : System.Threading.Tasks.Dataflow.IDataflowBlock
     {
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        TOutput ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<TOutput> target, out bool messageConsumed);
+        TOutput? ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<TOutput> target, out bool messageConsumed);
         System.IDisposable LinkTo(System.Threading.Tasks.Dataflow.ITargetBlock<TOutput> target, System.Threading.Tasks.Dataflow.DataflowLinkOptions linkOptions);
         void ReleaseReservation(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<TOutput> target);
         bool ReserveMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<TOutput> target);
@@ -267,8 +263,7 @@ namespace System.Threading.Tasks.Dataflow
         public void Complete() { }
         public System.IDisposable LinkTo(System.Threading.Tasks.Dataflow.ITargetBlock<TOutput> target, System.Threading.Tasks.Dataflow.DataflowLinkOptions linkOptions) { throw null; }
         void System.Threading.Tasks.Dataflow.IDataflowBlock.Fault(System.Exception exception) { }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        TOutput System.Threading.Tasks.Dataflow.ISourceBlock<TOutput>.ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<TOutput> target, out bool messageConsumed) { throw null; }
+        TOutput? System.Threading.Tasks.Dataflow.ISourceBlock<TOutput>.ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<TOutput> target, out bool messageConsumed) { throw null; }
         void System.Threading.Tasks.Dataflow.ISourceBlock<TOutput>.ReleaseReservation(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<TOutput> target) { }
         bool System.Threading.Tasks.Dataflow.ISourceBlock<TOutput>.ReserveMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<TOutput> target) { throw null; }
         System.Threading.Tasks.Dataflow.DataflowMessageStatus System.Threading.Tasks.Dataflow.ITargetBlock<TInput>.OfferMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, TInput messageValue, System.Threading.Tasks.Dataflow.ISourceBlock<TInput>? source, bool consumeToAccept) { throw null; }
@@ -288,8 +283,7 @@ namespace System.Threading.Tasks.Dataflow
         public void Complete() { }
         public System.IDisposable LinkTo(System.Threading.Tasks.Dataflow.ITargetBlock<TOutput> target, System.Threading.Tasks.Dataflow.DataflowLinkOptions linkOptions) { throw null; }
         void System.Threading.Tasks.Dataflow.IDataflowBlock.Fault(System.Exception exception) { }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        TOutput System.Threading.Tasks.Dataflow.ISourceBlock<TOutput>.ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<TOutput> target, out bool messageConsumed) { throw null; }
+        TOutput? System.Threading.Tasks.Dataflow.ISourceBlock<TOutput>.ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<TOutput> target, out bool messageConsumed) { throw null; }
         void System.Threading.Tasks.Dataflow.ISourceBlock<TOutput>.ReleaseReservation(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<TOutput> target) { }
         bool System.Threading.Tasks.Dataflow.ISourceBlock<TOutput>.ReserveMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<TOutput> target) { throw null; }
         System.Threading.Tasks.Dataflow.DataflowMessageStatus System.Threading.Tasks.Dataflow.ITargetBlock<TInput>.OfferMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, TInput messageValue, System.Threading.Tasks.Dataflow.ISourceBlock<TInput>? source, bool consumeToAccept) { throw null; }
@@ -306,8 +300,7 @@ namespace System.Threading.Tasks.Dataflow
         public System.IDisposable LinkTo(System.Threading.Tasks.Dataflow.ITargetBlock<T> target, System.Threading.Tasks.Dataflow.DataflowLinkOptions linkOptions) { throw null; }
         void System.Threading.Tasks.Dataflow.IDataflowBlock.Fault(System.Exception exception) { }
         bool System.Threading.Tasks.Dataflow.IReceivableSourceBlock<T>.TryReceiveAll([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Collections.Generic.IList<T>? items) { throw null; }
-        [return: System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        T System.Threading.Tasks.Dataflow.ISourceBlock<T>.ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<T> target, out bool messageConsumed) { throw null; }
+        T? System.Threading.Tasks.Dataflow.ISourceBlock<T>.ConsumeMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<T> target, out bool messageConsumed) { throw null; }
         void System.Threading.Tasks.Dataflow.ISourceBlock<T>.ReleaseReservation(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<T> target) { }
         bool System.Threading.Tasks.Dataflow.ISourceBlock<T>.ReserveMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, System.Threading.Tasks.Dataflow.ITargetBlock<T> target) { throw null; }
         System.Threading.Tasks.Dataflow.DataflowMessageStatus System.Threading.Tasks.Dataflow.ITargetBlock<T>.OfferMessage(System.Threading.Tasks.Dataflow.DataflowMessageHeader messageHeader, T messageValue, System.Threading.Tasks.Dataflow.ISourceBlock<T>? source, bool consumeToAccept) { throw null; }
index 45d7c5c..2785f3e 100644 (file)
@@ -154,8 +154,7 @@ namespace System.Threading.Tasks.Dataflow
             }
 
             /// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Sources/Member[@name="ConsumeMessage"]/*' />
-            [return: MaybeNull]
-            T ISourceBlock<T>.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<T> target, out bool messageConsumed)
+            T? ISourceBlock<T>.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<T> target, out bool messageConsumed)
             {
                 // This message should have only made it to the target if it passes the filter, so we shouldn't need to check again.
                 // The real source will also be doing verifications, so we don't need to validate args here.
@@ -621,8 +620,7 @@ namespace System.Threading.Tasks.Dataflow
             }
 
             /// <summary>Called by the target to consume the buffered message.</summary>
-            [return: MaybeNull]
-            TOutput ISourceBlock<TOutput>.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<TOutput> target, out bool messageConsumed)
+            TOutput? ISourceBlock<TOutput>.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<TOutput> target, out bool messageConsumed)
             {
                 // Validate arguments
                 if (!messageHeader.IsValid) throw new ArgumentException(SR.Argument_InvalidMessageHeader, nameof(messageHeader));
@@ -1129,8 +1127,7 @@ namespace System.Threading.Tasks.Dataflow
             };
 
             /// <summary>The received value if we accepted a value from the source.</summary>
-            [AllowNull, MaybeNull]
-            private T _receivedValue = default!;
+            private T? _receivedValue;
 
             /// <summary>The cancellation token source representing both external and internal cancellation.</summary>
             internal readonly CancellationTokenSource _cts = new CancellationTokenSource();
@@ -1664,8 +1661,7 @@ namespace System.Threading.Tasks.Dataflow
             }
 
             /// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Sources/Member[@name="ConsumeMessage"]/*' />
-            [return: MaybeNull]
-            public TOutput ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<TOutput> target, out bool messageConsumed)
+            public TOutput? ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<TOutput> target, out bool messageConsumed)
             {
                 return _source.ConsumeMessage(messageHeader, target, out messageConsumed);
             }
index 518f8fb..8e4d27a 100644 (file)
@@ -27,8 +27,7 @@ namespace System.Threading.Tasks.Dataflow
         // IMPLEMENT EXPLICITLY
 
         /// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Sources/Member[@name="ConsumeMessage"]/*' />
-        [return: MaybeNull]
-        TOutput ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<TOutput> target, out bool messageConsumed);
+        TOutput? ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<TOutput> target, out bool messageConsumed);
 
         /// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Sources/Member[@name="ReserveMessage"]/*' />
         bool ReserveMessage(DataflowMessageHeader messageHeader, ITargetBlock<TOutput> target);
index df9bb9c..af2775e 100644 (file)
@@ -154,8 +154,7 @@ namespace System.Threading.Tasks.Dataflow
         }
 
         /// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Sources/Member[@name="ConsumeMessage"]/*' />
-        [return: MaybeNull]
-        T[] ISourceBlock<T[]>.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<T[]> target, out bool messageConsumed)
+        T[]? ISourceBlock<T[]>.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<T[]> target, out bool messageConsumed)
         {
             return _source.ConsumeMessage(messageHeader, target, out messageConsumed);
         }
index 054eaa3..8099f49 100644 (file)
@@ -172,8 +172,7 @@ namespace System.Threading.Tasks.Dataflow
         }
 
         /// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Sources/Member[@name="ConsumeMessage"]/*' />
-        [return: MaybeNull]
-        Tuple<IList<T1>, IList<T2>> ISourceBlock<Tuple<IList<T1>, IList<T2>>>.ConsumeMessage(
+        Tuple<IList<T1>, IList<T2>>? ISourceBlock<Tuple<IList<T1>, IList<T2>>>.ConsumeMessage(
             DataflowMessageHeader messageHeader, ITargetBlock<Tuple<IList<T1>, IList<T2>>> target, out bool messageConsumed)
         {
             return _source.ConsumeMessage(messageHeader, target, out messageConsumed);
@@ -436,8 +435,7 @@ namespace System.Threading.Tasks.Dataflow
         }
 
         /// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Sources/Member[@name="ConsumeMessage"]/*' />
-        [return: MaybeNull]
-        Tuple<IList<T1>, IList<T2>, IList<T3>> ISourceBlock<Tuple<IList<T1>, IList<T2>, IList<T3>>>.ConsumeMessage(
+        Tuple<IList<T1>, IList<T2>, IList<T3>>? ISourceBlock<Tuple<IList<T1>, IList<T2>, IList<T3>>>.ConsumeMessage(
             DataflowMessageHeader messageHeader, ITargetBlock<Tuple<IList<T1>, IList<T2>, IList<T3>>> target, out bool messageConsumed)
         {
             return _source.ConsumeMessage(messageHeader, target, out messageConsumed);
index 508d151..9f9b932 100644 (file)
@@ -417,8 +417,7 @@ namespace System.Threading.Tasks.Dataflow
         }
 
         /// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Sources/Member[@name="ConsumeMessage"]/*' />
-        [return: MaybeNull]
-        T ISourceBlock<T>.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<T> target, out bool messageConsumed)
+        T? ISourceBlock<T>.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<T> target, out bool messageConsumed)
         {
             return _source.ConsumeMessage(messageHeader, target, out messageConsumed);
         }
@@ -531,8 +530,7 @@ namespace System.Threading.Tasks.Dataflow
             /// <summary>An indicator whether _currentMessage has a value.</summary>
             private bool _currentMessageIsValid;
             /// <summary>The message currently being broadcast.</summary>
-            [AllowNull, MaybeNull]
-            private TOutput _currentMessage = default;
+            private TOutput? _currentMessage;
             /// <summary>The target that the next message is reserved for, or null if nothing is reserved.</summary>
             private ITargetBlock<TOutput>? _nextMessageReservedFor;
             /// <summary>Whether this block should again attempt to offer messages to targets.</summary>
@@ -1049,8 +1047,7 @@ namespace System.Threading.Tasks.Dataflow
             }
 
             /// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Sources/Member[@name="ConsumeMessage"]/*' />
-            [return: MaybeNull]
-            internal TOutput ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<TOutput> target, out bool messageConsumed)
+            internal TOutput? ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<TOutput> target, out bool messageConsumed)
             {
                 // Validate arguments
                 if (!messageHeader.IsValid) throw new ArgumentException(SR.Argument_InvalidMessageHeader, nameof(messageHeader));
index dc7b45d..6d5e702 100644 (file)
@@ -197,8 +197,7 @@ namespace System.Threading.Tasks.Dataflow
         public Task Completion { get { return _source.Completion; } }
 
         /// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Sources/Member[@name="ConsumeMessage"]/*' />
-        [return: MaybeNull]
-        T ISourceBlock<T>.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<T> target, out bool messageConsumed)
+        T? ISourceBlock<T>.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<T> target, out bool messageConsumed)
         {
             return _source.ConsumeMessage(messageHeader, target, out messageConsumed);
         }
index cbaff49..b5267ca 100644 (file)
@@ -368,8 +368,7 @@ namespace System.Threading.Tasks.Dataflow
         }
 
         /// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Sources/Member[@name="ConsumeMessage"]/*' />
-        [return: MaybeNull]
-        TOutput ISourceBlock<TOutput>.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<TOutput> target, out bool messageConsumed)
+        TOutput? ISourceBlock<TOutput>.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<TOutput> target, out bool messageConsumed)
         {
             return _source.ConsumeMessage(messageHeader, target, out messageConsumed);
         }
index a1d7dcc..0e6ddfa 100644 (file)
@@ -601,8 +601,7 @@ namespace System.Threading.Tasks.Dataflow
         }
 
         /// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Sources/Member[@name="ConsumeMessage"]/*' />
-        [return: MaybeNull]
-        TOutput ISourceBlock<TOutput>.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<TOutput> target, out bool messageConsumed)
+        TOutput? ISourceBlock<TOutput>.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<TOutput> target, out bool messageConsumed)
         {
             return _source.ConsumeMessage(messageHeader, target, out messageConsumed);
         }
index 22d052a..244703a 100644 (file)
@@ -39,8 +39,7 @@ namespace System.Threading.Tasks.Dataflow
         /// <summary>The header of the singly-assigned value.</summary>
         private DataflowMessageHeader _header;
         /// <summary>The singly-assigned value.</summary>
-        [AllowNull, MaybeNull]
-        private T _value = default;
+        private T? _value;
 
         /// <summary>Gets the object used as the value lock.</summary>
         private object ValueLock { get { return _targetRegistry; } }
@@ -381,7 +380,7 @@ namespace System.Threading.Tasks.Dataflow
         }
 
         /// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Sources/Member[@name="ConsumeMessage"]/*' />
-        T ISourceBlock<T>.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<T> target, out bool messageConsumed)
+        T? ISourceBlock<T>.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<T> target, out bool messageConsumed)
         {
             // Validate arguments
             if (!messageHeader.IsValid) throw new ArgumentException(SR.Argument_InvalidMessageHeader, nameof(messageHeader));
@@ -397,7 +396,7 @@ namespace System.Threading.Tasks.Dataflow
             else
             {
                 messageConsumed = false;
-                return default(T)!;
+                return default;
             }
         }
 
@@ -506,8 +505,7 @@ namespace System.Threading.Tasks.Dataflow
         /// <summary>Gets whether the block is storing a value.</summary>
         private bool HasValue { get { return _header.IsValid; } }
         /// <summary>Gets the value being stored by the block.</summary>
-        [MaybeNull]
-        private T Value { get { return _header.IsValid ? _value : default(T); } }
+        private T? Value { get { return _header.IsValid ? _value : default(T); } }
 
         /// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Blocks/Member[@name="ToString"]/*' />
         public override string ToString() { return Common.GetNameForDebugger(this, _dataflowBlockOptions); }
@@ -546,8 +544,7 @@ namespace System.Threading.Tasks.Dataflow
             /// <summary>Gets whether the WriteOnceBlock has a value.</summary>
             public bool HasValue { get { return _writeOnceBlock.HasValue; } }
             /// <summary>Gets the WriteOnceBlock's value if it has one, or default(T) if it doesn't.</summary>
-            [MaybeNull]
-            public T Value { get { return _writeOnceBlock.Value; } }
+            public T? Value { get { return _writeOnceBlock.Value; } }
 
             /// <summary>Gets the DataflowBlockOptions used to configure this block.</summary>
             public DataflowBlockOptions DataflowBlockOptions { get { return _writeOnceBlock._dataflowBlockOptions; } }
index 275b293..0022621 100644 (file)
@@ -93,8 +93,7 @@ namespace System.Threading.Tasks.Dataflow.Internal
         /// <typeparam name="T">The type of the data to be unwrapped.</typeparam>
         /// <param name="state">The weak reference.</param>
         /// <returns>The T instance.</returns>
-        [return: MaybeNull]
-        internal static T UnwrapWeakReference<T>(object state) where T : class
+        internal static T? UnwrapWeakReference<T>(object state) where T : class
         {
             var wr = state as WeakReference<T>;
             Debug.Assert(wr != null, "Expected a WeakReference<T> as the state argument");
index e69865b..80513f6 100644 (file)
@@ -66,7 +66,7 @@ namespace System.Threading.Tasks.Dataflow.Internal
         /// <param name="id">The ID of the item.</param>
         /// <param name="item">The completed item.</param>
         /// <param name="itemIsValid">Specifies whether the item is valid (true) or just a placeholder (false).</param>
-        internal void AddItem(long id, [AllowNull] TOutput item, bool itemIsValid)
+        internal void AddItem(long id, TOutput? item, bool itemIsValid)
         {
             Debug.Assert(id != Common.INVALID_REORDERING_ID, "This ID should never have been handed out.");
             Common.ContractAssertMonitorStatus(ValueLock, held: false);
@@ -104,7 +104,7 @@ namespace System.Threading.Tasks.Dataflow.Internal
         /// true if the item was not added but is next in line.
         /// false if the item was not added and is not next in line.
         /// </returns>
-        internal bool? AddItemIfNextAndTrusted(long id, [AllowNull] TOutput item, bool isTrusted)
+        internal bool? AddItemIfNextAndTrusted(long id, TOutput? item, bool isTrusted)
         {
             Debug.Assert(id != Common.INVALID_REORDERING_ID, "This ID should never have been handed out.");
             Common.ContractAssertMonitorStatus(ValueLock, held: false);
@@ -138,7 +138,7 @@ namespace System.Threading.Tasks.Dataflow.Internal
         /// <summary>Outputs the item.  The item must have already been confirmed to have the next ID.</summary>
         /// <param name="theNextItem">The item to output.</param>
         /// <param name="itemIsValid">Whether the item is valid.</param>
-        private void OutputNextItem([AllowNull] TOutput theNextItem, bool itemIsValid)
+        private void OutputNextItem(TOutput? theNextItem, bool itemIsValid)
         {
             Common.ContractAssertMonitorStatus(ValueLock, held: true);
 
index 99d772c..a9e86e6 100644 (file)
@@ -155,8 +155,7 @@ namespace System.Threading.Tasks.Dataflow.Internal
         }
 
         /// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Sources/Member[@name="ConsumeMessage"]/*' />
-        [return: MaybeNull]
-        internal TOutput ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<TOutput> target, out bool messageConsumed)
+        internal TOutput? ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<TOutput> target, out bool messageConsumed)
         {
             // Validate arguments
             if (!messageHeader.IsValid) throw new ArgumentException(SR.Argument_InvalidMessageHeader, nameof(messageHeader));
index 9420fc8..6cc23ec 100644 (file)
@@ -331,8 +331,7 @@ namespace System.Threading.Tasks.Dataflow.Internal
             }
 
             /// <include file='XmlDocs/CommonXmlDocComments.xml' path='CommonXmlDocComments/Sources/Member[@name="ConsumeMessage"]/*' />
-            [return: MaybeNull]
-            T ISourceBlock<T>.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<T> target, out bool messageConsumed)
+            T? ISourceBlock<T>.ConsumeMessage(DataflowMessageHeader messageHeader, ITargetBlock<T> target, out bool messageConsumed)
             {
                 return _owningSource.ConsumeMessage(messageHeader, this, out messageConsumed);
             }
index d5fceaa..888abda 100644 (file)
@@ -35,10 +35,8 @@ namespace System.Threading
         private readonly T _PreviousValue_k__BackingField;
         private readonly T _CurrentValue_k__BackingField;
         private readonly int _dummyPrimitive;
-        [System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public T CurrentValue { get { throw null; } }
-        [System.Diagnostics.CodeAnalysis.MaybeNullAttribute]
-        public T PreviousValue { get { throw null; } }
+        public T? CurrentValue { get { throw null; } }
+        public T? PreviousValue { get { throw null; } }
         public bool ThreadContextChanged { get { throw null; } }
     }
     public sealed partial class AsyncLocal<T>
index a4bc5ac..e54fecd 100644 (file)
@@ -74,7 +74,7 @@ namespace System
 
             public abstract ITypeName NestedName(ITypeIdentifier innerName);
 
-            public bool Equals([AllowNull] ITypeName other)
+            public bool Equals(ITypeName? other)
             {
                 return other != null && DisplayName == other.DisplayName;
             }
index 8ab12b5..e4c4b0a 100644 (file)
@@ -11,8 +11,7 @@ namespace System
         private GCHandle handle;
         private bool trackResurrection;
 
-        [MaybeNull]
-        private T Target
+        private T? Target
         {
             get
             {