Просмотр исходного кода

Fix some #nullable in the CAL.

Bart De Smet 5 лет назад
Родитель
Сommit
9e7b65ea03

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

@@ -47,7 +47,7 @@ namespace System.Reactive.Concurrency
         /// <param name="state">State to pass to the method.</param>
         /// <param name="dueTime">Time to execute the method on.</param>
         /// <returns>Disposable object that can be used to stop the timer.</returns>
-        IDisposable StartTimer(Action<object> action, object state, TimeSpan dueTime);
+        IDisposable StartTimer(Action<object?> action, object? state, TimeSpan dueTime);
 
         /// <summary>
         /// Queues a method for periodic execution based on the specified period.
@@ -63,7 +63,7 @@ namespace System.Reactive.Concurrency
         /// <param name="action">Method to execute.</param>
         /// <param name="state">State to pass to the method.</param>
         /// <returns>Disposable object that can be used to cancel the queued method.</returns>
-        IDisposable QueueUserWorkItem(Action<object> action, object state);
+        IDisposable QueueUserWorkItem(Action<object?> action, object? state);
 
         /// <summary>
         /// Blocking sleep operation.
@@ -87,6 +87,6 @@ namespace System.Reactive.Concurrency
         /// </summary>
         /// <param name="action">Method to execute.</param>
         /// <param name="state">State to pass to the method.</param>
-        void StartThread(Action<object> action, object state);
+        void StartThread(Action<object?> action, object? state);
     }
 }

+ 10 - 10
Rx.NET/Source/src/System.Reactive/Concurrency/ConcurrencyAbstractionLayerImpl.cs

@@ -17,17 +17,17 @@ namespace System.Reactive.Concurrency
     {
         private sealed class WorkItem
         {
-            public WorkItem(Action<object> action, object state)
+            public WorkItem(Action<object?> action, object? state)
             {
                 Action = action;
                 State = state;
             }
 
-            public Action<object> Action { get; }
-            public object State { get; }
+            public Action<object?> Action { get; }
+            public object? State { get; }
         }
 
-        public IDisposable StartTimer(Action<object> action, object state, TimeSpan dueTime) => new Timer(action, state, Normalize(dueTime));
+        public IDisposable StartTimer(Action<object?> action, object? state, TimeSpan dueTime) => new Timer(action, state, Normalize(dueTime));
 
         public IDisposable StartPeriodicTimer(Action action, TimeSpan period)
         {
@@ -48,7 +48,7 @@ namespace System.Reactive.Concurrency
             return new PeriodicTimer(action, period);
         }
 
-        public IDisposable QueueUserWorkItem(Action<object> action, object state)
+        public IDisposable QueueUserWorkItem(Action<object?> action, object? state)
         {
             ThreadPool.QueueUserWorkItem(itemObject =>
             {
@@ -66,7 +66,7 @@ namespace System.Reactive.Concurrency
 
         public bool SupportsLongRunning => true;
 
-        public void StartThread(Action<object> action, object state)
+        public void StartThread(Action<object?> action, object? state)
         {
             new Thread(itemObject =>
             {
@@ -152,13 +152,13 @@ namespace System.Reactive.Concurrency
 
         private sealed class Timer : IDisposable
         {
-            private volatile object _state;
-            private Action<object> _action;
+            private volatile object? _state;
+            private Action<object?> _action;
             private IDisposable _timer;
 
             private static readonly object DisposedState = new object();
 
-            public Timer(Action<object> action, object state, TimeSpan dueTime)
+            public Timer(Action<object?> action, object? state, TimeSpan dueTime)
             {
                 _state = state;
                 _action = action;
@@ -188,7 +188,7 @@ namespace System.Reactive.Concurrency
             {
                 if (Disposable.TryDispose(ref _timer))
                 {
-                    _action = Stubs<object>.Ignore;
+                    _action = Stubs<object?>.Ignore;
                     _state = DisposedState;
                 }
             }

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

@@ -42,7 +42,7 @@ namespace System.Reactive.Concurrency
             var workItem = new UserWorkItem<TState>(this, state, action);
 
             workItem.CancelQueueDisposable = Cal.QueueUserWorkItem(
-                static closureWorkItem => ((UserWorkItem<TState>)closureWorkItem).Run(),
+                static closureWorkItem => ((UserWorkItem<TState>)closureWorkItem!).Run(),
                 workItem);
 
             return workItem;
@@ -73,7 +73,7 @@ namespace System.Reactive.Concurrency
             var workItem = new UserWorkItem<TState>(this, state, action);
 
             workItem.CancelQueueDisposable = Cal.StartTimer(
-                static closureWorkItem => ((UserWorkItem<TState>)closureWorkItem).Run(),
+                static closureWorkItem => ((UserWorkItem<TState>)closureWorkItem!).Run(),
                 workItem,
                 dt);
 
@@ -171,7 +171,7 @@ namespace System.Reactive.Concurrency
                     Cal.StartThread(
                         thisObject =>
                         {
-                            var @this = (LongScheduledWorkItem<TState>)thisObject;
+                            var @this = (LongScheduledWorkItem<TState>)thisObject!;
 
                             //
                             // Notice we don't check d.IsDisposed. The contract for ISchedulerLongRunning

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

@@ -378,13 +378,13 @@ namespace System.Reactive.Concurrency
             }
         }
 
-        private void Tick(object state)
+        private void Tick(object? state)
         {
             lock (_gate)
             {
                 if (!_disposed)
                 {
-                    var item = (ScheduledItem<TimeSpan>)state;
+                    var item = (ScheduledItem<TimeSpan>)state!;
                     if (item == _nextItem)
                     {
                         _nextItem = null;

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Concurrency/UserWorkItem.cs

@@ -32,7 +32,7 @@ namespace System.Reactive.Concurrency
 
         public IDisposable CancelQueueDisposable
         {
-            get => Disposable.GetValue(ref _cancelQueueDisposable);
+            //get => Disposable.GetValue(ref _cancelQueueDisposable);
             set => Disposable.SetSingle(ref _cancelQueueDisposable, value);
         }
 

+ 3 - 3
Rx.NET/Source/tests/Tests.System.Reactive.ApiApprovals/Api/ApiApprovalTests.Core.verified.cs

@@ -302,12 +302,12 @@ namespace System.Reactive.Concurrency
     public interface IConcurrencyAbstractionLayer
     {
         bool SupportsLongRunning { get; }
-        System.IDisposable QueueUserWorkItem(System.Action<object> action, object state);
+        System.IDisposable QueueUserWorkItem(System.Action<object?> action, object? state);
         void Sleep(System.TimeSpan timeout);
         System.IDisposable StartPeriodicTimer(System.Action action, System.TimeSpan period);
         System.Reactive.Concurrency.IStopwatch StartStopwatch();
-        void StartThread(System.Action<object> action, object state);
-        System.IDisposable StartTimer(System.Action<object> action, object state, System.TimeSpan dueTime);
+        void StartThread(System.Action<object?> action, object? state);
+        System.IDisposable StartTimer(System.Action<object?> action, object? state, System.TimeSpan dueTime);
     }
     public interface IScheduledItem<TAbsolute>
     {