浏览代码

Harvest some low-hanging nullable fruit.

Bart De Smet 5 年之前
父节点
当前提交
d16cbcb442

+ 5 - 7
Rx.NET/Source/src/System.Reactive/Concurrency/CurrentThreadScheduler.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 using System.ComponentModel;
 
 namespace System.Reactive.Concurrency
@@ -26,17 +24,17 @@ namespace System.Reactive.Concurrency
         public static CurrentThreadScheduler Instance => StaticInstance.Value;
 
         [ThreadStatic]
-        private static SchedulerQueue<TimeSpan> _threadLocalQueue;
+        private static SchedulerQueue<TimeSpan>? _threadLocalQueue;
 
         [ThreadStatic]
-        private static IStopwatch _clock;
+        private static IStopwatch? _clock;
 
         [ThreadStatic]
         private static bool _running;
 
-        private static SchedulerQueue<TimeSpan> GetQueue() => _threadLocalQueue;
+        private static SchedulerQueue<TimeSpan>? GetQueue() => _threadLocalQueue;
 
-        private static void SetQueue(SchedulerQueue<TimeSpan> newQueue)
+        private static void SetQueue(SchedulerQueue<TimeSpan>? newQueue)
         {
             _threadLocalQueue = newQueue;
         }
@@ -84,7 +82,7 @@ namespace System.Reactive.Concurrency
                 throw new ArgumentNullException(nameof(action));
             }
 
-            SchedulerQueue<TimeSpan> queue;
+            SchedulerQueue<TimeSpan>? queue;
 
             // There is no timed task and no task is currently running
             if (!_running)

+ 0 - 2
Rx.NET/Source/src/System.Reactive/Concurrency/IScheduler.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 namespace System.Reactive.Concurrency
 {
     /// <summary>

+ 0 - 2
Rx.NET/Source/src/System.Reactive/Concurrency/ISchedulerLongRunning.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 using System.Reactive.Disposables;
 
 namespace System.Reactive.Concurrency

+ 0 - 2
Rx.NET/Source/src/System.Reactive/Concurrency/ISchedulerPeriodic.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 namespace System.Reactive.Concurrency
 {
     /// <summary>

+ 3 - 5
Rx.NET/Source/src/System.Reactive/Concurrency/ImmediateScheduler.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 using System.Reactive.Disposables;
 
 namespace System.Reactive.Concurrency
@@ -14,7 +12,7 @@ namespace System.Reactive.Concurrency
     /// <seealso cref="Scheduler.Immediate">Singleton instance of this type exposed through this static property.</seealso>
     public sealed class ImmediateScheduler : LocalScheduler
     {
-        private static readonly Lazy<ImmediateScheduler> _instance = new Lazy<ImmediateScheduler>(static () => new ImmediateScheduler());
+        private static readonly Lazy<ImmediateScheduler> StaticInstance = new Lazy<ImmediateScheduler>(static () => new ImmediateScheduler());
 
         private ImmediateScheduler()
         {
@@ -23,7 +21,7 @@ namespace System.Reactive.Concurrency
         /// <summary>
         /// Gets the singleton instance of the immediate scheduler.
         /// </summary>
-        public static ImmediateScheduler Instance => _instance.Value;
+        public static ImmediateScheduler Instance => StaticInstance.Value;
 
         /// <summary>
         /// Schedules an action to be executed.
@@ -70,7 +68,7 @@ namespace System.Reactive.Concurrency
 
         private sealed class AsyncLockScheduler : LocalScheduler
         {
-            private AsyncLock _asyncLock;
+            private AsyncLock? _asyncLock;
 
             public override IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
             {

+ 4 - 6
Rx.NET/Source/src/System.Reactive/Concurrency/LocalScheduler.TimerQueue.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 using System.Collections.Generic;
 using System.Reactive.Disposables;
 using System.Reactive.PlatformServices;
@@ -43,7 +41,7 @@ namespace System.Reactive.Concurrency
         /// or can continue using the current timer (because no earlier long term work was
         /// added to the queue).
         /// </summary>
-        private static WorkItem _nextLongTermWorkItem;
+        private static WorkItem? _nextLongTermWorkItem;
 
         /// <summary>
         /// Short term work queue. Contains work that's due soon, computed at the time of
@@ -209,7 +207,7 @@ namespace System.Reactive.Concurrency
         /// <returns>Empty disposable. Recursive work cancellation is wired through the original WorkItem.</returns>
         private IDisposable ExecuteNextShortTermWorkItem(IScheduler scheduler, IDisposable cancel)
         {
-            WorkItem next = null;
+            WorkItem? next = null;
 
             lock (Gate)
             {
@@ -424,7 +422,7 @@ namespace System.Reactive.Concurrency
             public readonly LocalScheduler Scheduler;
             public readonly DateTimeOffset DueTime;
 
-            private IDisposable _disposable;
+            private IDisposable? _disposable;
             private int _hasRun;
 
             protected WorkItem(LocalScheduler scheduler, DateTimeOffset dueTime)
@@ -461,7 +459,7 @@ namespace System.Reactive.Concurrency
 
             protected abstract IDisposable InvokeCore(IScheduler scheduler);
 
-            public int CompareTo(WorkItem/*!*/ other) => Comparer<DateTimeOffset>.Default.Compare(DueTime, other.DueTime);
+            public int CompareTo(WorkItem? other) => Comparer<DateTimeOffset>.Default.Compare(DueTime, other!.DueTime);
 
             public void Dispose() => Disposable.TryDispose(ref _disposable);
         }

+ 0 - 2
Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Wrappers.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 namespace System.Reactive.Concurrency
 {
     public static partial class Scheduler

+ 0 - 2
Rx.NET/Source/src/System.Reactive/Concurrency/SchedulerDefaults.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 namespace System.Reactive.Concurrency
 {
     internal static class SchedulerDefaults

+ 4 - 6
Rx.NET/Source/src/System.Reactive/Concurrency/SchedulerOperation.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 using System.ComponentModel;
 using System.Runtime.CompilerServices;
 using System.Threading;
@@ -70,7 +68,7 @@ namespace System.Reactive.Concurrency
 
             if (cancellationToken.CanBeCanceled)
             {
-                _ctr = _cancellationToken.Register(static @this => ((SchedulerOperationAwaiter)@this).Cancel(), this);
+                _ctr = _cancellationToken.Register(static @this => ((SchedulerOperationAwaiter)@this!).Cancel(), this);
             }
         }
 
@@ -122,7 +120,7 @@ namespace System.Reactive.Concurrency
                         // is a conscious design decision as the performance impact was non
                         // negligible and our schedulers abstract over more constructs.
                         //
-                        ctx.Post(static a => ((Action)a)(), original);
+                        ctx.Post(static a => ((Action)a!)(), original);
                     };
                 }
             }
@@ -141,8 +139,8 @@ namespace System.Reactive.Concurrency
             _work = _schedule(_continuation);
         }
 
-        private volatile Action _continuation;
-        private volatile IDisposable _work;
+        private volatile Action? _continuation;
+        private volatile IDisposable? _work;
 
         private void Cancel()
         {

+ 0 - 2
Rx.NET/Source/src/System.Reactive/Concurrency/SchedulerQueue.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 namespace System.Reactive.Concurrency
 {
     /// <summary>

+ 0 - 2
Rx.NET/Source/src/System.Reactive/Disposables/BooleanDisposable.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 namespace System.Reactive.Disposables
 {
     /// <summary>

+ 0 - 2
Rx.NET/Source/src/System.Reactive/Linq/Observable/Empty.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 using System.Reactive.Concurrency;
 using System.Reactive.Disposables;
 

+ 0 - 2
Rx.NET/Source/src/System.Reactive/Linq/Observable/Never.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 using System.Reactive.Disposables;
 
 namespace System.Reactive.Linq.ObservableImpl

+ 0 - 2
Rx.NET/Source/src/System.Reactive/Linq/Observable/Return.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 using System.Reactive.Concurrency;
 using System.Reactive.Disposables;
 

+ 2 - 4
Rx.NET/Source/src/System.Reactive/Subjects/ConnectableObservable.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 using System.Reactive.Linq;
 
 namespace System.Reactive.Subjects
@@ -19,7 +17,7 @@ namespace System.Reactive.Subjects
         private readonly IObservable<TSource> _source;
         private readonly object _gate;
 
-        private Connection _connection;
+        private Connection? _connection;
 
         /// <summary>
         /// Creates an observable that can be connected and disconnected from its source.
@@ -54,7 +52,7 @@ namespace System.Reactive.Subjects
         private sealed class Connection : IDisposable
         {
             private readonly ConnectableObservable<TSource, TResult> _parent;
-            private IDisposable _subscription;
+            private IDisposable? _subscription;
 
             public Connection(ConnectableObservable<TSource, TResult> parent, IDisposable subscription)
             {

+ 0 - 2
Rx.NET/Source/src/System.Reactive/Subjects/Subject.Extensions.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 using System.Reactive.Concurrency;
 using System.Reactive.Linq;
 

+ 0 - 2
Rx.NET/Source/src/System.Reactive/Subjects/SubjectBase.cs

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT License.
 // See the LICENSE file in the project root for more information. 
 
-#nullable disable
-
 namespace System.Reactive.Subjects
 {
     /// <summary>