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

Merge branch 'develop' of https://github.com/Reactive-Extensions/Rx.NET into RenameOmega

Bart De Smet 8 лет назад
Родитель
Сommit
3a03004a37
82 измененных файлов с 765 добавлено и 1095 удалено
  1. 4 1
      Rx.NET/Source/src/System.Reactive/Concurrency/AsyncLock.cs
  2. 9 10
      Rx.NET/Source/src/System.Reactive/Concurrency/CatchScheduler.cs
  3. 1 4
      Rx.NET/Source/src/System.Reactive/Concurrency/ConcurrencyAbstractionLayer.cs
  4. 4 18
      Rx.NET/Source/src/System.Reactive/Concurrency/ConcurrencyAbstractionLayerImpl.Windows.cs
  5. 11 43
      Rx.NET/Source/src/System.Reactive/Concurrency/ConcurrencyAbstractionLayerImpl.cs
  6. 14 30
      Rx.NET/Source/src/System.Reactive/Concurrency/CurrentThreadScheduler.cs
  7. 10 12
      Rx.NET/Source/src/System.Reactive/Concurrency/DefaultScheduler.cs
  8. 1 1
      Rx.NET/Source/src/System.Reactive/Concurrency/DisableOptimizationsScheduler.cs
  9. 7 5
      Rx.NET/Source/src/System.Reactive/Concurrency/EventLoopScheduler.cs
  10. 19 19
      Rx.NET/Source/src/System.Reactive/Concurrency/HistoricalScheduler.cs
  11. 1 1
      Rx.NET/Source/src/System.Reactive/Concurrency/IScheduler.cs
  12. 1 1
      Rx.NET/Source/src/System.Reactive/Concurrency/ISchedulerLongRunning.cs
  13. 0 2
      Rx.NET/Source/src/System.Reactive/Concurrency/ISchedulerPeriodic.cs
  14. 0 2
      Rx.NET/Source/src/System.Reactive/Concurrency/IStopwatch.cs
  15. 1 3
      Rx.NET/Source/src/System.Reactive/Concurrency/IStopwatchProvider.cs
  16. 21 9
      Rx.NET/Source/src/System.Reactive/Concurrency/ImmediateScheduler.cs
  17. 15 30
      Rx.NET/Source/src/System.Reactive/Concurrency/LocalScheduler.TimerQueue.cs
  18. 8 17
      Rx.NET/Source/src/System.Reactive/Concurrency/LocalScheduler.cs
  19. 7 13
      Rx.NET/Source/src/System.Reactive/Concurrency/NewThreadScheduler.cs
  20. 32 58
      Rx.NET/Source/src/System.Reactive/Concurrency/ScheduledItem.cs
  21. 23 25
      Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Async.cs
  22. 22 10
      Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Recursive.cs
  23. 23 14
      Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.Emulation.cs
  24. 23 32
      Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.cs
  25. 5 5
      Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Simple.cs
  26. 3 3
      Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Wrappers.cs
  27. 11 58
      Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.cs
  28. 5 5
      Rx.NET/Source/src/System.Reactive/Concurrency/SchedulerDefaults.cs
  29. 5 15
      Rx.NET/Source/src/System.Reactive/Concurrency/SchedulerOperation.cs
  30. 5 20
      Rx.NET/Source/src/System.Reactive/Concurrency/SchedulerQueue.cs
  31. 1 4
      Rx.NET/Source/src/System.Reactive/Concurrency/SchedulerWrapper.cs
  32. 8 8
      Rx.NET/Source/src/System.Reactive/Concurrency/Synchronization.ObserveOn.cs
  33. 7 7
      Rx.NET/Source/src/System.Reactive/Concurrency/Synchronization.Synchronize.cs
  34. 8 6
      Rx.NET/Source/src/System.Reactive/Concurrency/Synchronization.cs
  35. 8 4
      Rx.NET/Source/src/System.Reactive/Concurrency/SynchronizationContextScheduler.cs
  36. 1 1
      Rx.NET/Source/src/System.Reactive/Concurrency/TaskHelpers.cs
  37. 18 15
      Rx.NET/Source/src/System.Reactive/Concurrency/TaskPoolScheduler.cs
  38. 6 7
      Rx.NET/Source/src/System.Reactive/Concurrency/Thread.Stub.cs
  39. 21 25
      Rx.NET/Source/src/System.Reactive/Concurrency/ThreadPoolScheduler.Windows.cs
  40. 17 28
      Rx.NET/Source/src/System.Reactive/Concurrency/ThreadPoolScheduler.cs
  41. 5 5
      Rx.NET/Source/src/System.Reactive/Concurrency/VirtualTimeScheduler.Extensions.cs
  42. 28 31
      Rx.NET/Source/src/System.Reactive/Concurrency/VirtualTimeScheduler.cs
  43. 5 10
      Rx.NET/Source/src/System.Reactive/Internal/AnonymousEnumerable.cs
  44. 1 1
      Rx.NET/Source/src/System.Reactive/Internal/AsyncLockObserver.cs
  45. 14 10
      Rx.NET/Source/src/System.Reactive/Internal/AutoDetachObserver.cs
  46. 3 3
      Rx.NET/Source/src/System.Reactive/Internal/BinaryObserver.cs
  47. 1 1
      Rx.NET/Source/src/System.Reactive/Internal/CheckedObserver.cs
  48. 4 14
      Rx.NET/Source/src/System.Reactive/Internal/ConcatSink.cs
  49. 2 2
      Rx.NET/Source/src/System.Reactive/Internal/Constants.cs
  50. 4 2
      Rx.NET/Source/src/System.Reactive/Internal/CurrentPlatformEnlightenmentProvider.cs
  51. 19 50
      Rx.NET/Source/src/System.Reactive/Internal/Either.Generic.cs
  52. 3 4
      Rx.NET/Source/src/System.Reactive/Internal/ExceptionServices.Default.cs
  53. 3 4
      Rx.NET/Source/src/System.Reactive/Internal/ExceptionServices.cs
  54. 3 4
      Rx.NET/Source/src/System.Reactive/Internal/ExceptionServicesImpl.cs
  55. 1 1
      Rx.NET/Source/src/System.Reactive/Internal/IConcatenatable.cs
  56. 1 1
      Rx.NET/Source/src/System.Reactive/Internal/IEvaluatableObservable.cs
  57. 10 8
      Rx.NET/Source/src/System.Reactive/Internal/ImmutableList.cs
  58. 24 36
      Rx.NET/Source/src/System.Reactive/Internal/Lookup.cs
  59. 19 26
      Rx.NET/Source/src/System.Reactive/Internal/Observers.cs
  60. 5 5
      Rx.NET/Source/src/System.Reactive/Internal/PlatformEnlightenmentProvider.cs
  61. 22 7
      Rx.NET/Source/src/System.Reactive/Internal/PriorityQueue.cs
  62. 2 2
      Rx.NET/Source/src/System.Reactive/Internal/Producer.cs
  63. 4 10
      Rx.NET/Source/src/System.Reactive/Internal/QueryServices.cs
  64. 11 18
      Rx.NET/Source/src/System.Reactive/Internal/ReflectionUtils.cs
  65. 7 1
      Rx.NET/Source/src/System.Reactive/Internal/SafeObserver.cs
  66. 7 11
      Rx.NET/Source/src/System.Reactive/Internal/ScheduledObserver.cs
  67. 3 10
      Rx.NET/Source/src/System.Reactive/Internal/Sink.cs
  68. 1 4
      Rx.NET/Source/src/System.Reactive/Internal/StopwatchImpl.cs
  69. 0 4
      Rx.NET/Source/src/System.Reactive/Internal/SynchronizationContextExtensions.cs
  70. 1 1
      Rx.NET/Source/src/System.Reactive/Internal/SynchronizedObserver.cs
  71. 1 4
      Rx.NET/Source/src/System.Reactive/Internal/SystemClock.Default.cs
  72. 3 6
      Rx.NET/Source/src/System.Reactive/Internal/SystemClock.cs
  73. 7 5
      Rx.NET/Source/src/System.Reactive/Internal/TailRecursiveSink.cs
  74. 28 30
      Rx.NET/Source/src/System.Reactive/Platforms/Windows/Concurrency/CoreDispatcherScheduler.cs
  75. 35 52
      Rx.NET/Source/src/System.Reactive/Platforms/Windows/Concurrency/DispatcherScheduler.cs
  76. 21 28
      Rx.NET/Source/src/System.Reactive/Subjects/AsyncSubject.cs
  77. 14 11
      Rx.NET/Source/src/System.Reactive/Subjects/BehaviorSubject.cs
  78. 1 1
      Rx.NET/Source/src/System.Reactive/Subjects/ConnectableObservable.cs
  79. 42 81
      Rx.NET/Source/src/System.Reactive/Subjects/ReplaySubject.cs
  80. 10 16
      Rx.NET/Source/src/System.Reactive/Subjects/Subject.Extensions.cs
  81. 1 1
      Rx.NET/Source/src/System.Reactive/Subjects/Subject.cs
  82. 3 3
      Rx.NET/Source/src/System.Reactive/Subjects/SubjectBase.cs

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

@@ -21,7 +21,7 @@ namespace System.Reactive.Concurrency
         /// processed by the owner.
         /// processed by the owner.
         /// </summary>
         /// </summary>
         /// <param name="action">Action to queue for execution.</param>
         /// <param name="action">Action to queue for execution.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public void Wait(Action action)
         public void Wait(Action action)
         {
         {
             if (action == null)
             if (action == null)
@@ -46,7 +46,9 @@ namespace System.Reactive.Concurrency
                     lock (queue)
                     lock (queue)
                     {
                     {
                         if (queue.Count > 0)
                         if (queue.Count > 0)
+                        {
                             work = queue.Dequeue();
                             work = queue.Dequeue();
+                        }
                         else
                         else
                         {
                         {
                             isAcquired = false;
                             isAcquired = false;
@@ -65,6 +67,7 @@ namespace System.Reactive.Concurrency
                             queue.Clear();
                             queue.Clear();
                             hasFaulted = true;
                             hasFaulted = true;
                         }
                         }
+
                         throw;
                         throw;
                     }
                     }
                 }
                 }

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

@@ -7,7 +7,7 @@ using System.Runtime.CompilerServices;
 
 
 namespace System.Reactive.Concurrency
 namespace System.Reactive.Concurrency
 {
 {
-    class CatchScheduler<TException> : SchedulerWrapper
+    internal sealed class CatchScheduler<TException> : SchedulerWrapper
         where TException : Exception
         where TException : Exception
     {
     {
         private readonly Func<TException, bool> _handler;
         private readonly Func<TException, bool> _handler;
@@ -26,11 +26,8 @@ namespace System.Reactive.Concurrency
                 {
                 {
                     return action(GetRecursiveWrapper(self), state);
                     return action(GetRecursiveWrapper(self), state);
                 }
                 }
-                catch (TException exception)
+                catch (TException exception) when (_handler(exception))
                 {
                 {
-                    if (!_handler(exception))
-                        throw;
-
                     return Disposable.Empty;
                     return Disposable.Empty;
                 }
                 }
             };
             };
@@ -54,15 +51,19 @@ namespace System.Reactive.Concurrency
             if (service != null)
             if (service != null)
             {
             {
                 if (serviceType == typeof(ISchedulerLongRunning))
                 if (serviceType == typeof(ISchedulerLongRunning))
+                {
                     service = new CatchSchedulerLongRunning((ISchedulerLongRunning)service, _handler);
                     service = new CatchSchedulerLongRunning((ISchedulerLongRunning)service, _handler);
+                }
                 else if (serviceType == typeof(ISchedulerPeriodic))
                 else if (serviceType == typeof(ISchedulerPeriodic))
+                {
                     service = new CatchSchedulerPeriodic((ISchedulerPeriodic)service, _handler);
                     service = new CatchSchedulerPeriodic((ISchedulerPeriodic)service, _handler);
+                }
             }
             }
 
 
             return true;
             return true;
         }
         }
 
 
-        class CatchSchedulerLongRunning : ISchedulerLongRunning
+        private class CatchSchedulerLongRunning : ISchedulerLongRunning
         {
         {
             private readonly ISchedulerLongRunning _scheduler;
             private readonly ISchedulerLongRunning _scheduler;
             private readonly Func<TException, bool> _handler;
             private readonly Func<TException, bool> _handler;
@@ -81,16 +82,14 @@ namespace System.Reactive.Concurrency
                     {
                     {
                         action(state_, cancel);
                         action(state_, cancel);
                     }
                     }
-                    catch (TException exception)
+                    catch (TException exception) when (_handler(exception))
                     {
                     {
-                        if (!_handler(exception))
-                            throw;
                     }
                     }
                 });
                 });
             }
             }
         }
         }
 
 
-        class CatchSchedulerPeriodic : ISchedulerPeriodic
+        private sealed class CatchSchedulerPeriodic : ISchedulerPeriodic
         {
         {
             private readonly ISchedulerPeriodic _scheduler;
             private readonly ISchedulerPeriodic _scheduler;
             private readonly Func<TException, bool> _handler;
             private readonly Func<TException, bool> _handler;

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

@@ -75,10 +75,7 @@ namespace System.Reactive.Concurrency
         /// <summary>
         /// <summary>
         /// Gets whether long-running scheduling is supported.
         /// Gets whether long-running scheduling is supported.
         /// </summary>
         /// </summary>
-        bool SupportsLongRunning
-        {
-            get;
-        }
+        bool SupportsLongRunning { get; }
 
 
         /// <summary>
         /// <summary>
         /// Starts a new long-running thread.
         /// Starts a new long-running thread.

+ 4 - 18
Rx.NET/Source/src/System.Reactive/Concurrency/ConcurrencyAbstractionLayerImpl.Windows.cs

@@ -3,8 +3,6 @@
 // See the LICENSE file in the project root for more information. 
 // See the LICENSE file in the project root for more information. 
 
 
 #if NO_THREAD && WINDOWS
 #if NO_THREAD && WINDOWS
-using System;
-using System.Collections.Generic;
 using System.Reactive.Disposables;
 using System.Reactive.Disposables;
 using System.Threading;
 using System.Threading;
 
 
@@ -72,28 +70,16 @@ namespace System.Reactive.Concurrency
             e.Wait();
             e.Wait();
         }
         }
 
 
-        public IStopwatch StartStopwatch()
-        {
-            return new StopwatchImpl();
-        }
+        public IStopwatch StartStopwatch() => new StopwatchImpl();
 
 
-        public bool SupportsLongRunning
-        {
-            get { return false; }
-        }
+        public bool SupportsLongRunning => false;
 
 
         public void StartThread(Action<object> action, object state)
         public void StartThread(Action<object> action, object state)
         {
         {
             throw new NotSupportedException();
             throw new NotSupportedException();
         }
         }
 
 
-        private TimeSpan Normalize(TimeSpan dueTime)
-        {
-            if (dueTime < TimeSpan.Zero)
-                return TimeSpan.Zero;
-
-            return dueTime;
-        }
+        private TimeSpan Normalize(TimeSpan dueTime) => dueTime < TimeSpan.Zero ? TimeSpan.Zero : dueTime;
     }
     }
 }
 }
-#endif
+#endif

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

@@ -3,7 +3,6 @@
 // See the LICENSE file in the project root for more information. 
 // See the LICENSE file in the project root for more information. 
 
 
 #if !NO_THREAD
 #if !NO_THREAD
-using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Reactive.Disposables;
 using System.Reactive.Disposables;
 using System.Threading;
 using System.Threading;
@@ -17,10 +16,7 @@ namespace System.Reactive.Concurrency
     //
     //
     internal class /*Default*/ConcurrencyAbstractionLayerImpl : IConcurrencyAbstractionLayer
     internal class /*Default*/ConcurrencyAbstractionLayerImpl : IConcurrencyAbstractionLayer
     {
     {
-        public IDisposable StartTimer(Action<object> action, object state, TimeSpan dueTime)
-        {
-            return 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)
         public IDisposable StartPeriodicTimer(Action action, TimeSpan period)
         {
         {
@@ -47,27 +43,11 @@ namespace System.Reactive.Concurrency
             return Disposable.Empty;
             return Disposable.Empty;
         }
         }
 
 
-#if USE_SLEEP_MS
-        public void Sleep(TimeSpan timeout)
-        {
-            System.Threading.Thread.Sleep((int)Normalize(timeout).TotalMilliseconds);
-        }
-#else
-        public void Sleep(TimeSpan timeout)
-        {
-            System.Threading.Thread.Sleep(Normalize(timeout));
-        }
-#endif
+        public void Sleep(TimeSpan timeout) => System.Threading.Thread.Sleep(Normalize(timeout));
 
 
-        public IStopwatch StartStopwatch()
-        {
-            return new StopwatchImpl();
-        }
+        public IStopwatch StartStopwatch() => new StopwatchImpl();
 
 
-        public bool SupportsLongRunning
-        {
-            get { return true; }
-        }
+        public bool SupportsLongRunning => true;
 
 
         public void StartThread(Action<object> action, object state)
         public void StartThread(Action<object> action, object state)
         {
         {
@@ -77,13 +57,7 @@ namespace System.Reactive.Concurrency
             }) { IsBackground = true }.Start();
             }) { IsBackground = true }.Start();
         }
         }
 
 
-        private static TimeSpan Normalize(TimeSpan dueTime)
-        {
-            if (dueTime < TimeSpan.Zero)
-                return TimeSpan.Zero;
-
-            return dueTime;
-        }
+        private static TimeSpan Normalize(TimeSpan dueTime) => dueTime < TimeSpan.Zero ? TimeSpan.Zero : dueTime;
 
 
         //
         //
         // Some historical context. In the early days of Rx, we discovered an issue with
         // Some historical context. In the early days of Rx, we discovered an issue with
@@ -156,7 +130,7 @@ namespace System.Reactive.Concurrency
         //                 symbol.
         //                 symbol.
         //
         //
 
 
-        class Timer : IDisposable
+        private sealed class Timer : IDisposable
         {
         {
             private Action<object> _action;
             private Action<object> _action;
             private volatile System.Threading.Timer _timer;
             private volatile System.Threading.Timer _timer;
@@ -190,10 +164,7 @@ namespace System.Reactive.Concurrency
                 }
                 }
             }
             }
 
 
-            private bool IsTimerAssigned()
-            {
-                return _timer != null;
-            }
+            private bool IsTimerAssigned() => _timer != null;
 
 
             public void Dispose()
             public void Dispose()
             {
             {
@@ -208,7 +179,7 @@ namespace System.Reactive.Concurrency
             }
             }
         }
         }
 
 
-        class PeriodicTimer : IDisposable
+        private sealed class PeriodicTimer : IDisposable
         {
         {
             private Action _action;
             private Action _action;
             private volatile System.Threading.Timer _timer;
             private volatile System.Threading.Timer _timer;
@@ -224,10 +195,7 @@ namespace System.Reactive.Concurrency
                 _timer = new System.Threading.Timer(this.Tick, null, period, period);
                 _timer = new System.Threading.Timer(this.Tick, null, period, period);
             }
             }
 
 
-            private void Tick(object state)
-            {
-                _action();
-            }
+            private void Tick(object state) => _action();
 
 
             public void Dispose()
             public void Dispose()
             {
             {
@@ -242,7 +210,7 @@ namespace System.Reactive.Concurrency
             }
             }
         }
         }
 
 
-        class FastPeriodicTimer : IDisposable
+        private sealed class FastPeriodicTimer : IDisposable
         {
         {
             private readonly Action _action;
             private readonly Action _action;
             private volatile bool disposed;
             private volatile bool disposed;
@@ -274,4 +242,4 @@ namespace System.Reactive.Concurrency
         }
         }
     }
     }
 }
 }
-#endif
+#endif

+ 14 - 30
Rx.NET/Source/src/System.Reactive/Concurrency/CurrentThreadScheduler.cs

@@ -16,28 +16,22 @@ namespace System.Reactive.Concurrency
     {
     {
         private static readonly Lazy<CurrentThreadScheduler> s_instance = new Lazy<CurrentThreadScheduler>(() => new CurrentThreadScheduler());
         private static readonly Lazy<CurrentThreadScheduler> s_instance = new Lazy<CurrentThreadScheduler>(() => new CurrentThreadScheduler());
 
 
-        CurrentThreadScheduler()
+        private CurrentThreadScheduler()
         {
         {
         }
         }
 
 
         /// <summary>
         /// <summary>
         /// Gets the singleton instance of the current thread scheduler.
         /// Gets the singleton instance of the current thread scheduler.
         /// </summary>
         /// </summary>
-        public static CurrentThreadScheduler Instance
-        {
-            get { return s_instance.Value; }
-        }
+        public static CurrentThreadScheduler Instance => s_instance.Value;
 
 
         [ThreadStatic]
         [ThreadStatic]
-        static SchedulerQueue<TimeSpan> s_threadLocalQueue;
+        private static SchedulerQueue<TimeSpan> s_threadLocalQueue;
 
 
         [ThreadStatic]
         [ThreadStatic]
-        static IStopwatch s_clock;
+        private static IStopwatch s_clock;
 
 
-        private static SchedulerQueue<TimeSpan> GetQueue()
-        {
-            return s_threadLocalQueue;
-        }
+        private static SchedulerQueue<TimeSpan> GetQueue() => s_threadLocalQueue;
 
 
         private static void SetQueue(SchedulerQueue<TimeSpan> newQueue)
         private static void SetQueue(SchedulerQueue<TimeSpan> newQueue)
         {
         {
@@ -61,25 +55,13 @@ namespace System.Reactive.Concurrency
         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Now marked as obsolete.")]
         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Now marked as obsolete.")]
         [EditorBrowsable(EditorBrowsableState.Never)]
         [EditorBrowsable(EditorBrowsableState.Never)]
         [Obsolete(Constants_Core.OBSOLETE_SCHEDULEREQUIRED)] // Preferring static method call over instance method call.
         [Obsolete(Constants_Core.OBSOLETE_SCHEDULEREQUIRED)] // Preferring static method call over instance method call.
-        public bool ScheduleRequired
-        {
-            get
-            {
-                return IsScheduleRequired;
-            }
-        }
+        public bool ScheduleRequired => IsScheduleRequired;
 
 
         /// <summary>
         /// <summary>
         /// Gets a value that indicates whether the caller must call a Schedule method.
         /// Gets a value that indicates whether the caller must call a Schedule method.
         /// </summary>
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Advanced)]
         [EditorBrowsable(EditorBrowsableState.Advanced)]
-        public static bool IsScheduleRequired
-        {
-            get
-            {
-                return GetQueue() == null;
-            }
-        }
+        public static bool IsScheduleRequired => GetQueue() == null;
 
 
         /// <summary>
         /// <summary>
         /// Schedules an action to be executed after dueTime.
         /// Schedules an action to be executed after dueTime.
@@ -89,7 +71,7 @@ namespace System.Reactive.Concurrency
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public override IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
         public override IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
         {
         {
             if (action == null)
             if (action == null)
@@ -106,14 +88,14 @@ namespace System.Reactive.Concurrency
                 queue = new SchedulerQueue<TimeSpan>(4);
                 queue = new SchedulerQueue<TimeSpan>(4);
                 queue.Enqueue(si);
                 queue.Enqueue(si);
 
 
-                CurrentThreadScheduler.SetQueue(queue);
+                SetQueue(queue);
                 try
                 try
                 {
                 {
                     Trampoline.Run(queue);
                     Trampoline.Run(queue);
                 }
                 }
                 finally
                 finally
                 {
                 {
-                    CurrentThreadScheduler.SetQueue(null);
+                    SetQueue(null);
                 }
                 }
             }
             }
             else
             else
@@ -124,7 +106,7 @@ namespace System.Reactive.Concurrency
             return Disposable.Create(si.Cancel);
             return Disposable.Create(si.Cancel);
         }
         }
 
 
-        static class Trampoline
+        private static class Trampoline
         {
         {
             public static void Run(SchedulerQueue<TimeSpan> queue)
             public static void Run(SchedulerQueue<TimeSpan> queue)
             {
             {
@@ -133,14 +115,16 @@ namespace System.Reactive.Concurrency
                     var item = queue.Dequeue();
                     var item = queue.Dequeue();
                     if (!item.IsCanceled)
                     if (!item.IsCanceled)
                     {
                     {
-                        var wait = item.DueTime - CurrentThreadScheduler.Time;
+                        var wait = item.DueTime - Time;
                         if (wait.Ticks > 0)
                         if (wait.Ticks > 0)
                         {
                         {
                             ConcurrencyAbstractionLayer.Current.Sleep(wait);
                             ConcurrencyAbstractionLayer.Current.Sleep(wait);
                         }
                         }
 
 
                         if (!item.IsCanceled)
                         if (!item.IsCanceled)
+                        {
                             item.Invoke();
                             item.Invoke();
+                        }
                     }
                     }
                 }
                 }
             }
             }

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

@@ -18,13 +18,7 @@ namespace System.Reactive.Concurrency
         /// <summary>
         /// <summary>
         /// Gets the singleton instance of the default scheduler.
         /// Gets the singleton instance of the default scheduler.
         /// </summary>
         /// </summary>
-        public static DefaultScheduler Instance
-        {
-            get
-            {
-                return s_instance.Value;
-            }
-        }
+        public static DefaultScheduler Instance => s_instance.Value;
 
 
         private DefaultScheduler()
         private DefaultScheduler()
         {
         {
@@ -37,7 +31,7 @@ namespace System.Reactive.Concurrency
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public override IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
         public override IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
         {
         {
             if (action == null)
             if (action == null)
@@ -48,7 +42,9 @@ namespace System.Reactive.Concurrency
             var cancel = s_cal.QueueUserWorkItem(_ =>
             var cancel = s_cal.QueueUserWorkItem(_ =>
             {
             {
                 if (!d.IsDisposed)
                 if (!d.IsDisposed)
+                {
                     d.Disposable = action(this, state);
                     d.Disposable = action(this, state);
+                }
             }, null);
             }, null);
 
 
             return StableCompositeDisposable.Create(
             return StableCompositeDisposable.Create(
@@ -65,7 +61,7 @@ namespace System.Reactive.Concurrency
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public override IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
         public override IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
         {
         {
             if (action == null)
             if (action == null)
@@ -80,7 +76,9 @@ namespace System.Reactive.Concurrency
             var cancel = s_cal.StartTimer(_ =>
             var cancel = s_cal.StartTimer(_ =>
             {
             {
                 if (!d.IsDisposed)
                 if (!d.IsDisposed)
+                {
                     d.Disposable = action(this, state);
                     d.Disposable = action(this, state);
+                }
             }, null, dt);
             }, null, dt);
 
 
             return StableCompositeDisposable.Create(
             return StableCompositeDisposable.Create(
@@ -97,8 +95,8 @@ namespace System.Reactive.Concurrency
         /// <param name="period">Period for running the work periodically.</param>
         /// <param name="period">Period for running the work periodically.</param>
         /// <param name="action">Action to be executed, potentially updating the state.</param>
         /// <param name="action">Action to be executed, potentially updating the state.</param>
         /// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns>
-        /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than TimeSpan.Zero.</exception>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than <see cref="TimeSpan.Zero"/>.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public IDisposable SchedulePeriodic<TState>(TState state, TimeSpan period, Func<TState, TState> action)
         public IDisposable SchedulePeriodic<TState>(TState state, TimeSpan period, Func<TState, TState> action)
         {
         {
             if (period < TimeSpan.Zero)
             if (period < TimeSpan.Zero)
@@ -143,7 +141,7 @@ namespace System.Reactive.Concurrency
             return base.GetService(serviceType);
             return base.GetService(serviceType);
         }
         }
 
 
-        class LongRunning : ISchedulerLongRunning
+        private sealed class LongRunning : ISchedulerLongRunning
         {
         {
             public static ISchedulerLongRunning Instance = new LongRunning();
             public static ISchedulerLongRunning Instance = new LongRunning();
 
 

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

@@ -7,7 +7,7 @@ using System.Runtime.CompilerServices;
 
 
 namespace System.Reactive.Concurrency
 namespace System.Reactive.Concurrency
 {
 {
-    class DisableOptimizationsScheduler : SchedulerWrapper
+    internal sealed class DisableOptimizationsScheduler : SchedulerWrapper
     {
     {
         private readonly Type[] _optimizationInterfaces;
         private readonly Type[] _optimizationInterfaces;
 
 

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

@@ -91,7 +91,7 @@ namespace System.Reactive.Concurrency
         /// Creates an object that schedules units of work on a designated thread, using the specified factory to control thread creation options.
         /// Creates an object that schedules units of work on a designated thread, using the specified factory to control thread creation options.
         /// </summary>
         /// </summary>
         /// <param name="threadFactory">Factory function for thread creation.</param>
         /// <param name="threadFactory">Factory function for thread creation.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="threadFactory"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="threadFactory"/> is <c>null</c>.</exception>
         public EventLoopScheduler(Func<ThreadStart, Thread> threadFactory)
         public EventLoopScheduler(Func<ThreadStart, Thread> threadFactory)
         {
         {
             if (threadFactory == null)
             if (threadFactory == null)
@@ -141,7 +141,7 @@ namespace System.Reactive.Concurrency
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         /// <exception cref="ObjectDisposedException">The scheduler has been disposed and doesn't accept new work.</exception>
         /// <exception cref="ObjectDisposedException">The scheduler has been disposed and doesn't accept new work.</exception>
         public override IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
         public override IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
         {
         {
@@ -181,8 +181,8 @@ namespace System.Reactive.Concurrency
         /// <param name="period">Period for running the work periodically.</param>
         /// <param name="period">Period for running the work periodically.</param>
         /// <param name="action">Action to be executed, potentially updating the state.</param>
         /// <param name="action">Action to be executed, potentially updating the state.</param>
         /// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
-        /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than TimeSpan.Zero.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
+        /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than <see cref="TimeSpan.Zero"/>.</exception>
         /// <exception cref="ObjectDisposedException">The scheduler has been disposed and doesn't accept new work.</exception>
         /// <exception cref="ObjectDisposedException">The scheduler has been disposed and doesn't accept new work.</exception>
         public IDisposable SchedulePeriodic<TState>(TState state, TimeSpan period, Func<TState, TState> action)
         public IDisposable SchedulePeriodic<TState>(TState state, TimeSpan period, Func<TState, TState> action)
         {
         {
@@ -325,7 +325,9 @@ namespace System.Reactive.Concurrency
                     foreach (var item in ready)
                     foreach (var item in ready)
                     {
                     {
                         if (!item.IsCanceled)
                         if (!item.IsCanceled)
+                        {
                             item.Invoke();
                             item.Invoke();
+                        }
                     }
                     }
                 }
                 }
 
 
@@ -362,4 +364,4 @@ namespace System.Reactive.Concurrency
 
 
         #endregion
         #endregion
     }
     }
-}
+}

+ 19 - 19
Rx.NET/Source/src/System.Reactive/Concurrency/HistoricalScheduler.cs

@@ -8,12 +8,12 @@ using System.Reactive.Disposables;
 namespace System.Reactive.Concurrency
 namespace System.Reactive.Concurrency
 {
 {
     /// <summary>
     /// <summary>
-    /// Base class for historical schedulers, which are virtual time schedulers that use DateTimeOffset for absolute time and TimeSpan for relative time.
+    /// Base class for historical schedulers, which are virtual time schedulers that use <see cref="DateTimeOffset"/> for absolute time and <see cref="TimeSpan"/> for relative time.
     /// </summary>
     /// </summary>
     public abstract class HistoricalSchedulerBase : VirtualTimeSchedulerBase<DateTimeOffset, TimeSpan>
     public abstract class HistoricalSchedulerBase : VirtualTimeSchedulerBase<DateTimeOffset, TimeSpan>
     {
     {
         /// <summary>
         /// <summary>
-        /// Creates a new historical scheduler with the minimum value of DateTimeOffset as the initial clock value.
+        /// Creates a new historical scheduler with the minimum value of <see cref="DateTimeOffset"/> as the initial clock value.
         /// </summary>
         /// </summary>
         protected HistoricalSchedulerBase()
         protected HistoricalSchedulerBase()
             : base(DateTimeOffset.MinValue, Comparer<DateTimeOffset>.Default)
             : base(DateTimeOffset.MinValue, Comparer<DateTimeOffset>.Default)
@@ -51,35 +51,29 @@ namespace System.Reactive.Concurrency
         }
         }
 
 
         /// <summary>
         /// <summary>
-        /// Converts the absolute time value to a DateTimeOffset value.
+        /// Converts the absolute time value to a <see cref="DateTimeOffset"/> value.
         /// </summary>
         /// </summary>
         /// <param name="absolute">Absolute time value to convert.</param>
         /// <param name="absolute">Absolute time value to convert.</param>
-        /// <returns>The corresponding DateTimeOffset value.</returns>
-        protected override DateTimeOffset ToDateTimeOffset(DateTimeOffset absolute)
-        {
-            return absolute;
-        }
+        /// <returns>The corresponding <see cref="DateTimeOffset"/> value.</returns>
+        protected override DateTimeOffset ToDateTimeOffset(DateTimeOffset absolute) => absolute;
 
 
         /// <summary>
         /// <summary>
-        /// Converts the TimeSpan value to a relative time value.
+        /// Converts the <see cref="TimeSpan"/> value to a relative time value.
         /// </summary>
         /// </summary>
-        /// <param name="timeSpan">TimeSpan value to convert.</param>
+        /// <param name="timeSpan"><see cref="TimeSpan"/> value to convert.</param>
         /// <returns>The corresponding relative time value.</returns>
         /// <returns>The corresponding relative time value.</returns>
-        protected override TimeSpan ToRelative(TimeSpan timeSpan)
-        {
-            return timeSpan;
-        }
+        protected override TimeSpan ToRelative(TimeSpan timeSpan) => timeSpan;
     }
     }
 
 
     /// <summary>
     /// <summary>
-    /// Provides a virtual time scheduler that uses DateTimeOffset for absolute time and TimeSpan for relative time.
+    /// Provides a virtual time scheduler that uses <see cref="DateTimeOffset"/> for absolute time and <see cref="TimeSpan"/> for relative time.
     /// </summary>
     /// </summary>
     public class HistoricalScheduler : HistoricalSchedulerBase
     public class HistoricalScheduler : HistoricalSchedulerBase
     {
     {
         private readonly SchedulerQueue<DateTimeOffset> queue = new SchedulerQueue<DateTimeOffset>();
         private readonly SchedulerQueue<DateTimeOffset> queue = new SchedulerQueue<DateTimeOffset>();
 
 
         /// <summary>
         /// <summary>
-        /// Creates a new historical scheduler with the minimum value of DateTimeOffset as the initial clock value.
+        /// Creates a new historical scheduler with the minimum value of <see cref="DateTimeOffset"/> as the initial clock value.
         /// </summary>
         /// </summary>
         public HistoricalScheduler()
         public HistoricalScheduler()
             : base()
             : base()
@@ -100,7 +94,7 @@ namespace System.Reactive.Concurrency
         /// </summary>
         /// </summary>
         /// <param name="initialClock">Initial value for the clock.</param>
         /// <param name="initialClock">Initial value for the clock.</param>
         /// <param name="comparer">Comparer to determine causality of events based on absolute time.</param>
         /// <param name="comparer">Comparer to determine causality of events based on absolute time.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="comparer"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="comparer"/> is <c>null</c>.</exception>
         public HistoricalScheduler(DateTimeOffset initialClock, IComparer<DateTimeOffset> comparer)
         public HistoricalScheduler(DateTimeOffset initialClock, IComparer<DateTimeOffset> comparer)
             : base(initialClock, comparer)
             : base(initialClock, comparer)
         {
         {
@@ -115,23 +109,29 @@ namespace System.Reactive.Concurrency
             while (queue.Count > 0)
             while (queue.Count > 0)
             {
             {
                 var next = queue.Peek();
                 var next = queue.Peek();
+
                 if (next.IsCanceled)
                 if (next.IsCanceled)
+                {
                     queue.Dequeue();
                     queue.Dequeue();
+                }
                 else
                 else
+                {
                     return next;
                     return next;
+                }
             }
             }
+
             return null;
             return null;
         }
         }
 
 
         /// <summary>
         /// <summary>
-        /// Schedules an action to be executed at dueTime.
+        /// Schedules an action to be executed at <paramref name="dueTime"/>.
         /// </summary>
         /// </summary>
         /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
         /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="dueTime">Absolute time at which to execute the action.</param>
         /// <param name="dueTime">Absolute time at which to execute the action.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public override IDisposable ScheduleAbsolute<TState>(TState state, DateTimeOffset dueTime, Func<IScheduler, TState, IDisposable> action)
         public override IDisposable ScheduleAbsolute<TState>(TState state, DateTimeOffset dueTime, Func<IScheduler, TState, IDisposable> action)
         {
         {
             if (action == null)
             if (action == null)

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

@@ -43,4 +43,4 @@ namespace System.Reactive.Concurrency
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         IDisposable Schedule<TState>(TState state, DateTimeOffset dueTime, Func<IScheduler, TState, IDisposable> action);
         IDisposable Schedule<TState>(TState state, DateTimeOffset dueTime, Func<IScheduler, TState, IDisposable> action);
     }
     }
-}
+}

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

@@ -25,4 +25,4 @@ namespace System.Reactive.Concurrency
         /// </remarks>
         /// </remarks>
         IDisposable ScheduleLongRunning<TState>(TState state, Action<TState, ICancelable> action);
         IDisposable ScheduleLongRunning<TState>(TState state, Action<TState, ICancelable> action);
     }
     }
-}
+}

+ 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 Apache 2.0 License.
 // The .NET Foundation licenses this file to you under the Apache 2.0 License.
 // See the LICENSE file in the project root for more information. 
 // See the LICENSE file in the project root for more information. 
 
 
-using System.Reactive.Disposables;
-
 namespace System.Reactive.Concurrency
 namespace System.Reactive.Concurrency
 {
 {
     /// <summary>
     /// <summary>

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

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

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

@@ -2,8 +2,6 @@
 // The .NET Foundation licenses this file to you under the Apache 2.0 License.
 // The .NET Foundation licenses this file to you under the Apache 2.0 License.
 // See the LICENSE file in the project root for more information. 
 // See the LICENSE file in the project root for more information. 
 
 
-using System;
-
 namespace System.Reactive.Concurrency
 namespace System.Reactive.Concurrency
 {
 {
     /*
     /*
@@ -14,7 +12,7 @@ namespace System.Reactive.Concurrency
      */
      */
 
 
     /// <summary>
     /// <summary>
-    /// Provider for IStopwatch objects.
+    /// Provider for <see cref="IStopwatch"/> objects.
     /// </summary>
     /// </summary>
     public interface IStopwatchProvider
     public interface IStopwatchProvider
     {
     {

+ 21 - 9
Rx.NET/Source/src/System.Reactive/Concurrency/ImmediateScheduler.cs

@@ -2,7 +2,6 @@
 // The .NET Foundation licenses this file to you under the Apache 2.0 License.
 // The .NET Foundation licenses this file to you under the Apache 2.0 License.
 // See the LICENSE file in the project root for more information. 
 // See the LICENSE file in the project root for more information. 
 
 
-using System.Threading;
 using System.Reactive.Disposables;
 using System.Reactive.Disposables;
 
 
 namespace System.Reactive.Concurrency
 namespace System.Reactive.Concurrency
@@ -15,17 +14,14 @@ namespace System.Reactive.Concurrency
     {
     {
         private static readonly Lazy<ImmediateScheduler> s_instance = new Lazy<ImmediateScheduler>(() => new ImmediateScheduler());
         private static readonly Lazy<ImmediateScheduler> s_instance = new Lazy<ImmediateScheduler>(() => new ImmediateScheduler());
 
 
-        ImmediateScheduler()
+        private ImmediateScheduler()
         {
         {
         }
         }
 
 
         /// <summary>
         /// <summary>
         /// Gets the singleton instance of the immediate scheduler.
         /// Gets the singleton instance of the immediate scheduler.
         /// </summary>
         /// </summary>
-        public static ImmediateScheduler Instance
-        {
-            get { return s_instance.Value; }
-        }
+        public static ImmediateScheduler Instance => s_instance.Value;
 
 
         /// <summary>
         /// <summary>
         /// Schedules an action to be executed.
         /// Schedules an action to be executed.
@@ -66,9 +62,9 @@ namespace System.Reactive.Concurrency
             return action(new AsyncLockScheduler(), state);
             return action(new AsyncLockScheduler(), state);
         }
         }
 
 
-        class AsyncLockScheduler : LocalScheduler
+        private sealed class AsyncLockScheduler : LocalScheduler
         {
         {
-            AsyncLock asyncLock;
+            private AsyncLock asyncLock;
 
 
             public override IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
             public override IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
             {
             {
@@ -78,12 +74,16 @@ namespace System.Reactive.Concurrency
                 var m = new SingleAssignmentDisposable();
                 var m = new SingleAssignmentDisposable();
 
 
                 if (asyncLock == null)
                 if (asyncLock == null)
+                {
                     asyncLock = new AsyncLock();
                     asyncLock = new AsyncLock();
+                }
 
 
                 asyncLock.Wait(() =>
                 asyncLock.Wait(() =>
                 {
                 {
                     if (!m.IsDisposed)
                     if (!m.IsDisposed)
+                    {
                         m.Disposable = action(this, state);
                         m.Disposable = action(this, state);
+                    }
                 });
                 });
 
 
                 return m;
                 return m;
@@ -95,14 +95,23 @@ namespace System.Reactive.Concurrency
                     throw new ArgumentNullException(nameof(action));
                     throw new ArgumentNullException(nameof(action));
 
 
                 if (dueTime.Ticks <= 0)
                 if (dueTime.Ticks <= 0)
-                    return Schedule<TState>(state, action);
+                {
+                    return Schedule(state, action);
+                }
 
 
+                return ScheduleSlow(state, dueTime, action);
+            }
+
+            private IDisposable ScheduleSlow<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
+            {
                 var timer = ConcurrencyAbstractionLayer.Current.StartStopwatch();
                 var timer = ConcurrencyAbstractionLayer.Current.StartStopwatch();
 
 
                 var m = new SingleAssignmentDisposable();
                 var m = new SingleAssignmentDisposable();
 
 
                 if (asyncLock == null)
                 if (asyncLock == null)
+                {
                     asyncLock = new AsyncLock();
                     asyncLock = new AsyncLock();
+                }
 
 
                 asyncLock.Wait(() =>
                 asyncLock.Wait(() =>
                 {
                 {
@@ -113,8 +122,11 @@ namespace System.Reactive.Concurrency
                         {
                         {
                             ConcurrencyAbstractionLayer.Current.Sleep(sleep);
                             ConcurrencyAbstractionLayer.Current.Sleep(sleep);
                         }
                         }
+
                         if (!m.IsDisposed)
                         if (!m.IsDisposed)
+                        {
                             m.Disposable = action(this, state);
                             m.Disposable = action(this, state);
+                        }
                     }
                     }
                 });
                 });
 
 

+ 15 - 30
Rx.NET/Source/src/System.Reactive/Concurrency/LocalScheduler.TimerQueue.cs

@@ -414,31 +414,23 @@ namespace System.Reactive.Concurrency
         /// This type is very similar to ScheduledItem, but we need a different Invoke signature to allow customization
         /// This type is very similar to ScheduledItem, but we need a different Invoke signature to allow customization
         /// of the target scheduler (e.g. when called in a recursive scheduling context, see ExecuteNextShortTermWorkItem).
         /// of the target scheduler (e.g. when called in a recursive scheduling context, see ExecuteNextShortTermWorkItem).
         /// </remarks>
         /// </remarks>
-        abstract class WorkItem : IComparable<WorkItem>, IDisposable
+        private abstract class WorkItem : IComparable<WorkItem>, IDisposable
         {
         {
-            private readonly LocalScheduler _scheduler;
-            private readonly DateTimeOffset _dueTime;
+            public readonly LocalScheduler Scheduler;
+            public readonly DateTimeOffset DueTime;
+
             private readonly SingleAssignmentDisposable _disposable;
             private readonly SingleAssignmentDisposable _disposable;
             private int _hasRun;
             private int _hasRun;
 
 
             public WorkItem(LocalScheduler scheduler, DateTimeOffset dueTime)
             public WorkItem(LocalScheduler scheduler, DateTimeOffset dueTime)
             {
             {
-                _scheduler = scheduler;
-                _dueTime = dueTime;
+                Scheduler = scheduler;
+                DueTime = dueTime;
+
                 _disposable = new SingleAssignmentDisposable();
                 _disposable = new SingleAssignmentDisposable();
                 _hasRun = 0;
                 _hasRun = 0;
             }
             }
 
 
-            public LocalScheduler Scheduler
-            {
-                get { return _scheduler; }
-            }
-
-            public DateTimeOffset DueTime
-            {
-                get { return _dueTime; }
-            }
-
             public void Invoke(IScheduler scheduler)
             public void Invoke(IScheduler scheduler)
             {
             {
                 //
                 //
@@ -452,33 +444,29 @@ namespace System.Reactive.Concurrency
                     try
                     try
                     {
                     {
                         if (!_disposable.IsDisposed)
                         if (!_disposable.IsDisposed)
+                        {
                             _disposable.Disposable = InvokeCore(scheduler);
                             _disposable.Disposable = InvokeCore(scheduler);
+                        }
                     }
                     }
                     finally
                     finally
                     {
                     {
                         SystemClock.Release();
                         SystemClock.Release();
                     }
                     }
-                }                
+                }
             }
             }
 
 
             protected abstract IDisposable InvokeCore(IScheduler scheduler);
             protected abstract IDisposable InvokeCore(IScheduler scheduler);
 
 
-            public int CompareTo(WorkItem/*!*/ other)
-            {
-                return Comparer<DateTimeOffset>.Default.Compare(this._dueTime, other._dueTime);
-            }
+            public int CompareTo(WorkItem/*!*/ other) => Comparer<DateTimeOffset>.Default.Compare(DueTime, other.DueTime);
 
 
-            public void Dispose()
-            {
-                _disposable.Dispose();
-            }
+            public void Dispose() => _disposable.Dispose();
         }
         }
 
 
         /// <summary>
         /// <summary>
         /// Represents a work item that closes over scheduler invocation state. Subtyping is
         /// Represents a work item that closes over scheduler invocation state. Subtyping is
         /// used to have a common type for the scheduler queues.
         /// used to have a common type for the scheduler queues.
         /// </summary>
         /// </summary>
-        sealed class WorkItem<TState> : WorkItem
+        private sealed class WorkItem<TState> : WorkItem
         {
         {
             private readonly TState _state;
             private readonly TState _state;
             private readonly Func<IScheduler, TState, IDisposable> _action;
             private readonly Func<IScheduler, TState, IDisposable> _action;
@@ -490,10 +478,7 @@ namespace System.Reactive.Concurrency
                 _action = action;
                 _action = action;
             }
             }
 
 
-            protected override IDisposable InvokeCore(IScheduler scheduler)
-            {
-                return _action(scheduler, _state);
-            }
+            protected override IDisposable InvokeCore(IScheduler scheduler) => _action(scheduler, _state);
         }
         }
     }
     }
-}
+}

+ 8 - 17
Rx.NET/Source/src/System.Reactive/Concurrency/LocalScheduler.cs

@@ -12,10 +12,7 @@ namespace System.Reactive.Concurrency
         /// <summary>
         /// <summary>
         /// Gets the scheduler's notion of current time.
         /// Gets the scheduler's notion of current time.
         /// </summary>
         /// </summary>
-        public virtual DateTimeOffset Now
-        {
-            get { return Scheduler.Now; }
-        }
+        public virtual DateTimeOffset Now => Scheduler.Now;
 
 
         /// <summary>
         /// <summary>
         /// Schedules an action to be executed.
         /// Schedules an action to be executed.
@@ -24,7 +21,7 @@ namespace System.Reactive.Concurrency
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public virtual IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
         public virtual IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
         {
         {
             if (action == null)
             if (action == null)
@@ -51,7 +48,7 @@ namespace System.Reactive.Concurrency
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="dueTime">Absolute time at which to execute the action.</param>
         /// <param name="dueTime">Absolute time at which to execute the action.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public virtual IDisposable Schedule<TState>(TState state, DateTimeOffset dueTime, Func<IScheduler, TState, IDisposable> action)
         public virtual IDisposable Schedule<TState>(TState state, DateTimeOffset dueTime, Func<IScheduler, TState, IDisposable> action)
         {
         {
             if (action == null)
             if (action == null)
@@ -65,18 +62,12 @@ namespace System.Reactive.Concurrency
         /// </summary>
         /// </summary>
         /// <returns>New stopwatch object; started at the time of the request.</returns>
         /// <returns>New stopwatch object; started at the time of the request.</returns>
         /// <remarks>
         /// <remarks>
-        /// Platform-specific scheduler implementations should reimplement IStopwatchProvider to provide a more
-        /// efficient IStopwatch implementation (if available).
+        /// Platform-specific scheduler implementations should reimplement <see cref="IStopwatchProvider"/>
+        /// to provide a more efficient <see cref="IStopwatch"/> implementation (if available).
         /// </remarks>
         /// </remarks>
-        public virtual IStopwatch StartStopwatch()
-        {
-            return ConcurrencyAbstractionLayer.Current.StartStopwatch();
-        }
+        public virtual IStopwatch StartStopwatch() => ConcurrencyAbstractionLayer.Current.StartStopwatch();
 
 
-        object IServiceProvider.GetService(Type serviceType)
-        {
-            return GetService(serviceType);
-        }
+        object IServiceProvider.GetService(Type serviceType) => GetService(serviceType);
 
 
         /// <summary>
         /// <summary>
         /// Discovers scheduler services by interface type. The base class implementation returns
         /// Discovers scheduler services by interface type. The base class implementation returns
@@ -84,7 +75,7 @@ namespace System.Reactive.Concurrency
         /// more control over service discovery, derived types can override this method.
         /// more control over service discovery, derived types can override this method.
         /// </summary>
         /// </summary>
         /// <param name="serviceType">Scheduler service interface type to discover.</param>
         /// <param name="serviceType">Scheduler service interface type to discover.</param>
-        /// <returns>Object implementing the requested service, if available; null otherwise.</returns>
+        /// <returns>Object implementing the requested service, if available; <c>null</c> otherwise.</returns>
         protected virtual object GetService(Type serviceType)
         protected virtual object GetService(Type serviceType)
         {
         {
             if (serviceType == typeof(IStopwatchProvider))
             if (serviceType == typeof(IStopwatchProvider))

+ 7 - 13
Rx.NET/Source/src/System.Reactive/Concurrency/NewThreadScheduler.cs

@@ -27,20 +27,14 @@ namespace System.Reactive.Concurrency
         /// <summary>
         /// <summary>
         /// Gets an instance of this scheduler that uses the default Thread constructor.
         /// Gets an instance of this scheduler that uses the default Thread constructor.
         /// </summary>
         /// </summary>
-        public static NewThreadScheduler Default
-        {
-            get
-            {
-                return s_instance.Value;
-            }
-        }
+        public static NewThreadScheduler Default => s_instance.Value;
 
 
 #if !NO_THREAD
 #if !NO_THREAD
         /// <summary>
         /// <summary>
         /// Creates an object that schedules each unit of work on a separate thread.
         /// Creates an object that schedules each unit of work on a separate thread.
         /// </summary>
         /// </summary>
         /// <param name="threadFactory">Factory function for thread creation.</param>
         /// <param name="threadFactory">Factory function for thread creation.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="threadFactory"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="threadFactory"/> is <c>null</c>.</exception>
         public NewThreadScheduler(Func<ThreadStart, Thread> threadFactory)
         public NewThreadScheduler(Func<ThreadStart, Thread> threadFactory)
         {
         {
             if (threadFactory == null)
             if (threadFactory == null)
@@ -60,7 +54,7 @@ namespace System.Reactive.Concurrency
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public override IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
         public override IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
         {
         {
             if (action == null)
             if (action == null)
@@ -78,7 +72,7 @@ namespace System.Reactive.Concurrency
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public IDisposable ScheduleLongRunning<TState>(TState state, Action<TState, ICancelable> action)
         public IDisposable ScheduleLongRunning<TState>(TState state, Action<TState, ICancelable> action)
         {
         {
             if (action == null)
             if (action == null)
@@ -109,8 +103,8 @@ namespace System.Reactive.Concurrency
         /// <param name="period">Period for running the work periodically.</param>
         /// <param name="period">Period for running the work periodically.</param>
         /// <param name="action">Action to be executed, potentially updating the state.</param>
         /// <param name="action">Action to be executed, potentially updating the state.</param>
         /// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
-        /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than TimeSpan.Zero.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
+        /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than <see cref="TimeSpan.Zero"/>.</exception>
         public IDisposable SchedulePeriodic<TState>(TState state, TimeSpan period, Func<TState, TState> action)
         public IDisposable SchedulePeriodic<TState>(TState state, TimeSpan period, Func<TState, TState> action)
         {
         {
             if (period < TimeSpan.Zero)
             if (period < TimeSpan.Zero)
@@ -126,7 +120,7 @@ namespace System.Reactive.Concurrency
             return periodic;
             return periodic;
         }
         }
 
 
-        class Periodic<TState> : IDisposable
+        private sealed class Periodic<TState> : IDisposable
         {
         {
             private readonly IStopwatch _stopwatch;
             private readonly IStopwatch _stopwatch;
             private readonly TimeSpan _period;
             private readonly TimeSpan _period;

+ 32 - 58
Rx.NET/Source/src/System.Reactive/Concurrency/ScheduledItem.cs

@@ -22,7 +22,7 @@ namespace System.Reactive.Concurrency
         /// </summary>
         /// </summary>
         /// <param name="dueTime">Absolute time at which the work item has to be executed.</param>
         /// <param name="dueTime">Absolute time at which the work item has to be executed.</param>
         /// <param name="comparer">Comparer used to compare work items based on their scheduled time.</param>
         /// <param name="comparer">Comparer used to compare work items based on their scheduled time.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="comparer"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="comparer"/> is <c>null</c>.</exception>
         protected ScheduledItem(TAbsolute dueTime, IComparer<TAbsolute> comparer)
         protected ScheduledItem(TAbsolute dueTime, IComparer<TAbsolute> comparer)
         {
         {
             if (comparer == null)
             if (comparer == null)
@@ -43,7 +43,9 @@ namespace System.Reactive.Concurrency
         public void Invoke()
         public void Invoke()
         {
         {
             if (!_disposable.IsDisposed)
             if (!_disposable.IsDisposed)
+            {
                 _disposable.Disposable = InvokeCore();
                 _disposable.Disposable = InvokeCore();
+            }
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -59,12 +61,14 @@ namespace System.Reactive.Concurrency
         /// </summary>
         /// </summary>
         /// <param name="other">Work item to compare the current work item to.</param>
         /// <param name="other">Work item to compare the current work item to.</param>
         /// <returns>Relative ordering between this and the specified work item.</returns>
         /// <returns>Relative ordering between this and the specified work item.</returns>
-        /// <remarks>The inequality operators are overloaded to provide results consistent with the IComparable implementation. Equality operators implement traditional reference equality semantics.</remarks>
+        /// <remarks>The inequality operators are overloaded to provide results consistent with the <see cref="IComparable"/> implementation. Equality operators implement traditional reference equality semantics.</remarks>
         public int CompareTo(ScheduledItem<TAbsolute> other)
         public int CompareTo(ScheduledItem<TAbsolute> other)
         {
         {
-            // MSDN: By definition, any object compares greater than null, and two null references compare equal to each other. 
-            if (object.ReferenceEquals(other, null))
+            // MSDN: By definition, any object compares greater than null, and two null references compare equal to each other.
+            if (ReferenceEquals(other, null))
+            {
                 return 1;
                 return 1;
+            }
 
 
             return _comparer.Compare(DueTime, other.DueTime);
             return _comparer.Compare(DueTime, other.DueTime);
         }
         }
@@ -74,48 +78,36 @@ namespace System.Reactive.Concurrency
         /// </summary>
         /// </summary>
         /// <param name="left">The first object to compare.</param>
         /// <param name="left">The first object to compare.</param>
         /// <param name="right">The second object to compare.</param>
         /// <param name="right">The second object to compare.</param>
-        /// <returns>true if the DueTime value of left is earlier than the DueTime value of right; otherwise, false.</returns>
-        /// <remarks>This operator provides results consistent with the IComparable implementation.</remarks>
-        public static bool operator <(ScheduledItem<TAbsolute> left, ScheduledItem<TAbsolute> right)
-        {
-            return Comparer<ScheduledItem<TAbsolute>>.Default.Compare(left, right) < 0;
-        }
+        /// <returns><c>true</c> if the <see cref="DueTime"/> value of left is earlier than the <see cref="DueTime"/> value of right; otherwise, <c>false</c>.</returns>
+        /// <remarks>This operator provides results consistent with the <see cref="IComparable"/> implementation.</remarks>
+        public static bool operator <(ScheduledItem<TAbsolute> left, ScheduledItem<TAbsolute> right) => Comparer<ScheduledItem<TAbsolute>>.Default.Compare(left, right) < 0;
 
 
         /// <summary>
         /// <summary>
         /// Determines whether one specified <see cref="ScheduledItem{TAbsolute}" /> object is due before or at the same of a second specified <see cref="ScheduledItem{TAbsolute}" /> object.
         /// Determines whether one specified <see cref="ScheduledItem{TAbsolute}" /> object is due before or at the same of a second specified <see cref="ScheduledItem{TAbsolute}" /> object.
         /// </summary>
         /// </summary>
         /// <param name="left">The first object to compare.</param>
         /// <param name="left">The first object to compare.</param>
         /// <param name="right">The second object to compare.</param>
         /// <param name="right">The second object to compare.</param>
-        /// <returns>true if the DueTime value of left is earlier than or simultaneous with the DueTime value of right; otherwise, false.</returns>
-        /// <remarks>This operator provides results consistent with the IComparable implementation.</remarks>
-        public static bool operator <=(ScheduledItem<TAbsolute> left, ScheduledItem<TAbsolute> right)
-        {
-            return Comparer<ScheduledItem<TAbsolute>>.Default.Compare(left, right) <= 0;
-        }
+        /// <returns><c>true</c> if the <see cref="DueTime"/> value of left is earlier than or simultaneous with the <see cref="DueTime"/> value of right; otherwise, <c>false</c>.</returns>
+        /// <remarks>This operator provides results consistent with the <see cref="IComparable"/> implementation.</remarks>
+        public static bool operator <=(ScheduledItem<TAbsolute> left, ScheduledItem<TAbsolute> right) => Comparer<ScheduledItem<TAbsolute>>.Default.Compare(left, right) <= 0;
 
 
         /// <summary>
         /// <summary>
         /// Determines whether one specified <see cref="ScheduledItem{TAbsolute}" /> object is due after a second specified <see cref="ScheduledItem{TAbsolute}" /> object.
         /// Determines whether one specified <see cref="ScheduledItem{TAbsolute}" /> object is due after a second specified <see cref="ScheduledItem{TAbsolute}" /> object.
         /// </summary>
         /// </summary>
         /// <param name="left">The first object to compare.</param>
         /// <param name="left">The first object to compare.</param>
         /// <param name="right">The second object to compare.</param>
         /// <param name="right">The second object to compare.</param>
-        /// <returns>true if the DueTime value of left is later than the DueTime value of right; otherwise, false.</returns>
-        /// <remarks>This operator provides results consistent with the IComparable implementation.</remarks>
-        public static bool operator >(ScheduledItem<TAbsolute> left, ScheduledItem<TAbsolute> right)
-        {
-            return Comparer<ScheduledItem<TAbsolute>>.Default.Compare(left, right) > 0;
-        }
+        /// <returns><c>true</c> if the <see cref="DueTime"/> value of left is later than the <see cref="DueTime"/> value of right; otherwise, <c>false</c>.</returns>
+        /// <remarks>This operator provides results consistent with the <see cref="IComparable"/> implementation.</remarks>
+        public static bool operator >(ScheduledItem<TAbsolute> left, ScheduledItem<TAbsolute> right) => Comparer<ScheduledItem<TAbsolute>>.Default.Compare(left, right) > 0;
 
 
         /// <summary>
         /// <summary>
         /// Determines whether one specified <see cref="ScheduledItem{TAbsolute}" /> object is due after or at the same time of a second specified <see cref="ScheduledItem{TAbsolute}" /> object.
         /// Determines whether one specified <see cref="ScheduledItem{TAbsolute}" /> object is due after or at the same time of a second specified <see cref="ScheduledItem{TAbsolute}" /> object.
         /// </summary>
         /// </summary>
         /// <param name="left">The first object to compare.</param>
         /// <param name="left">The first object to compare.</param>
         /// <param name="right">The second object to compare.</param>
         /// <param name="right">The second object to compare.</param>
-        /// <returns>true if the DueTime value of left is later than or simultaneous with the DueTime value of right; otherwise, false.</returns>
-        /// <remarks>This operator provides results consistent with the IComparable implementation.</remarks>
-        public static bool operator >=(ScheduledItem<TAbsolute> left, ScheduledItem<TAbsolute> right)
-        {
-            return Comparer<ScheduledItem<TAbsolute>>.Default.Compare(left, right) >= 0;
-        }
+        /// <returns><c>true</c> if the <see cref="DueTime"/> value of left is later than or simultaneous with the <see cref="DueTime"/> value of right; otherwise, <c>false</c>.</returns>
+        /// <remarks>This operator provides results consistent with the <see cref="IComparable"/> implementation.</remarks>
+        public static bool operator >=(ScheduledItem<TAbsolute> left, ScheduledItem<TAbsolute> right) => Comparer<ScheduledItem<TAbsolute>>.Default.Compare(left, right) >= 0;
 
 
         #endregion
         #endregion
 
 
@@ -126,53 +118,38 @@ namespace System.Reactive.Concurrency
         /// </summary>
         /// </summary>
         /// <param name="left">The first object to compare.</param>
         /// <param name="left">The first object to compare.</param>
         /// <param name="right">The second object to compare.</param>
         /// <param name="right">The second object to compare.</param>
-        /// <returns>true if both <see cref="ScheduledItem{TAbsolute, TValue}" /> are equal; otherwise, false.</returns>
+        /// <returns><c>true</c> if both <see cref="ScheduledItem{TAbsolute, TValue}" /> are equal; otherwise, <c>false</c>.</returns>
         /// <remarks>This operator does not provide results consistent with the IComparable implementation. Instead, it implements reference equality.</remarks>
         /// <remarks>This operator does not provide results consistent with the IComparable implementation. Instead, it implements reference equality.</remarks>
-        public static bool operator ==(ScheduledItem<TAbsolute> left, ScheduledItem<TAbsolute> right)
-        {
-            return object.ReferenceEquals(left, right);
-        }
+        public static bool operator ==(ScheduledItem<TAbsolute> left, ScheduledItem<TAbsolute> right) => ReferenceEquals(left, right);
 
 
         /// <summary>
         /// <summary>
         /// Determines whether two specified <see cref="ScheduledItem{TAbsolute, TValue}" /> objects are inequal.
         /// Determines whether two specified <see cref="ScheduledItem{TAbsolute, TValue}" /> objects are inequal.
         /// </summary>
         /// </summary>
         /// <param name="left">The first object to compare.</param>
         /// <param name="left">The first object to compare.</param>
         /// <param name="right">The second object to compare.</param>
         /// <param name="right">The second object to compare.</param>
-        /// <returns>true if both <see cref="ScheduledItem{TAbsolute, TValue}" /> are inequal; otherwise, false.</returns>
+        /// <returns><c>true</c> if both <see cref="ScheduledItem{TAbsolute, TValue}" /> are inequal; otherwise, <c>false</c>.</returns>
         /// <remarks>This operator does not provide results consistent with the IComparable implementation. Instead, it implements reference equality.</remarks>
         /// <remarks>This operator does not provide results consistent with the IComparable implementation. Instead, it implements reference equality.</remarks>
-        public static bool operator !=(ScheduledItem<TAbsolute> left, ScheduledItem<TAbsolute> right)
-        {
-            return !(left == right);
-        }
+        public static bool operator !=(ScheduledItem<TAbsolute> left, ScheduledItem<TAbsolute> right) => !(left == right);
 
 
         /// <summary>
         /// <summary>
         /// Determines whether a <see cref="ScheduledItem{TAbsolute}" /> object is equal to the specified object.
         /// Determines whether a <see cref="ScheduledItem{TAbsolute}" /> object is equal to the specified object.
         /// </summary>
         /// </summary>
         /// <param name="obj">The object to compare to the current <see cref="ScheduledItem{TAbsolute}" /> object.</param>
         /// <param name="obj">The object to compare to the current <see cref="ScheduledItem{TAbsolute}" /> object.</param>
-        /// <returns>true if the obj parameter is a <see cref="ScheduledItem{TAbsolute}" /> object and is equal to the current <see cref="ScheduledItem{TAbsolute}" /> object; otherwise, false.</returns>
-        public override bool Equals(object obj)
-        {
-            return object.ReferenceEquals(this, obj);
-        }
+        /// <returns><c>true</c> if the obj parameter is a <see cref="ScheduledItem{TAbsolute}" /> object and is equal to the current <see cref="ScheduledItem{TAbsolute}" /> object; otherwise, <c>false</c>.</returns>
+        public override bool Equals(object obj) => ReferenceEquals(this, obj);
 
 
         /// <summary>
         /// <summary>
         /// Returns the hash code for the current <see cref="ScheduledItem{TAbsolute}" /> object.
         /// Returns the hash code for the current <see cref="ScheduledItem{TAbsolute}" /> object.
         /// </summary>
         /// </summary>
         /// <returns>A 32-bit signed integer hash code.</returns>
         /// <returns>A 32-bit signed integer hash code.</returns>
-        public override int GetHashCode()
-        {
-            return base.GetHashCode();
-        }
+        public override int GetHashCode() => base.GetHashCode();
 
 
         #endregion
         #endregion
 
 
         /// <summary>
         /// <summary>
-        /// Cancels the work item by disposing the resource returned by InvokeCore as soon as possible.
+        /// Cancels the work item by disposing the resource returned by <see cref="InvokeCore"/> as soon as possible.
         /// </summary>
         /// </summary>
-        public void Cancel()
-        {
-            _disposable.Dispose();
-        }
+        public void Cancel() => _disposable.Dispose();
 
 
         /// <summary>
         /// <summary>
         /// Gets whether the work item has received a cancellation request.
         /// Gets whether the work item has received a cancellation request.
@@ -200,7 +177,7 @@ namespace System.Reactive.Concurrency
         /// <param name="action">Scheduled action.</param>
         /// <param name="action">Scheduled action.</param>
         /// <param name="dueTime">Time at which to run the scheduled action.</param>
         /// <param name="dueTime">Time at which to run the scheduled action.</param>
         /// <param name="comparer">Comparer used to compare work items based on their scheduled time.</param>
         /// <param name="comparer">Comparer used to compare work items based on their scheduled time.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> or <paramref name="comparer"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> or <paramref name="comparer"/> is <c>null</c>.</exception>
         public ScheduledItem(IScheduler scheduler, TValue state, Func<IScheduler, TValue, IDisposable> action, TAbsolute dueTime, IComparer<TAbsolute> comparer)
         public ScheduledItem(IScheduler scheduler, TValue state, Func<IScheduler, TValue, IDisposable> action, TAbsolute dueTime, IComparer<TAbsolute> comparer)
             : base(dueTime, comparer)
             : base(dueTime, comparer)
         {
         {
@@ -221,7 +198,7 @@ namespace System.Reactive.Concurrency
         /// <param name="state">State to pass to the scheduled action.</param>
         /// <param name="state">State to pass to the scheduled action.</param>
         /// <param name="action">Scheduled action.</param>
         /// <param name="action">Scheduled action.</param>
         /// <param name="dueTime">Time at which to run the scheduled action.</param>
         /// <param name="dueTime">Time at which to run the scheduled action.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
         public ScheduledItem(IScheduler scheduler, TValue state, Func<IScheduler, TValue, IDisposable> action, TAbsolute dueTime)
         public ScheduledItem(IScheduler scheduler, TValue state, Func<IScheduler, TValue, IDisposable> action, TAbsolute dueTime)
             : this(scheduler, state, action, dueTime, Comparer<TAbsolute>.Default)
             : this(scheduler, state, action, dueTime, Comparer<TAbsolute>.Default)
         {
         {
@@ -231,9 +208,6 @@ namespace System.Reactive.Concurrency
         /// Invokes the scheduled action with the supplied recursive scheduler and state.
         /// Invokes the scheduled action with the supplied recursive scheduler and state.
         /// </summary>
         /// </summary>
         /// <returns>Cancellation resource returned by the scheduled action.</returns>
         /// <returns>Cancellation resource returned by the scheduled action.</returns>
-        protected override IDisposable InvokeCore()
-        {
-            return _action(_scheduler, _state);
-        }
+        protected override IDisposable InvokeCore() => _action(_scheduler, _state);
     }
     }
 }
 }

+ 23 - 25
Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Async.cs

@@ -16,7 +16,7 @@ namespace System.Reactive.Concurrency
         /// </summary>
         /// </summary>
         /// <param name="scheduler">Scheduler to yield work on.</param>
         /// <param name="scheduler">Scheduler to yield work on.</param>
         /// <returns>Scheduler operation object to await in order to schedule the continuation.</returns>
         /// <returns>Scheduler operation object to await in order to schedule the continuation.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is <c>null</c>.</exception>
         public static SchedulerOperation Yield(this IScheduler scheduler)
         public static SchedulerOperation Yield(this IScheduler scheduler)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -32,7 +32,7 @@ namespace System.Reactive.Concurrency
         /// <param name="scheduler">Scheduler to yield work on.</param>
         /// <param name="scheduler">Scheduler to yield work on.</param>
         /// <param name="cancellationToken">Cancellation token to cancel the continuation to run.</param>
         /// <param name="cancellationToken">Cancellation token to cancel the continuation to run.</param>
         /// <returns>Scheduler operation object to await in order to schedule the continuation.</returns>
         /// <returns>Scheduler operation object to await in order to schedule the continuation.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is <c>null</c>.</exception>
         public static SchedulerOperation Yield(this IScheduler scheduler, CancellationToken cancellationToken)
         public static SchedulerOperation Yield(this IScheduler scheduler, CancellationToken cancellationToken)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -48,7 +48,7 @@ namespace System.Reactive.Concurrency
         /// <param name="scheduler">Scheduler to yield work on.</param>
         /// <param name="scheduler">Scheduler to yield work on.</param>
         /// <param name="dueTime">Time when the continuation should run.</param>
         /// <param name="dueTime">Time when the continuation should run.</param>
         /// <returns>Scheduler operation object to await in order to schedule the continuation.</returns>
         /// <returns>Scheduler operation object to await in order to schedule the continuation.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is <c>null</c>.</exception>
         public static SchedulerOperation Sleep(this IScheduler scheduler, TimeSpan dueTime)
         public static SchedulerOperation Sleep(this IScheduler scheduler, TimeSpan dueTime)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -65,7 +65,7 @@ namespace System.Reactive.Concurrency
         /// <param name="dueTime">Time when the continuation should run.</param>
         /// <param name="dueTime">Time when the continuation should run.</param>
         /// <param name="cancellationToken">Cancellation token to cancel the continuation to run.</param>
         /// <param name="cancellationToken">Cancellation token to cancel the continuation to run.</param>
         /// <returns>Scheduler operation object to await in order to schedule the continuation.</returns>
         /// <returns>Scheduler operation object to await in order to schedule the continuation.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is <c>null</c>.</exception>
         public static SchedulerOperation Sleep(this IScheduler scheduler, TimeSpan dueTime, CancellationToken cancellationToken)
         public static SchedulerOperation Sleep(this IScheduler scheduler, TimeSpan dueTime, CancellationToken cancellationToken)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -81,7 +81,7 @@ namespace System.Reactive.Concurrency
         /// <param name="scheduler">Scheduler to yield work on.</param>
         /// <param name="scheduler">Scheduler to yield work on.</param>
         /// <param name="dueTime">Time when the continuation should run.</param>
         /// <param name="dueTime">Time when the continuation should run.</param>
         /// <returns>Scheduler operation object to await in order to schedule the continuation.</returns>
         /// <returns>Scheduler operation object to await in order to schedule the continuation.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is <c>null</c>.</exception>
         public static SchedulerOperation Sleep(this IScheduler scheduler, DateTimeOffset dueTime)
         public static SchedulerOperation Sleep(this IScheduler scheduler, DateTimeOffset dueTime)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -98,7 +98,7 @@ namespace System.Reactive.Concurrency
         /// <param name="dueTime">Time when the continuation should run.</param>
         /// <param name="dueTime">Time when the continuation should run.</param>
         /// <param name="cancellationToken">Cancellation token to cancel the continuation to run.</param>
         /// <param name="cancellationToken">Cancellation token to cancel the continuation to run.</param>
         /// <returns>Scheduler operation object to await in order to schedule the continuation.</returns>
         /// <returns>Scheduler operation object to await in order to schedule the continuation.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is <c>null</c>.</exception>
         public static SchedulerOperation Sleep(this IScheduler scheduler, DateTimeOffset dueTime, CancellationToken cancellationToken)
         public static SchedulerOperation Sleep(this IScheduler scheduler, DateTimeOffset dueTime, CancellationToken cancellationToken)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -115,7 +115,7 @@ namespace System.Reactive.Concurrency
         /// <param name="state">State to pass to the asynchronous method.</param>
         /// <param name="state">State to pass to the asynchronous method.</param>
         /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
         /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
         /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
         /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
         public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, Func<IScheduler, TState, CancellationToken, Task> action)
         public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, Func<IScheduler, TState, CancellationToken, Task> action)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -134,7 +134,7 @@ namespace System.Reactive.Concurrency
         /// <param name="state">State to pass to the asynchronous method.</param>
         /// <param name="state">State to pass to the asynchronous method.</param>
         /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
         /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
         /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
         /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
         public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
         public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -151,7 +151,7 @@ namespace System.Reactive.Concurrency
         /// <param name="scheduler">Scheduler to schedule work on.</param>
         /// <param name="scheduler">Scheduler to schedule work on.</param>
         /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
         /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
         /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
         /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
         public static IDisposable ScheduleAsync(this IScheduler scheduler, Func<IScheduler, CancellationToken, Task> action)
         public static IDisposable ScheduleAsync(this IScheduler scheduler, Func<IScheduler, CancellationToken, Task> action)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -168,7 +168,7 @@ namespace System.Reactive.Concurrency
         /// <param name="scheduler">Scheduler to schedule work on.</param>
         /// <param name="scheduler">Scheduler to schedule work on.</param>
         /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
         /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
         /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
         /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
         public static IDisposable ScheduleAsync(this IScheduler scheduler, Func<IScheduler, CancellationToken, Task<IDisposable>> action)
         public static IDisposable ScheduleAsync(this IScheduler scheduler, Func<IScheduler, CancellationToken, Task<IDisposable>> action)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -188,7 +188,7 @@ namespace System.Reactive.Concurrency
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
         /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
         /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
         /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
         public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, TimeSpan dueTime, Func<IScheduler, TState, CancellationToken, Task> action)
         public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, TimeSpan dueTime, Func<IScheduler, TState, CancellationToken, Task> action)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -208,7 +208,7 @@ namespace System.Reactive.Concurrency
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
         /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
         /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
         /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
         public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, TimeSpan dueTime, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
         public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, TimeSpan dueTime, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -226,7 +226,7 @@ namespace System.Reactive.Concurrency
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
         /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
         /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
         /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
         public static IDisposable ScheduleAsync(this IScheduler scheduler, TimeSpan dueTime, Func<IScheduler, CancellationToken, Task> action)
         public static IDisposable ScheduleAsync(this IScheduler scheduler, TimeSpan dueTime, Func<IScheduler, CancellationToken, Task> action)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -244,7 +244,7 @@ namespace System.Reactive.Concurrency
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
         /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
         /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
         /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
         public static IDisposable ScheduleAsync(this IScheduler scheduler, TimeSpan dueTime, Func<IScheduler, CancellationToken, Task<IDisposable>> action)
         public static IDisposable ScheduleAsync(this IScheduler scheduler, TimeSpan dueTime, Func<IScheduler, CancellationToken, Task<IDisposable>> action)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -264,7 +264,7 @@ namespace System.Reactive.Concurrency
         /// <param name="dueTime">Absolute time at which to execute the action.</param>
         /// <param name="dueTime">Absolute time at which to execute the action.</param>
         /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
         /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
         /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
         /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
         public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, DateTimeOffset dueTime, Func<IScheduler, TState, CancellationToken, Task> action)
         public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, DateTimeOffset dueTime, Func<IScheduler, TState, CancellationToken, Task> action)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -284,7 +284,7 @@ namespace System.Reactive.Concurrency
         /// <param name="dueTime">Absolute time at which to execute the action.</param>
         /// <param name="dueTime">Absolute time at which to execute the action.</param>
         /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
         /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
         /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
         /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
         public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, DateTimeOffset dueTime, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
         public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, DateTimeOffset dueTime, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -302,7 +302,7 @@ namespace System.Reactive.Concurrency
         /// <param name="dueTime">Absolute time at which to execute the action.</param>
         /// <param name="dueTime">Absolute time at which to execute the action.</param>
         /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
         /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
         /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
         /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
         public static IDisposable ScheduleAsync(this IScheduler scheduler, DateTimeOffset dueTime, Func<IScheduler, CancellationToken, Task> action)
         public static IDisposable ScheduleAsync(this IScheduler scheduler, DateTimeOffset dueTime, Func<IScheduler, CancellationToken, Task> action)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -320,7 +320,7 @@ namespace System.Reactive.Concurrency
         /// <param name="dueTime">Absolute time at which to execute the action.</param>
         /// <param name="dueTime">Absolute time at which to execute the action.</param>
         /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
         /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
         /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
         /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
         public static IDisposable ScheduleAsync(this IScheduler scheduler, DateTimeOffset dueTime, Func<IScheduler, CancellationToken, Task<IDisposable>> action)
         public static IDisposable ScheduleAsync(this IScheduler scheduler, DateTimeOffset dueTime, Func<IScheduler, CancellationToken, Task<IDisposable>> action)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -372,7 +372,9 @@ namespace System.Reactive.Concurrency
                     return;
                     return;
 
 
                 if (t.Exception != null)
                 if (t.Exception != null)
+                {
                     t.Exception.Handle(e => e is OperationCanceledException);
                     t.Exception.Handle(e => e is OperationCanceledException);
+                }
 
 
                 d.Disposable = t.Result;
                 d.Disposable = t.Result;
             }, TaskContinuationOptions.ExecuteSynchronously);
             }, TaskContinuationOptions.ExecuteSynchronously);
@@ -391,7 +393,7 @@ namespace System.Reactive.Concurrency
             return cs != null ? cs.Token : CancellationToken.None;
             return cs != null ? cs.Token : CancellationToken.None;
         }
         }
 
 
-        class CancelableScheduler : IScheduler
+        private sealed class CancelableScheduler : IScheduler
         {
         {
             private readonly IScheduler _scheduler;
             private readonly IScheduler _scheduler;
             private readonly CancellationToken _cancellationToken;
             private readonly CancellationToken _cancellationToken;
@@ -407,10 +409,7 @@ namespace System.Reactive.Concurrency
                 get { return _cancellationToken; }
                 get { return _cancellationToken; }
             }
             }
 
 
-            public DateTimeOffset Now
-            {
-                get { return _scheduler.Now; }
-            }
+            public DateTimeOffset Now => _scheduler.Now;
 
 
             public IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
             public IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
             {
             {
@@ -427,6 +426,5 @@ namespace System.Reactive.Concurrency
                 return _scheduler.Schedule(state, dueTime, action);
                 return _scheduler.Schedule(state, dueTime, action);
             }
             }
         }
         }
-
     }
     }
-}
+}

+ 22 - 10
Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Recursive.cs

@@ -14,7 +14,7 @@ namespace System.Reactive.Concurrency
         /// <param name="scheduler">Scheduler to execute the recursive action on.</param>
         /// <param name="scheduler">Scheduler to execute the recursive action on.</param>
         /// <param name="action">Action to execute recursively. The parameter passed to the action is used to trigger recursive scheduling of the action.</param>
         /// <param name="action">Action to execute recursively. The parameter passed to the action is used to trigger recursive scheduling of the action.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
         public static IDisposable Schedule(this IScheduler scheduler, Action<Action> action)
         public static IDisposable Schedule(this IScheduler scheduler, Action<Action> action)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -33,7 +33,7 @@ namespace System.Reactive.Concurrency
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="action">Action to execute recursively. The last parameter passed to the action is used to trigger recursive scheduling of the action, passing in recursive invocation state.</param>
         /// <param name="action">Action to execute recursively. The last parameter passed to the action is used to trigger recursive scheduling of the action, passing in recursive invocation state.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
         public static IDisposable Schedule<TState>(this IScheduler scheduler, TState state, Action<TState, Action<TState>> action)
         public static IDisposable Schedule<TState>(this IScheduler scheduler, TState state, Action<TState, Action<TState>> action)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -44,7 +44,7 @@ namespace System.Reactive.Concurrency
             return scheduler.Schedule(new Pair<TState, Action<TState, Action<TState>>> { First = state, Second = action }, InvokeRec1);
             return scheduler.Schedule(new Pair<TState, Action<TState, Action<TState>>> { First = state, Second = action }, InvokeRec1);
         }
         }
 
 
-        static IDisposable InvokeRec1<TState>(IScheduler scheduler, Pair<TState, Action<TState, Action<TState>>> pair)
+        private static IDisposable InvokeRec1<TState>(IScheduler scheduler, Pair<TState, Action<TState, Action<TState>>> pair)
         {
         {
             var group = new CompositeDisposable(1);
             var group = new CompositeDisposable(1);
             var gate = new object();
             var gate = new object();
@@ -62,9 +62,13 @@ namespace System.Reactive.Concurrency
                     lock (gate)
                     lock (gate)
                     {
                     {
                         if (isAdded)
                         if (isAdded)
+                        {
                             group.Remove(d);
                             group.Remove(d);
+                        }
                         else
                         else
+                        {
                             isDone = true;
                             isDone = true;
+                        }
                     }
                     }
                     recursiveAction(state3);
                     recursiveAction(state3);
                     return Disposable.Empty;
                     return Disposable.Empty;
@@ -92,7 +96,7 @@ namespace System.Reactive.Concurrency
         /// <param name="action">Action to execute recursively. The parameter passed to the action is used to trigger recursive scheduling of the action at the specified relative time.</param>
         /// <param name="action">Action to execute recursively. The parameter passed to the action is used to trigger recursive scheduling of the action at the specified relative time.</param>
         /// <param name="dueTime">Relative time after which to execute the action for the first time.</param>
         /// <param name="dueTime">Relative time after which to execute the action for the first time.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
         public static IDisposable Schedule(this IScheduler scheduler, TimeSpan dueTime, Action<Action<TimeSpan>> action)
         public static IDisposable Schedule(this IScheduler scheduler, TimeSpan dueTime, Action<Action<TimeSpan>> action)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -112,7 +116,7 @@ namespace System.Reactive.Concurrency
         /// <param name="action">Action to execute recursively. The last parameter passed to the action is used to trigger recursive scheduling of the action, passing in the recursive due time and invocation state.</param>
         /// <param name="action">Action to execute recursively. The last parameter passed to the action is used to trigger recursive scheduling of the action, passing in the recursive due time and invocation state.</param>
         /// <param name="dueTime">Relative time after which to execute the action for the first time.</param>
         /// <param name="dueTime">Relative time after which to execute the action for the first time.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
         public static IDisposable Schedule<TState>(this IScheduler scheduler, TState state, TimeSpan dueTime, Action<TState, Action<TState, TimeSpan>> action)
         public static IDisposable Schedule<TState>(this IScheduler scheduler, TState state, TimeSpan dueTime, Action<TState, Action<TState, TimeSpan>> action)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -123,7 +127,7 @@ namespace System.Reactive.Concurrency
             return scheduler.Schedule(new Pair<TState, Action<TState, Action<TState, TimeSpan>>> { First = state, Second = action }, dueTime, InvokeRec2);
             return scheduler.Schedule(new Pair<TState, Action<TState, Action<TState, TimeSpan>>> { First = state, Second = action }, dueTime, InvokeRec2);
         }
         }
 
 
-        static IDisposable InvokeRec2<TState>(IScheduler scheduler, Pair<TState, Action<TState, Action<TState, TimeSpan>>> pair)
+        private static IDisposable InvokeRec2<TState>(IScheduler scheduler, Pair<TState, Action<TState, Action<TState, TimeSpan>>> pair)
         {
         {
             var group = new CompositeDisposable(1);
             var group = new CompositeDisposable(1);
             var gate = new object();
             var gate = new object();
@@ -141,9 +145,13 @@ namespace System.Reactive.Concurrency
                     lock (gate)
                     lock (gate)
                     {
                     {
                         if (isAdded)
                         if (isAdded)
+                        {
                             group.Remove(d);
                             group.Remove(d);
+                        }
                         else
                         else
+                        {
                             isDone = true;
                             isDone = true;
+                        }
                     }
                     }
                     recursiveAction(state3);
                     recursiveAction(state3);
                     return Disposable.Empty;
                     return Disposable.Empty;
@@ -171,7 +179,7 @@ namespace System.Reactive.Concurrency
         /// <param name="action">Action to execute recursively. The parameter passed to the action is used to trigger recursive scheduling of the action at the specified absolute time.</param>
         /// <param name="action">Action to execute recursively. The parameter passed to the action is used to trigger recursive scheduling of the action at the specified absolute time.</param>
         /// <param name="dueTime">Absolute time at which to execute the action for the first time.</param>
         /// <param name="dueTime">Absolute time at which to execute the action for the first time.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
         public static IDisposable Schedule(this IScheduler scheduler, DateTimeOffset dueTime, Action<Action<DateTimeOffset>> action)
         public static IDisposable Schedule(this IScheduler scheduler, DateTimeOffset dueTime, Action<Action<DateTimeOffset>> action)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -191,7 +199,7 @@ namespace System.Reactive.Concurrency
         /// <param name="action">Action to execute recursively. The last parameter passed to the action is used to trigger recursive scheduling of the action, passing in the recursive due time and invocation state.</param>
         /// <param name="action">Action to execute recursively. The last parameter passed to the action is used to trigger recursive scheduling of the action, passing in the recursive due time and invocation state.</param>
         /// <param name="dueTime">Absolute time at which to execute the action for the first time.</param>
         /// <param name="dueTime">Absolute time at which to execute the action for the first time.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
         public static IDisposable Schedule<TState>(this IScheduler scheduler, TState state, DateTimeOffset dueTime, Action<TState, Action<TState, DateTimeOffset>> action)
         public static IDisposable Schedule<TState>(this IScheduler scheduler, TState state, DateTimeOffset dueTime, Action<TState, Action<TState, DateTimeOffset>> action)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -202,7 +210,7 @@ namespace System.Reactive.Concurrency
             return scheduler.Schedule(new Pair<TState, Action<TState, Action<TState, DateTimeOffset>>> { First = state, Second = action }, dueTime, InvokeRec3);
             return scheduler.Schedule(new Pair<TState, Action<TState, Action<TState, DateTimeOffset>>> { First = state, Second = action }, dueTime, InvokeRec3);
         }
         }
 
 
-        static IDisposable InvokeRec3<TState>(IScheduler scheduler, Pair<TState, Action<TState, Action<TState, DateTimeOffset>>> pair)
+        private static IDisposable InvokeRec3<TState>(IScheduler scheduler, Pair<TState, Action<TState, Action<TState, DateTimeOffset>>> pair)
         {
         {
             var group = new CompositeDisposable(1);
             var group = new CompositeDisposable(1);
             var gate = new object();
             var gate = new object();
@@ -220,9 +228,13 @@ namespace System.Reactive.Concurrency
                     lock (gate)
                     lock (gate)
                     {
                     {
                         if (isAdded)
                         if (isAdded)
+                        {
                             group.Remove(d);
                             group.Remove(d);
+                        }
                         else
                         else
+                        {
                             isDone = true;
                             isDone = true;
+                        }
                     }
                     }
                     recursiveAction(state3);
                     recursiveAction(state3);
                     return Disposable.Empty;
                     return Disposable.Empty;
@@ -246,7 +258,7 @@ namespace System.Reactive.Concurrency
 #if !NO_SERIALIZABLE
 #if !NO_SERIALIZABLE
         [Serializable]
         [Serializable]
 #endif
 #endif
-        struct Pair<T1, T2>
+        private struct Pair<T1, T2>
         {
         {
             public T1 First;
             public T1 First;
             public T2 Second;
             public T2 Second;

+ 23 - 14
Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.Emulation.cs

@@ -23,8 +23,8 @@ namespace System.Reactive.Concurrency
         /// <param name="period">Period for running the work periodically.</param>
         /// <param name="period">Period for running the work periodically.</param>
         /// <param name="action">Action to be executed, potentially updating the state.</param>
         /// <param name="action">Action to be executed, potentially updating the state.</param>
         /// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
-        /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than TimeSpan.Zero.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
+        /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than <see cref="TimeSpan.Zero"/>.</exception>
         public static IDisposable SchedulePeriodic<TState>(this IScheduler scheduler, TState state, TimeSpan period, Func<TState, TState> action)
         public static IDisposable SchedulePeriodic<TState>(this IScheduler scheduler, TState state, TimeSpan period, Func<TState, TState> action)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -49,8 +49,8 @@ namespace System.Reactive.Concurrency
         /// <param name="period">Period for running the work periodically.</param>
         /// <param name="period">Period for running the work periodically.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
-        /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than TimeSpan.Zero.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
+        /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than <see cref="TimeSpan.Zero"/>.</exception>
         public static IDisposable SchedulePeriodic<TState>(this IScheduler scheduler, TState state, TimeSpan period, Action<TState> action)
         public static IDisposable SchedulePeriodic<TState>(this IScheduler scheduler, TState state, TimeSpan period, Action<TState> action)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -73,8 +73,8 @@ namespace System.Reactive.Concurrency
         /// <param name="period">Period for running the work periodically.</param>
         /// <param name="period">Period for running the work periodically.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
-        /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than TimeSpan.Zero.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
+        /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than <see cref="TimeSpan.Zero"/>.</exception>
         public static IDisposable SchedulePeriodic(this IScheduler scheduler, TimeSpan period, Action action)
         public static IDisposable SchedulePeriodic(this IScheduler scheduler, TimeSpan period, Action action)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -94,7 +94,7 @@ namespace System.Reactive.Concurrency
         /// </summary>
         /// </summary>
         /// <param name="scheduler">Scheduler to obtain a stopwatch for.</param>
         /// <param name="scheduler">Scheduler to obtain a stopwatch for.</param>
         /// <returns>New stopwatch object; started at the time of the request.</returns>
         /// <returns>New stopwatch object; started at the time of the request.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is <c>null</c>.</exception>
         /// <remarks>The resulting stopwatch object can have non-monotonic behavior.</remarks>
         /// <remarks>The resulting stopwatch object can have non-monotonic behavior.</remarks>
         public static IStopwatch StartStopwatch(this IScheduler scheduler)
         public static IStopwatch StartStopwatch(this IScheduler scheduler)
         {
         {
@@ -135,7 +135,9 @@ namespace System.Reactive.Concurrency
             //
             //
             var swp = scheduler.AsStopwatchProvider();
             var swp = scheduler.AsStopwatchProvider();
             if (swp != null)
             if (swp != null)
+            {
                 return swp.StartStopwatch();
                 return swp.StartStopwatch();
+            }
 
 
             return new EmulatedStopwatch(scheduler);
             return new EmulatedStopwatch(scheduler);
         }
         }
@@ -287,7 +289,7 @@ namespace System.Reactive.Concurrency
             }
             }
         }
         }
 
 
-        class SchedulePeriodicStopwatch<TState>
+        private sealed class SchedulePeriodicStopwatch<TState>
         {
         {
             private readonly IScheduler _scheduler;
             private readonly IScheduler _scheduler;
             private readonly TimeSpan _period;
             private readonly TimeSpan _period;
@@ -409,7 +411,9 @@ namespace System.Reactive.Concurrency
                     // once more.
                     // once more.
                     //
                     //
                     if (shouldWaitForResume)
                     if (shouldWaitForResume)
+                    {
                         _resumeEvent.WaitOne();
                         _resumeEvent.WaitOne();
+                    }
                 }
                 }
 
 
                 recurse(next);
                 recurse(next);
@@ -424,7 +428,9 @@ namespace System.Reactive.Concurrency
                     _runState = DISPOSED;
                     _runState = DISPOSED;
 
 
                     if (!Environment.HasShutdownStarted)
                     if (!Environment.HasShutdownStarted)
+                    {
                         _resumeEvent.Set();
                         _resumeEvent.Set();
+                    }
                 }
                 }
             }
             }
 
 
@@ -452,7 +458,9 @@ namespace System.Reactive.Concurrency
                         _runState = SUSPENDED;
                         _runState = SUSPENDED;
 
 
                         if (!Environment.HasShutdownStarted)
                         if (!Environment.HasShutdownStarted)
+                        {
                             _resumeEvent.Reset();
                             _resumeEvent.Reset();
+                        }
                     }
                     }
                 }
                 }
             }
             }
@@ -484,7 +492,9 @@ namespace System.Reactive.Concurrency
                         _runState = RUNNING;
                         _runState = RUNNING;
 
 
                         if (!Environment.HasShutdownStarted)
                         if (!Environment.HasShutdownStarted)
+                        {
                             _resumeEvent.Set();
                             _resumeEvent.Set();
+                        }
                     }
                     }
                 }
                 }
             }
             }
@@ -504,7 +514,7 @@ namespace System.Reactive.Concurrency
             }
             }
         }
         }
 
 
-        class SchedulePeriodicRecursive<TState>
+        private sealed class SchedulePeriodicRecursive<TState>
         {
         {
             private readonly IScheduler _scheduler;
             private readonly IScheduler _scheduler;
             private readonly TimeSpan _period;
             private readonly TimeSpan _period;
@@ -605,14 +615,16 @@ namespace System.Reactive.Concurrency
                         // we make tail calls to play nice with the scheduler.
                         // we make tail calls to play nice with the scheduler.
                         //
                         //
                         if (Interlocked.Decrement(ref _pendingTickCount) > 0)
                         if (Interlocked.Decrement(ref _pendingTickCount) > 0)
+                        {
                             recurse(DISPATCH_START, TimeSpan.Zero);
                             recurse(DISPATCH_START, TimeSpan.Zero);
+                        }
 
 
                         break;
                         break;
                 }
                 }
             }
             }
         }
         }
 
 
-        class EmulatedStopwatch : IStopwatch
+        private sealed class EmulatedStopwatch : IStopwatch
         {
         {
             private readonly IScheduler _scheduler;
             private readonly IScheduler _scheduler;
             private readonly DateTimeOffset _start;
             private readonly DateTimeOffset _start;
@@ -623,10 +635,7 @@ namespace System.Reactive.Concurrency
                 _start = _scheduler.Now;
                 _start = _scheduler.Now;
             }
             }
 
 
-            public TimeSpan Elapsed
-            {
-                get { return Scheduler.Normalize(_scheduler.Now - _start); }
-            }
+            public TimeSpan Elapsed => Normalize(_scheduler.Now - _start);
         }
         }
     }
     }
 }
 }

+ 23 - 32
Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.cs

@@ -18,70 +18,61 @@ namespace System.Reactive.Concurrency
         };
         };
 
 
         /// <summary>
         /// <summary>
-        /// Returns the ISchedulerLongRunning implementation of the specified scheduler, or null if no such implementation is available.
+        /// Returns the <see cref="ISchedulerLongRunning"/> implementation of the specified scheduler, or <c>null</c> if no such implementation is available.
         /// </summary>
         /// </summary>
-        /// <param name="scheduler">Scheduler to get the ISchedulerLongRunning implementation for.</param>
-        /// <returns>The scheduler's ISchedulerLongRunning implementation if available; null otherwise.</returns>
+        /// <param name="scheduler">Scheduler to get the <see cref="ISchedulerLongRunning"/> implementation for.</param>
+        /// <returns>The scheduler's <see cref="ISchedulerLongRunning"/> implementation if available; <c>null</c> otherwise.</returns>
         /// <remarks>
         /// <remarks>
         /// This helper method is made available for query operator authors in order to discover scheduler services by using the required
         /// This helper method is made available for query operator authors in order to discover scheduler services by using the required
         /// IServiceProvider pattern, which allows for interception or redefinition of scheduler services.
         /// IServiceProvider pattern, which allows for interception or redefinition of scheduler services.
         /// </remarks>
         /// </remarks>
-        public static ISchedulerLongRunning AsLongRunning(this IScheduler scheduler)
-        {
-            var svc = scheduler as IServiceProvider;
-            if (svc != null)
-                return (ISchedulerLongRunning)svc.GetService(typeof(ISchedulerLongRunning));
-
-            return null;
-        }
+        public static ISchedulerLongRunning AsLongRunning(this IScheduler scheduler) => As<ISchedulerLongRunning>(scheduler);
 
 
         /// <summary>
         /// <summary>
-        /// Returns the IStopwatchProvider implementation of the specified scheduler, or null if no such implementation is available.
+        /// Returns the <see cref="IStopwatchProvider"/> implementation of the specified scheduler, or <c>null</c> if no such implementation is available.
         /// </summary>
         /// </summary>
-        /// <param name="scheduler">Scheduler to get the IStopwatchProvider implementation for.</param>
-        /// <returns>The scheduler's IStopwatchProvider implementation if available; null otherwise.</returns>
+        /// <param name="scheduler">Scheduler to get the <see cref="IStopwatchProvider"/> implementation for.</param>
+        /// <returns>The scheduler's <see cref="IStopwatchProvider"/> implementation if available; <c>null</c> otherwise.</returns>
         /// <remarks>
         /// <remarks>
         /// <para>
         /// <para>
         /// This helper method is made available for query operator authors in order to discover scheduler services by using the required
         /// This helper method is made available for query operator authors in order to discover scheduler services by using the required
         /// IServiceProvider pattern, which allows for interception or redefinition of scheduler services.
         /// IServiceProvider pattern, which allows for interception or redefinition of scheduler services.
         /// </para>
         /// </para>
         /// <para>
         /// <para>
-        /// Consider using <see cref="Scheduler.StartStopwatch"/> in case a stopwatch is required, but use of emulation stopwatch based
+        /// Consider using <see cref="StartStopwatch"/> in case a stopwatch is required, but use of emulation stopwatch based
         /// on the scheduler's clock is acceptable. Use of this method is recommended for best-effort use of the stopwatch provider
         /// on the scheduler's clock is acceptable. Use of this method is recommended for best-effort use of the stopwatch provider
         /// scheduler service, where the caller falls back to not using stopwatches if this facility wasn't found.
         /// scheduler service, where the caller falls back to not using stopwatches if this facility wasn't found.
         /// </para>
         /// </para>
         /// </remarks>
         /// </remarks>
-        public static IStopwatchProvider AsStopwatchProvider(this IScheduler scheduler)
-        {
-            var svc = scheduler as IServiceProvider;
-            if (svc != null)
-                return (IStopwatchProvider)svc.GetService(typeof(IStopwatchProvider));
-
-            return null;
-        }
+        public static IStopwatchProvider AsStopwatchProvider(this IScheduler scheduler) => As<IStopwatchProvider>(scheduler);
 
 
         /// <summary>
         /// <summary>
-        /// Returns the IStopwatchProvider implementation of the specified scheduler, or null if no such implementation is available.
+        /// Returns the <see cref="ISchedulerPeriodic"/> implementation of the specified scheduler, or <c>null</c> if no such implementation is available.
         /// </summary>
         /// </summary>
-        /// <param name="scheduler">Scheduler to get the IStopwatchProvider implementation for.</param>
-        /// <returns>The scheduler's IStopwatchProvider implementation if available; null otherwise.</returns>
+        /// <param name="scheduler">Scheduler to get the <see cref="ISchedulerPeriodic"/> implementation for.</param>
+        /// <returns>The scheduler's <see cref="ISchedulerPeriodic"/> implementation if available; <c>null</c> otherwise.</returns>
         /// <remarks>
         /// <remarks>
         /// <para>
         /// <para>
         /// This helper method is made available for query operator authors in order to discover scheduler services by using the required
         /// This helper method is made available for query operator authors in order to discover scheduler services by using the required
         /// IServiceProvider pattern, which allows for interception or redefinition of scheduler services.
         /// IServiceProvider pattern, which allows for interception or redefinition of scheduler services.
         /// </para>
         /// </para>
         /// <para>
         /// <para>
-        /// Consider using the Scheduler.SchedulePeriodic extension methods for IScheduler in case periodic scheduling is required and
-        /// emulation of periodic behavior using other scheduler services is desirable. Use of this method is recommended for best-effort
-        /// use of the periodic scheduling service, where the caller falls back to not using periodic scheduling if this facility wasn't
-        /// found.
+        /// Consider using the <see cref="SchedulePeriodic"/> extension methods for <see cref="IScheduler"/> in case periodic scheduling
+        /// is required and emulation of periodic behavior using other scheduler services is desirable. Use of this method is recommended
+        /// for best-effort use of the periodic scheduling service, where the caller falls back to not using periodic scheduling if this
+        /// facility wasn't found.
         /// </para>
         /// </para>
         /// </remarks>
         /// </remarks>
-        public static ISchedulerPeriodic AsPeriodic(this IScheduler scheduler)
+        public static ISchedulerPeriodic AsPeriodic(this IScheduler scheduler) => As<ISchedulerPeriodic>(scheduler);
+
+        private static T As<T>(IScheduler scheduler)
+            where T : class
         {
         {
             var svc = scheduler as IServiceProvider;
             var svc = scheduler as IServiceProvider;
             if (svc != null)
             if (svc != null)
-                return (ISchedulerPeriodic)svc.GetService(typeof(ISchedulerPeriodic));
+            {
+                return (T)svc.GetService(typeof(T));
+            }
 
 
             return null;
             return null;
         }
         }

+ 5 - 5
Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Simple.cs

@@ -14,7 +14,7 @@ namespace System.Reactive.Concurrency
         /// <param name="scheduler">Scheduler to execute the action on.</param>
         /// <param name="scheduler">Scheduler to execute the action on.</param>
         /// <param name="action">Action to execute.</param>
         /// <param name="action">Action to execute.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
         public static IDisposable Schedule(this IScheduler scheduler, Action action)
         public static IDisposable Schedule(this IScheduler scheduler, Action action)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -32,7 +32,7 @@ namespace System.Reactive.Concurrency
         /// <param name="action">Action to execute.</param>
         /// <param name="action">Action to execute.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
         public static IDisposable Schedule(this IScheduler scheduler, TimeSpan dueTime, Action action)
         public static IDisposable Schedule(this IScheduler scheduler, TimeSpan dueTime, Action action)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -50,7 +50,7 @@ namespace System.Reactive.Concurrency
         /// <param name="action">Action to execute.</param>
         /// <param name="action">Action to execute.</param>
         /// <param name="dueTime">Absolute time at which to execute the action.</param>
         /// <param name="dueTime">Absolute time at which to execute the action.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
         public static IDisposable Schedule(this IScheduler scheduler, DateTimeOffset dueTime, Action action)
         public static IDisposable Schedule(this IScheduler scheduler, DateTimeOffset dueTime, Action action)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -67,7 +67,7 @@ namespace System.Reactive.Concurrency
         /// <param name="scheduler">Scheduler to execute the action on.</param>
         /// <param name="scheduler">Scheduler to execute the action on.</param>
         /// <param name="action">Action to execute.</param>
         /// <param name="action">Action to execute.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
         public static IDisposable ScheduleLongRunning(this ISchedulerLongRunning scheduler, Action<ICancelable> action)
         public static IDisposable ScheduleLongRunning(this ISchedulerLongRunning scheduler, Action<ICancelable> action)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -78,7 +78,7 @@ namespace System.Reactive.Concurrency
             return scheduler.ScheduleLongRunning(action, (a, c) => a(c));
             return scheduler.ScheduleLongRunning(action, (a, c) => a(c));
         }
         }
 
 
-        static IDisposable Invoke(IScheduler scheduler, Action action)
+        private static IDisposable Invoke(IScheduler scheduler, Action action)
         {
         {
             action();
             action();
             return Disposable.Empty;
             return Disposable.Empty;

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

@@ -11,7 +11,7 @@ namespace System.Reactive.Concurrency
         /// </summary>
         /// </summary>
         /// <param name="scheduler">Scheduler to disable all optimizations for.</param>
         /// <param name="scheduler">Scheduler to disable all optimizations for.</param>
         /// <returns>Proxy to the original scheduler but without any optimizations enabled.</returns>
         /// <returns>Proxy to the original scheduler but without any optimizations enabled.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is <c>null</c>.</exception>
         public static IScheduler DisableOptimizations(this IScheduler scheduler)
         public static IScheduler DisableOptimizations(this IScheduler scheduler)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -26,7 +26,7 @@ namespace System.Reactive.Concurrency
         /// <param name="scheduler">Scheduler to disable the specified optimizations for.</param>
         /// <param name="scheduler">Scheduler to disable the specified optimizations for.</param>
         /// <param name="optimizationInterfaces">Types of the optimization interfaces that have to be disabled.</param>
         /// <param name="optimizationInterfaces">Types of the optimization interfaces that have to be disabled.</param>
         /// <returns>Proxy to the original scheduler but without the specified optimizations enabled.</returns>
         /// <returns>Proxy to the original scheduler but without the specified optimizations enabled.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="optimizationInterfaces"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="optimizationInterfaces"/> is <c>null</c>.</exception>
         public static IScheduler DisableOptimizations(this IScheduler scheduler, params Type[] optimizationInterfaces)
         public static IScheduler DisableOptimizations(this IScheduler scheduler, params Type[] optimizationInterfaces)
         {
         {
             if (scheduler == null)
             if (scheduler == null)
@@ -44,7 +44,7 @@ namespace System.Reactive.Concurrency
         /// <param name="scheduler">Scheduler to apply an exception filter for.</param>
         /// <param name="scheduler">Scheduler to apply an exception filter for.</param>
         /// <param name="handler">Handler that's run if an exception is caught. The exception will be rethrown if the handler returns false.</param>
         /// <param name="handler">Handler that's run if an exception is caught. The exception will be rethrown if the handler returns false.</param>
         /// <returns>Wrapper around the original scheduler, enforcing exception handling.</returns>
         /// <returns>Wrapper around the original scheduler, enforcing exception handling.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="handler"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="handler"/> is <c>null</c>.</exception>
         public static IScheduler Catch<TException>(this IScheduler scheduler, Func<TException, bool> handler)
         public static IScheduler Catch<TException>(this IScheduler scheduler, Func<TException, bool> handler)
             where TException : Exception
             where TException : Exception
         {
         {

+ 11 - 58
Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.cs

@@ -21,58 +21,29 @@ namespace System.Reactive.Concurrency
         /// <summary>
         /// <summary>
         /// Gets the current time according to the local machine's system clock.
         /// Gets the current time according to the local machine's system clock.
         /// </summary>
         /// </summary>
-        public static DateTimeOffset Now
-        {
-            get
-            {
-                return SystemClock.UtcNow;
-            }
-        }
+        public static DateTimeOffset Now => SystemClock.UtcNow;
 
 
         /// <summary>
         /// <summary>
-        /// Normalizes the specified TimeSpan value to a positive value.
+        /// Normalizes the specified <see cref="TimeSpan"/> value to a positive value.
         /// </summary>
         /// </summary>
-        /// <param name="timeSpan">The TimeSpan value to normalize.</param>
-        /// <returns>The specified TimeSpan value if it is zero or positive; otherwise, TimeSpan.Zero.</returns>
-        public static TimeSpan Normalize(TimeSpan timeSpan)
-        {
-            if (timeSpan.Ticks < 0)
-                return TimeSpan.Zero;
-            return timeSpan;
-        }
+        /// <param name="timeSpan">The <see cref="TimeSpan"/> value to normalize.</param>
+        /// <returns>The specified TimeSpan value if it is zero or positive; otherwise, <see cref="TimeSpan.Zero"/>.</returns>
+        public static TimeSpan Normalize(TimeSpan timeSpan) => timeSpan.Ticks < 0 ? TimeSpan.Zero : timeSpan;
 
 
         /// <summary>
         /// <summary>
         /// Gets a scheduler that schedules work immediately on the current thread.
         /// Gets a scheduler that schedules work immediately on the current thread.
         /// </summary>
         /// </summary>
-        public static ImmediateScheduler Immediate
-        {
-            get
-            {
-                return ImmediateScheduler.Instance;
-            }
-        }
+        public static ImmediateScheduler Immediate => ImmediateScheduler.Instance;
 
 
         /// <summary>
         /// <summary>
         /// Gets a scheduler that schedules work as soon as possible on the current thread.
         /// Gets a scheduler that schedules work as soon as possible on the current thread.
         /// </summary>
         /// </summary>
-        public static CurrentThreadScheduler CurrentThread
-        {
-            get
-            {
-                return CurrentThreadScheduler.Instance;
-            }
-        }
+        public static CurrentThreadScheduler CurrentThread => CurrentThreadScheduler.Instance;
 
 
         /// <summary>
         /// <summary>
         /// Gets a scheduler that schedules work on the platform's default scheduler.
         /// Gets a scheduler that schedules work on the platform's default scheduler.
         /// </summary>
         /// </summary>
-        public static DefaultScheduler Default
-        {
-            get
-            {
-                return DefaultScheduler.Instance;
-            }
-        }
+        public static DefaultScheduler Default => DefaultScheduler.Instance;
 
 
 
 
         //
         //
@@ -95,13 +66,7 @@ namespace System.Reactive.Concurrency
         /// Gets a scheduler that schedules work on the thread pool.
         /// Gets a scheduler that schedules work on the thread pool.
         /// </summary>
         /// </summary>
         [Obsolete(Constants_Core.OBSOLETE_SCHEDULER_THREADPOOL)]
         [Obsolete(Constants_Core.OBSOLETE_SCHEDULER_THREADPOOL)]
-        public static IScheduler ThreadPool
-        {
-            get
-            {
-                return s_threadPool.Value;
-            }
-        }
+        public static IScheduler ThreadPool => s_threadPool.Value;
 
 
         private static Lazy<IScheduler> s_newThread = new Lazy<IScheduler>(() => Initialize("NewThread"));
         private static Lazy<IScheduler> s_newThread = new Lazy<IScheduler>(() => Initialize("NewThread"));
 
 
@@ -109,13 +74,7 @@ namespace System.Reactive.Concurrency
         /// Gets a scheduler that schedules work on a new thread using default thread creation options.
         /// Gets a scheduler that schedules work on a new thread using default thread creation options.
         /// </summary>
         /// </summary>
         [Obsolete(Constants_Core.OBSOLETE_SCHEDULER_NEWTHREAD)]
         [Obsolete(Constants_Core.OBSOLETE_SCHEDULER_NEWTHREAD)]
-        public static IScheduler NewThread
-        {
-            get
-            {
-                return s_newThread.Value;
-            }
-        }
+        public static IScheduler NewThread => s_newThread.Value;
 
 
         private static Lazy<IScheduler> s_taskPool = new Lazy<IScheduler>(() => Initialize("TaskPool"));
         private static Lazy<IScheduler> s_taskPool = new Lazy<IScheduler>(() => Initialize("TaskPool"));
 
 
@@ -123,13 +82,7 @@ namespace System.Reactive.Concurrency
         /// Gets a scheduler that schedules work on Task Parallel Library (TPL) task pool using the default TaskScheduler.
         /// Gets a scheduler that schedules work on Task Parallel Library (TPL) task pool using the default TaskScheduler.
         /// </summary>
         /// </summary>
         [Obsolete(Constants_Core.OBSOLETE_SCHEDULER_TASKPOOL)]
         [Obsolete(Constants_Core.OBSOLETE_SCHEDULER_TASKPOOL)]
-        public static IScheduler TaskPool
-        {
-            get
-            {
-                return s_taskPool.Value;
-            }
-        }
+        public static IScheduler TaskPool => s_taskPool.Value;
 
 
         private static IScheduler Initialize(string name)
         private static IScheduler Initialize(string name)
         {
         {

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

@@ -6,10 +6,10 @@ namespace System.Reactive.Concurrency
 {
 {
     internal static class SchedulerDefaults
     internal static class SchedulerDefaults
     {
     {
-        internal static IScheduler ConstantTimeOperations { get { return ImmediateScheduler.Instance; } }
-        internal static IScheduler TailRecursion { get { return ImmediateScheduler.Instance; } }
-        internal static IScheduler Iteration { get { return CurrentThreadScheduler.Instance; } }
-        internal static IScheduler TimeBasedOperations { get { return DefaultScheduler.Instance; } }
-        internal static IScheduler AsyncConversions { get { return DefaultScheduler.Instance; } }
+        internal static IScheduler ConstantTimeOperations => ImmediateScheduler.Instance;
+        internal static IScheduler TailRecursion => ImmediateScheduler.Instance;
+        internal static IScheduler Iteration => CurrentThreadScheduler.Instance;
+        internal static IScheduler TimeBasedOperations => DefaultScheduler.Instance;
+        internal static IScheduler AsyncConversions => DefaultScheduler.Instance;
     }
     }
 }
 }

+ 5 - 15
Rx.NET/Source/src/System.Reactive/Concurrency/SchedulerOperation.cs

@@ -53,8 +53,7 @@ namespace System.Reactive.Concurrency
     /// (Infrastructure) Scheduler operation awaiter type used by the code generated for C# await and Visual Basic Await expressions.
     /// (Infrastructure) Scheduler operation awaiter type used by the code generated for C# await and Visual Basic Await expressions.
     /// </summary>
     /// </summary>
     [EditorBrowsable(EditorBrowsableState.Never)]
     [EditorBrowsable(EditorBrowsableState.Never)]
-    public sealed class SchedulerOperationAwaiter
-        : INotifyCompletion
+    public sealed class SchedulerOperationAwaiter : INotifyCompletion
     {
     {
         private readonly Func<Action, IDisposable> _schedule;
         private readonly Func<Action, IDisposable> _schedule;
         private readonly CancellationToken _cancellationToken;
         private readonly CancellationToken _cancellationToken;
@@ -76,18 +75,12 @@ namespace System.Reactive.Concurrency
         /// <summary>
         /// <summary>
         /// Indicates whether the scheduler operation has completed. Returns false unless cancellation was already requested.
         /// Indicates whether the scheduler operation has completed. Returns false unless cancellation was already requested.
         /// </summary>
         /// </summary>
-        public bool IsCompleted
-        {
-            get { return _cancellationToken.IsCancellationRequested; }
-        }
+        public bool IsCompleted => _cancellationToken.IsCancellationRequested;
 
 
         /// <summary>
         /// <summary>
         /// Completes the scheduler operation, throwing an OperationCanceledException in case cancellation was requested.
         /// Completes the scheduler operation, throwing an OperationCanceledException in case cancellation was requested.
         /// </summary>
         /// </summary>
-        public void GetResult()
-        {
-            _cancellationToken.ThrowIfCancellationRequested();
-        }
+        public void GetResult() => _cancellationToken.ThrowIfCancellationRequested();
 
 
         /// <summary>
         /// <summary>
         /// Registers the continuation with the scheduler operation.
         /// Registers the continuation with the scheduler operation.
@@ -147,11 +140,8 @@ namespace System.Reactive.Concurrency
 
 
         private void Cancel()
         private void Cancel()
         {
         {
-            var w = _work;
-            if (w != null)
-                w.Dispose();
-
+            _work?.Dispose();
             _continuation?.Invoke();
             _continuation?.Invoke();
         }
         }
     }
     }
-}
+}

+ 5 - 20
Rx.NET/Source/src/System.Reactive/Concurrency/SchedulerQueue.cs

@@ -39,13 +39,7 @@ namespace System.Reactive.Concurrency
         /// <summary>
         /// <summary>
         /// Gets the number of scheduled items in the scheduler queue.
         /// Gets the number of scheduled items in the scheduler queue.
         /// </summary>
         /// </summary>
-        public int Count
-        {
-            get
-            {
-                return _queue.Count;
-            }
-        }
+        public int Count => _queue.Count;
 
 
         /// <summary>
         /// <summary>
         /// Enqueues the specified work item to be scheduled.
         /// Enqueues the specified work item to be scheduled.
@@ -60,28 +54,19 @@ namespace System.Reactive.Concurrency
         /// Removes the specified work item from the scheduler queue.
         /// Removes the specified work item from the scheduler queue.
         /// </summary>
         /// </summary>
         /// <param name="scheduledItem">Work item to be removed from the scheduler queue.</param>
         /// <param name="scheduledItem">Work item to be removed from the scheduler queue.</param>
-        /// <returns>true if the item was found; false otherwise.</returns>
-        public bool Remove(ScheduledItem<TAbsolute> scheduledItem)
-        {
-            return _queue.Remove(scheduledItem);
-        }
+        /// <returns><c>true</c> if the item was found; <c>false</c> otherwise.</returns>
+        public bool Remove(ScheduledItem<TAbsolute> scheduledItem) => _queue.Remove(scheduledItem);
 
 
         /// <summary>
         /// <summary>
         /// Dequeues the next work item from the scheduler queue.
         /// Dequeues the next work item from the scheduler queue.
         /// </summary>
         /// </summary>
         /// <returns>Next work item in the scheduler queue (removed).</returns>
         /// <returns>Next work item in the scheduler queue (removed).</returns>
-        public ScheduledItem<TAbsolute> Dequeue()
-        {
-            return _queue.Dequeue();
-        }
+        public ScheduledItem<TAbsolute> Dequeue() => _queue.Dequeue();
 
 
         /// <summary>
         /// <summary>
         /// Peeks the next work item in the scheduler queue.
         /// Peeks the next work item in the scheduler queue.
         /// </summary>
         /// </summary>
         /// <returns>Next work item in the scheduler queue (not removed).</returns>
         /// <returns>Next work item in the scheduler queue (not removed).</returns>
-        public ScheduledItem<TAbsolute> Peek()
-        {
-            return _queue.Peek();
-        }
+        public ScheduledItem<TAbsolute> Peek() => _queue.Peek();
     }
     }
 }
 }

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

@@ -23,10 +23,7 @@ namespace System.Reactive.Concurrency
             _cache = cache;
             _cache = cache;
         }
         }
 
 
-        public DateTimeOffset Now
-        {
-            get { return _scheduler.Now; }
-        }
+        public DateTimeOffset Now => _scheduler.Now;
 
 
         public IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
         public IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
         {
         {

+ 8 - 8
Rx.NET/Source/src/System.Reactive/Concurrency/Synchronization.ObserveOn.cs

@@ -7,7 +7,7 @@ using System.Threading;
 
 
 namespace System.Reactive.Concurrency
 namespace System.Reactive.Concurrency
 {
 {
-    class ObserveOn<TSource> : Producer<TSource>
+    internal sealed class ObserveOn<TSource> : Producer<TSource>
     {
     {
         private readonly IObservable<TSource> _source;
         private readonly IObservable<TSource> _source;
         private readonly IScheduler _scheduler;
         private readonly IScheduler _scheduler;
@@ -42,7 +42,7 @@ namespace System.Reactive.Concurrency
             }
             }
         }
         }
 
 
-        class ObserveOnSink : Sink<TSource>, IObserver<TSource>
+        private sealed class ObserveOnSink : Sink<TSource>, IObserver<TSource>
         {
         {
             private readonly ObserveOn<TSource> _parent;
             private readonly ObserveOn<TSource> _parent;
 
 
@@ -84,24 +84,24 @@ namespace System.Reactive.Concurrency
 
 
             public void OnCompleted()
             public void OnCompleted()
             {
             {
-                _parent._context.Post(OnCompletedPosted, null);
+                _parent._context.Post(OnCompletedPosted, state: null);
             }
             }
 
 
             private void OnNextPosted(object value)
             private void OnNextPosted(object value)
             {
             {
-                base._observer.OnNext((TSource)value);
+                _observer.OnNext((TSource)value);
             }
             }
 
 
             private void OnErrorPosted(object error)
             private void OnErrorPosted(object error)
             {
             {
-                base._observer.OnError((Exception)error);
-                base.Dispose();
+                _observer.OnError((Exception)error);
+                Dispose();
             }
             }
 
 
             private void OnCompletedPosted(object ignored)
             private void OnCompletedPosted(object ignored)
             {
             {
-                base._observer.OnCompleted();
-                base.Dispose();
+                _observer.OnCompleted();
+                Dispose();
             }
             }
         }
         }
     }
     }

+ 7 - 7
Rx.NET/Source/src/System.Reactive/Concurrency/Synchronization.Synchronize.cs

@@ -4,7 +4,7 @@
 
 
 namespace System.Reactive.Concurrency
 namespace System.Reactive.Concurrency
 {
 {
-    class Synchronize<TSource> : Producer<TSource>
+    internal sealed class Synchronize<TSource> : Producer<TSource>
     {
     {
         private readonly IObservable<TSource> _source;
         private readonly IObservable<TSource> _source;
         private readonly object _gate;
         private readonly object _gate;
@@ -28,7 +28,7 @@ namespace System.Reactive.Concurrency
             return _source.SubscribeSafe(sink);
             return _source.SubscribeSafe(sink);
         }
         }
 
 
-        class _ : Sink<TSource>, IObserver<TSource>
+        private sealed class _ : Sink<TSource>, IObserver<TSource>
         {
         {
             private readonly Synchronize<TSource> _parent;
             private readonly Synchronize<TSource> _parent;
             private readonly object _gate;
             private readonly object _gate;
@@ -44,7 +44,7 @@ namespace System.Reactive.Concurrency
             {
             {
                 lock (_gate)
                 lock (_gate)
                 {
                 {
-                    base._observer.OnNext(value);
+                    _observer.OnNext(value);
                 }
                 }
             }
             }
 
 
@@ -52,8 +52,8 @@ namespace System.Reactive.Concurrency
             {
             {
                 lock (_gate)
                 lock (_gate)
                 {
                 {
-                    base._observer.OnError(error);
-                    base.Dispose();
+                    _observer.OnError(error);
+                    Dispose();
                 }
                 }
             }
             }
 
 
@@ -61,8 +61,8 @@ namespace System.Reactive.Concurrency
             {
             {
                 lock (_gate)
                 lock (_gate)
                 {
                 {
-                    base._observer.OnCompleted();
-                    base.Dispose();
+                    _observer.OnCompleted();
+                    Dispose();
                 }
                 }
             }
             }
         }
         }

+ 8 - 6
Rx.NET/Source/src/System.Reactive/Concurrency/Synchronization.cs

@@ -23,7 +23,7 @@ namespace System.Reactive.Concurrency
         /// <param name="source">Source sequence.</param>
         /// <param name="source">Source sequence.</param>
         /// <param name="scheduler">Scheduler to perform subscription and unsubscription actions on.</param>
         /// <param name="scheduler">Scheduler to perform subscription and unsubscription actions on.</param>
         /// <returns>The source sequence whose subscriptions and unsubscriptions happen on the specified scheduler.</returns>
         /// <returns>The source sequence whose subscriptions and unsubscriptions happen on the specified scheduler.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is <c>null</c>.</exception>
         /// <remarks>
         /// <remarks>
         /// Only the side-effects of subscribing to the source sequence and disposing subscriptions to the source sequence are run on the specified scheduler.
         /// Only the side-effects of subscribing to the source sequence and disposing subscriptions to the source sequence are run on the specified scheduler.
         /// In order to invoke observer callbacks on the specified scheduler, e.g. to offload callback processing to a dedicated thread, use <see cref="Synchronization.ObserveOn{TSource}(IObservable{TSource}, IScheduler)"/>.
         /// In order to invoke observer callbacks on the specified scheduler, e.g. to offload callback processing to a dedicated thread, use <see cref="Synchronization.ObserveOn{TSource}(IObservable{TSource}, IScheduler)"/>.
@@ -57,7 +57,7 @@ namespace System.Reactive.Concurrency
         /// <param name="source">Source sequence.</param>
         /// <param name="source">Source sequence.</param>
         /// <param name="context">Synchronization context to perform subscription and unsubscription actions on.</param>
         /// <param name="context">Synchronization context to perform subscription and unsubscription actions on.</param>
         /// <returns>The source sequence whose subscriptions and unsubscriptions happen on the specified synchronization context.</returns>
         /// <returns>The source sequence whose subscriptions and unsubscriptions happen on the specified synchronization context.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="context"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="context"/> is <c>null</c>.</exception>
         /// <remarks>
         /// <remarks>
         /// Only the side-effects of subscribing to the source sequence and disposing subscriptions to the source sequence are run on the specified synchronization context.
         /// Only the side-effects of subscribing to the source sequence and disposing subscriptions to the source sequence are run on the specified synchronization context.
         /// In order to invoke observer callbacks on the specified synchronization context, e.g. to post callbacks to a UI thread represented by the synchronization context, use <see cref="Synchronization.ObserveOn{TSource}(IObservable{TSource}, SynchronizationContext)"/>.
         /// In order to invoke observer callbacks on the specified synchronization context, e.g. to post callbacks to a UI thread represented by the synchronization context, use <see cref="Synchronization.ObserveOn{TSource}(IObservable{TSource}, SynchronizationContext)"/>.
@@ -75,7 +75,9 @@ namespace System.Reactive.Concurrency
                 context.PostWithStartComplete(() =>
                 context.PostWithStartComplete(() =>
                 {
                 {
                     if (!subscription.IsDisposed)
                     if (!subscription.IsDisposed)
+                    {
                         subscription.Disposable = new ContextDisposable(context, source.SubscribeSafe(observer));
                         subscription.Disposable = new ContextDisposable(context, source.SubscribeSafe(observer));
+                    }
                 });
                 });
                 return subscription;
                 return subscription;
             });
             });
@@ -92,7 +94,7 @@ namespace System.Reactive.Concurrency
         /// <param name="source">Source sequence.</param>
         /// <param name="source">Source sequence.</param>
         /// <param name="scheduler">Scheduler to notify observers on.</param>
         /// <param name="scheduler">Scheduler to notify observers on.</param>
         /// <returns>The source sequence whose observations happen on the specified scheduler.</returns>
         /// <returns>The source sequence whose observations happen on the specified scheduler.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is <c>null</c>.</exception>
         public static IObservable<TSource> ObserveOn<TSource>(IObservable<TSource> source, IScheduler scheduler)
         public static IObservable<TSource> ObserveOn<TSource>(IObservable<TSource> source, IScheduler scheduler)
         {
         {
             if (source == null)
             if (source == null)
@@ -110,7 +112,7 @@ namespace System.Reactive.Concurrency
         /// <param name="source">Source sequence.</param>
         /// <param name="source">Source sequence.</param>
         /// <param name="context">Synchronization context to notify observers on.</param>
         /// <param name="context">Synchronization context to notify observers on.</param>
         /// <returns>The source sequence whose observations happen on the specified synchronization context.</returns>
         /// <returns>The source sequence whose observations happen on the specified synchronization context.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="context"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="context"/> is <c>null</c>.</exception>
         public static IObservable<TSource> ObserveOn<TSource>(IObservable<TSource> source, SynchronizationContext context)
         public static IObservable<TSource> ObserveOn<TSource>(IObservable<TSource> source, SynchronizationContext context)
         {
         {
             if (source == null)
             if (source == null)
@@ -131,7 +133,7 @@ namespace System.Reactive.Concurrency
         /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
         /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
         /// <param name="source">Source sequence.</param>
         /// <param name="source">Source sequence.</param>
         /// <returns>The source sequence whose outgoing calls to observers are synchronized.</returns>
         /// <returns>The source sequence whose outgoing calls to observers are synchronized.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="source"/> is <c>null</c>.</exception>
         public static IObservable<TSource> Synchronize<TSource>(IObservable<TSource> source)
         public static IObservable<TSource> Synchronize<TSource>(IObservable<TSource> source)
         {
         {
             if (source == null)
             if (source == null)
@@ -147,7 +149,7 @@ namespace System.Reactive.Concurrency
         /// <param name="source">Source sequence.</param>
         /// <param name="source">Source sequence.</param>
         /// <param name="gate">Gate object to synchronize each observer call on.</param>
         /// <param name="gate">Gate object to synchronize each observer call on.</param>
         /// <returns>The source sequence whose outgoing calls to observers are synchronized on the given gate object.</returns>
         /// <returns>The source sequence whose outgoing calls to observers are synchronized on the given gate object.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="gate"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="gate"/> is <c>null</c>.</exception>
         public static IObservable<TSource> Synchronize<TSource>(IObservable<TSource> source, object gate)
         public static IObservable<TSource> Synchronize<TSource>(IObservable<TSource> source, object gate)
         {
         {
             if (source == null)
             if (source == null)

+ 8 - 4
Rx.NET/Source/src/System.Reactive/Concurrency/SynchronizationContextScheduler.cs

@@ -19,7 +19,7 @@ namespace System.Reactive.Concurrency
         /// Creates an object that schedules units of work on the provided <see cref="SynchronizationContext"/>.
         /// Creates an object that schedules units of work on the provided <see cref="SynchronizationContext"/>.
         /// </summary>
         /// </summary>
         /// <param name="context">Synchronization context to schedule units of work on.</param>
         /// <param name="context">Synchronization context to schedule units of work on.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="context"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="context"/> is <c>null</c>.</exception>
         public SynchronizationContextScheduler(SynchronizationContext context)
         public SynchronizationContextScheduler(SynchronizationContext context)
         {
         {
             if (context == null)
             if (context == null)
@@ -34,7 +34,7 @@ namespace System.Reactive.Concurrency
         /// </summary>
         /// </summary>
         /// <param name="context">Synchronization context to schedule units of work on.</param>
         /// <param name="context">Synchronization context to schedule units of work on.</param>
         /// <param name="alwaysPost">Configures whether scheduling always posts to the synchronization context, regardless whether the caller is on the same synchronization context.</param>
         /// <param name="alwaysPost">Configures whether scheduling always posts to the synchronization context, regardless whether the caller is on the same synchronization context.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="context"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="context"/> is <c>null</c>.</exception>
         public SynchronizationContextScheduler(SynchronizationContext context, bool alwaysPost)
         public SynchronizationContextScheduler(SynchronizationContext context, bool alwaysPost)
         {
         {
             if (context == null)
             if (context == null)
@@ -51,7 +51,7 @@ namespace System.Reactive.Concurrency
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public override IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
         public override IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
         {
         {
             if (action == null)
             if (action == null)
@@ -68,7 +68,9 @@ namespace System.Reactive.Concurrency
                 _context.PostWithStartComplete(() =>
                 _context.PostWithStartComplete(() =>
                 {
                 {
                     if (!d.IsDisposed)
                     if (!d.IsDisposed)
+                    {
                         d.Disposable = action(this, state);
                         d.Disposable = action(this, state);
+                    }
                 });
                 });
             }
             }
 
 
@@ -83,7 +85,7 @@ namespace System.Reactive.Concurrency
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public override IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
         public override IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
         {
         {
             if (action == null)
             if (action == null)
@@ -91,7 +93,9 @@ namespace System.Reactive.Concurrency
 
 
             var dt = Scheduler.Normalize(dueTime);
             var dt = Scheduler.Normalize(dueTime);
             if (dt.Ticks == 0)
             if (dt.Ticks == 0)
+            {
                 return Schedule(state, action);
                 return Schedule(state, action);
+            }
 
 
             return DefaultScheduler.Instance.Schedule(state, dt, (_, state1) => Schedule(state1, action));
             return DefaultScheduler.Instance.Schedule(state, dt, (_, state1) => Schedule(state1, action));
         }
         }

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

@@ -7,7 +7,7 @@ using System.Threading.Tasks;
 
 
 namespace System.Reactive.Concurrency
 namespace System.Reactive.Concurrency
 {
 {
-    static class TaskHelpers
+    internal static class TaskHelpers
     {
     {
         private const int MAX_DELAY = int.MaxValue;
         private const int MAX_DELAY = int.MaxValue;
 
 

+ 18 - 15
Rx.NET/Source/src/System.Reactive/Concurrency/TaskPoolScheduler.cs

@@ -18,10 +18,10 @@ namespace System.Reactive.Concurrency
         private readonly TaskFactory taskFactory;
         private readonly TaskFactory taskFactory;
 
 
         /// <summary>
         /// <summary>
-        /// Creates an object that schedules units of work using the provided TaskFactory.
+        /// Creates an object that schedules units of work using the provided <see cref="TaskFactory"/>.
         /// </summary>
         /// </summary>
         /// <param name="taskFactory">Task factory used to create tasks to run units of work.</param>
         /// <param name="taskFactory">Task factory used to create tasks to run units of work.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="taskFactory"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="taskFactory"/> is <c>null</c>.</exception>
         public TaskPoolScheduler(TaskFactory taskFactory)
         public TaskPoolScheduler(TaskFactory taskFactory)
         {
         {
             if (taskFactory == null)
             if (taskFactory == null)
@@ -31,15 +31,9 @@ namespace System.Reactive.Concurrency
         }
         }
 
 
         /// <summary>
         /// <summary>
-        /// Gets an instance of this scheduler that uses the default TaskScheduler.
+        /// Gets an instance of this scheduler that uses the default <see cref="TaskScheduler"/>.
         /// </summary>
         /// </summary>
-        public static TaskPoolScheduler Default
-        {
-            get
-            {
-                return s_instance.Value;
-            }
-        }
+        public static TaskPoolScheduler Default => s_instance.Value;
 
 
         /// <summary>
         /// <summary>
         /// Schedules an action to be executed.
         /// Schedules an action to be executed.
@@ -48,7 +42,7 @@ namespace System.Reactive.Concurrency
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public override IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
         public override IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
         {
         {
             if (action == null)
             if (action == null)
@@ -96,7 +90,7 @@ namespace System.Reactive.Concurrency
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public override IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
         public override IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
         {
         {
             if (action == null)
             if (action == null)
@@ -104,8 +98,15 @@ namespace System.Reactive.Concurrency
 
 
             var dt = Scheduler.Normalize(dueTime);
             var dt = Scheduler.Normalize(dueTime);
             if (dt.Ticks == 0)
             if (dt.Ticks == 0)
+            {
                 return Schedule(state, action);
                 return Schedule(state, action);
+            }
+
+            return ScheduleSlow(state, dt, action);
+        }
 
 
+        private IDisposable ScheduleSlow<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
+        {
             var d = new MultipleAssignmentDisposable();
             var d = new MultipleAssignmentDisposable();
 
 
             var ct = new CancellationDisposable();
             var ct = new CancellationDisposable();
@@ -114,7 +115,9 @@ namespace System.Reactive.Concurrency
             TaskHelpers.Delay(dueTime, ct.Token).ContinueWith(_ =>
             TaskHelpers.Delay(dueTime, ct.Token).ContinueWith(_ =>
             {
             {
                 if (!d.IsDisposed)
                 if (!d.IsDisposed)
+                {
                     d.Disposable = action(this, state);
                     d.Disposable = action(this, state);
+                }
             }, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion, taskFactory.Scheduler);
             }, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion, taskFactory.Scheduler);
 
 
             return d;
             return d;
@@ -127,7 +130,7 @@ namespace System.Reactive.Concurrency
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public IDisposable ScheduleLongRunning<TState>(TState state, Action<TState, ICancelable> action)
         public IDisposable ScheduleLongRunning<TState>(TState state, Action<TState, ICancelable> action)
         {
         {
             var d = new BooleanDisposable();
             var d = new BooleanDisposable();
@@ -167,8 +170,8 @@ namespace System.Reactive.Concurrency
         /// <param name="period">Period for running the work periodically.</param>
         /// <param name="period">Period for running the work periodically.</param>
         /// <param name="action">Action to be executed, potentially updating the state.</param>
         /// <param name="action">Action to be executed, potentially updating the state.</param>
         /// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
-        /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than TimeSpan.Zero.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
+        /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than <see cref="TimeSpan.Zero"/>.</exception>
         public IDisposable SchedulePeriodic<TState>(TState state, TimeSpan period, Func<TState, TState> action)
         public IDisposable SchedulePeriodic<TState>(TState state, TimeSpan period, Func<TState, TState> action)
         {
         {
             if (period < TimeSpan.Zero)
             if (period < TimeSpan.Zero)

+ 6 - 7
Rx.NET/Source/src/System.Reactive/Concurrency/Thread.Stub.cs

@@ -3,9 +3,11 @@
 // See the LICENSE file in the project root for more information. 
 // See the LICENSE file in the project root for more information. 
 
 
 #if NO_THREAD
 #if NO_THREAD
+using System.Threading.Tasks;
+
 namespace System.Reactive.Concurrency
 namespace System.Reactive.Concurrency
 {
 {
-    class Thread
+    internal sealed class Thread
     {
     {
         private readonly ThreadStart _start;
         private readonly ThreadStart _start;
 
 
@@ -19,15 +21,12 @@ namespace System.Reactive.Concurrency
 
 
         public void Start()
         public void Start()
         {
         {
-            System.Threading.Tasks.Task.Factory.StartNew(Run, System.Threading.Tasks.TaskCreationOptions.LongRunning);
+            Task.Factory.StartNew(Run, TaskCreationOptions.LongRunning);
         }
         }
 
 
-        private void Run()
-        {
-            _start();
-        }
+        private void Run() => _start();
     }
     }
 
 
     delegate void ThreadStart();
     delegate void ThreadStart();
 }
 }
-#endif
+#endif

+ 21 - 25
Rx.NET/Source/src/System.Reactive/Concurrency/ThreadPoolScheduler.Windows.cs

@@ -3,7 +3,6 @@
 // See the LICENSE file in the project root for more information. 
 // See the LICENSE file in the project root for more information. 
 
 
 #if WINDOWS
 #if WINDOWS
-using System.Reactive.Concurrency;
 using System.Reactive.Disposables;
 using System.Reactive.Disposables;
 using Windows.System.Threading;
 using Windows.System.Threading;
 
 
@@ -16,8 +15,6 @@ namespace System.Reactive.Concurrency
     [CLSCompliant(false)]
     [CLSCompliant(false)]
     public sealed class ThreadPoolScheduler : LocalScheduler, ISchedulerPeriodic
     public sealed class ThreadPoolScheduler : LocalScheduler, ISchedulerPeriodic
     {
     {
-        private readonly WorkItemPriority _priority;
-        private readonly WorkItemOptions _options;
         private static Lazy<ThreadPoolScheduler> s_default = new Lazy<ThreadPoolScheduler>(() => new ThreadPoolScheduler());
         private static Lazy<ThreadPoolScheduler> s_default = new Lazy<ThreadPoolScheduler>(() => new ThreadPoolScheduler());
 
 
         /// <summary>
         /// <summary>
@@ -33,8 +30,8 @@ namespace System.Reactive.Concurrency
         /// <param name="priority">Priority for scheduled units of work.</param>
         /// <param name="priority">Priority for scheduled units of work.</param>
         public ThreadPoolScheduler(WorkItemPriority priority)
         public ThreadPoolScheduler(WorkItemPriority priority)
         {
         {
-            _priority = priority;
-            _options = WorkItemOptions.None;
+            Priority = priority;
+            Options = WorkItemOptions.None;
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -44,36 +41,24 @@ namespace System.Reactive.Concurrency
         /// <param name="options">Options that configure how work is scheduled.</param>
         /// <param name="options">Options that configure how work is scheduled.</param>
         public ThreadPoolScheduler(WorkItemPriority priority, WorkItemOptions options)
         public ThreadPoolScheduler(WorkItemPriority priority, WorkItemOptions options)
         {
         {
-            _priority = priority;
-            _options = options;
+            Priority = priority;
+            Options = options;
         }
         }
 
 
         /// <summary>
         /// <summary>
         /// Gets the singleton instance of the Windows Runtime thread pool scheduler.
         /// Gets the singleton instance of the Windows Runtime thread pool scheduler.
         /// </summary>
         /// </summary>
-        public static ThreadPoolScheduler Default
-        {
-            get
-            {
-                return s_default.Value;
-            }
-        }
+        public static ThreadPoolScheduler Default => s_default.Value;
 
 
         /// <summary>
         /// <summary>
         /// Gets the priority at which work is scheduled.
         /// Gets the priority at which work is scheduled.
         /// </summary>
         /// </summary>
-        public WorkItemPriority Priority
-        {
-            get { return _priority; }
-        }
+        public WorkItemPriority Priority { get; }
 
 
         /// <summary>
         /// <summary>
         /// Gets the options that configure how work is scheduled.
         /// Gets the options that configure how work is scheduled.
         /// </summary>
         /// </summary>
-        public WorkItemOptions Options
-        {
-            get { return _options; }
-        }
+        public WorkItemOptions Options { get; }
 
 
         /// <summary>
         /// <summary>
         /// Schedules an action to be executed.
         /// Schedules an action to be executed.
@@ -93,8 +78,10 @@ namespace System.Reactive.Concurrency
             var res = global::Windows.System.Threading.ThreadPool.RunAsync(iaa =>
             var res = global::Windows.System.Threading.ThreadPool.RunAsync(iaa =>
             {
             {
                 if (!d.IsDisposed)
                 if (!d.IsDisposed)
+                {
                     d.Disposable = action(this, state);
                     d.Disposable = action(this, state);
-            }, _priority, _options);
+                }
+            }, Priority, Options);
 
 
             return new CompositeDisposable(
             return new CompositeDisposable(
                 d,
                 d,
@@ -119,17 +106,26 @@ namespace System.Reactive.Concurrency
             var dt = Scheduler.Normalize(dueTime);
             var dt = Scheduler.Normalize(dueTime);
 
 
             if (dt.Ticks == 0)
             if (dt.Ticks == 0)
+            {
                 return Schedule(state, action);
                 return Schedule(state, action);
+            }
 
 
+            return ScheduleSlow(state, dt, action);
+        }
+
+        private IDisposable ScheduleSlow<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
+        {
             var d = new SingleAssignmentDisposable();
             var d = new SingleAssignmentDisposable();
 
 
             var res = global::Windows.System.Threading.ThreadPoolTimer.CreateTimer(
             var res = global::Windows.System.Threading.ThreadPoolTimer.CreateTimer(
                 tpt =>
                 tpt =>
                 {
                 {
                     if (!d.IsDisposed)
                     if (!d.IsDisposed)
+                    {
                         d.Disposable = action(this, state);
                         d.Disposable = action(this, state);
+                    }
                 },
                 },
-                dt
+                dueTime
             );
             );
 
 
             return new CompositeDisposable(
             return new CompositeDisposable(
@@ -184,4 +180,4 @@ namespace System.Reactive.Concurrency
         }
         }
     }
     }
 }
 }
-#endif
+#endif

+ 17 - 28
Rx.NET/Source/src/System.Reactive/Concurrency/ThreadPoolScheduler.cs

@@ -21,15 +21,9 @@ namespace System.Reactive.Concurrency
         /// <summary>
         /// <summary>
         /// Gets the singleton instance of the CLR thread pool scheduler.
         /// Gets the singleton instance of the CLR thread pool scheduler.
         /// </summary>
         /// </summary>
-        public static ThreadPoolScheduler Instance
-        {
-            get
-            {
-                return s_instance.Value;
-            }
-        }
+        public static ThreadPoolScheduler Instance => s_instance.Value;
 
 
-        ThreadPoolScheduler()
+        private ThreadPoolScheduler()
         {
         {
         }
         }
 
 
@@ -40,7 +34,7 @@ namespace System.Reactive.Concurrency
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public override IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
         public override IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
         {
         {
             if (action == null)
             if (action == null)
@@ -51,7 +45,9 @@ namespace System.Reactive.Concurrency
             ThreadPool.QueueUserWorkItem(_ =>
             ThreadPool.QueueUserWorkItem(_ =>
             {
             {
                 if (!d.IsDisposed)
                 if (!d.IsDisposed)
+                {
                     d.Disposable = action(this, state);
                     d.Disposable = action(this, state);
+                }
             }, null);
             }, null);
 
 
             return d;
             return d;
@@ -65,7 +61,7 @@ namespace System.Reactive.Concurrency
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public override IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
         public override IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
         {
         {
             if (action == null)
             if (action == null)
@@ -73,7 +69,9 @@ namespace System.Reactive.Concurrency
 
 
             var dt = Scheduler.Normalize(dueTime);
             var dt = Scheduler.Normalize(dueTime);
             if (dt.Ticks == 0)
             if (dt.Ticks == 0)
+            {
                 return Schedule(state, action);
                 return Schedule(state, action);
+            }
 
 
             return new Timer<TState>(this, state, dt, action);
             return new Timer<TState>(this, state, dt, action);
         }
         }
@@ -85,7 +83,7 @@ namespace System.Reactive.Concurrency
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public IDisposable ScheduleLongRunning<TState>(TState state, Action<TState, ICancelable> action)
         public IDisposable ScheduleLongRunning<TState>(TState state, Action<TState, ICancelable> action)
         {
         {
             if (action == null)
             if (action == null)
@@ -116,7 +114,7 @@ namespace System.Reactive.Concurrency
         /// <param name="period">Period for running the work periodically.</param>
         /// <param name="period">Period for running the work periodically.</param>
         /// <param name="action">Action to be executed, potentially updating the state.</param>
         /// <param name="action">Action to be executed, potentially updating the state.</param>
         /// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than zero.</exception>
         /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than zero.</exception>
         public IDisposable SchedulePeriodic<TState>(TState state, TimeSpan period, Func<TState, TState> action)
         public IDisposable SchedulePeriodic<TState>(TState state, TimeSpan period, Func<TState, TState> action)
         {
         {
@@ -135,7 +133,7 @@ namespace System.Reactive.Concurrency
             }
             }
         }
         }
 
 
-        sealed class FastPeriodicTimer<TState> : IDisposable
+        private sealed class FastPeriodicTimer<TState> : IDisposable
         {
         {
             private TState _state;
             private TState _state;
             private Func<TState, TState> _action;
             private Func<TState, TState> _action;
@@ -170,7 +168,7 @@ namespace System.Reactive.Concurrency
         // below and its timer rooting behavior.
         // below and its timer rooting behavior.
         //
         //
 
 
-        sealed class Timer<TState> : IDisposable
+        private sealed class Timer<TState> : IDisposable
         {
         {
             private readonly MultipleAssignmentDisposable _disposable;
             private readonly MultipleAssignmentDisposable _disposable;
 
 
@@ -214,15 +212,9 @@ namespace System.Reactive.Concurrency
                 }
                 }
             }
             }
 
 
-            private bool IsTimerAssigned()
-            {
-                return _timer != null;
-            }
+            private bool IsTimerAssigned() => _timer != null;
 
 
-            public void Dispose()
-            {
-                _disposable.Dispose();
-            }
+            public void Dispose() => _disposable.Dispose();
 
 
             private void Stop()
             private void Stop()
             {
             {
@@ -236,13 +228,10 @@ namespace System.Reactive.Concurrency
                 }
                 }
             }
             }
 
 
-            private IDisposable Nop(IScheduler scheduler, TState state)
-            {
-                return Disposable.Empty;
-            }
+            private IDisposable Nop(IScheduler scheduler, TState state) => Disposable.Empty;
         }
         }
 
 
-        sealed class PeriodicTimer<TState> : IDisposable
+        private sealed class PeriodicTimer<TState> : IDisposable
         {
         {
             private TState _state;
             private TState _state;
             private Func<TState, TState> _action;
             private Func<TState, TState> _action;
@@ -287,4 +276,4 @@ namespace System.Reactive.Concurrency
         }
         }
     }
     }
 }
 }
-#endif
+#endif

+ 5 - 5
Rx.NET/Source/src/System.Reactive/Concurrency/VirtualTimeScheduler.Extensions.cs

@@ -12,7 +12,7 @@ namespace System.Reactive.Concurrency
     public static class VirtualTimeSchedulerExtensions
     public static class VirtualTimeSchedulerExtensions
     {
     {
         /// <summary>
         /// <summary>
-        /// Schedules an action to be executed at dueTime.
+        /// Schedules an action to be executed at <paramref name="dueTime"/>.
         /// </summary>
         /// </summary>
         /// <typeparam name="TAbsolute">Absolute time representation type.</typeparam>
         /// <typeparam name="TAbsolute">Absolute time representation type.</typeparam>
         /// <typeparam name="TRelative">Relative time representation type.</typeparam>
         /// <typeparam name="TRelative">Relative time representation type.</typeparam>
@@ -20,7 +20,7 @@ namespace System.Reactive.Concurrency
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
         public static IDisposable ScheduleRelative<TAbsolute, TRelative>(this VirtualTimeSchedulerBase<TAbsolute, TRelative> scheduler, TRelative dueTime, Action action)
         public static IDisposable ScheduleRelative<TAbsolute, TRelative>(this VirtualTimeSchedulerBase<TAbsolute, TRelative> scheduler, TRelative dueTime, Action action)
             where TAbsolute : IComparable<TAbsolute>
             where TAbsolute : IComparable<TAbsolute>
         {
         {
@@ -33,7 +33,7 @@ namespace System.Reactive.Concurrency
         }
         }
 
 
         /// <summary>
         /// <summary>
-        /// Schedules an action to be executed at dueTime.
+        /// Schedules an action to be executed at <paramref name="dueTime"/>.
         /// </summary>
         /// </summary>
         /// <typeparam name="TAbsolute">Absolute time representation type.</typeparam>
         /// <typeparam name="TAbsolute">Absolute time representation type.</typeparam>
         /// <typeparam name="TRelative">Relative time representation type.</typeparam>
         /// <typeparam name="TRelative">Relative time representation type.</typeparam>
@@ -41,7 +41,7 @@ namespace System.Reactive.Concurrency
         /// <param name="dueTime">Absolute time at which to execute the action.</param>
         /// <param name="dueTime">Absolute time at which to execute the action.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is <c>null</c>.</exception>
         public static IDisposable ScheduleAbsolute<TAbsolute, TRelative>(this VirtualTimeSchedulerBase<TAbsolute, TRelative> scheduler, TAbsolute dueTime, Action action)
         public static IDisposable ScheduleAbsolute<TAbsolute, TRelative>(this VirtualTimeSchedulerBase<TAbsolute, TRelative> scheduler, TAbsolute dueTime, Action action)
             where TAbsolute : IComparable<TAbsolute>
             where TAbsolute : IComparable<TAbsolute>
         {
         {
@@ -53,7 +53,7 @@ namespace System.Reactive.Concurrency
             return scheduler.ScheduleAbsolute(action, dueTime, Invoke);
             return scheduler.ScheduleAbsolute(action, dueTime, Invoke);
         }
         }
 
 
-        static IDisposable Invoke(IScheduler scheduler, Action action)
+        private static IDisposable Invoke(IScheduler scheduler, Action action)
         {
         {
             action();
             action();
             return Disposable.Empty;
             return Disposable.Empty;

+ 28 - 31
Rx.NET/Source/src/System.Reactive/Concurrency/VirtualTimeScheduler.cs

@@ -29,7 +29,7 @@ namespace System.Reactive.Concurrency
         /// </summary>
         /// </summary>
         /// <param name="initialClock">Initial value for the clock.</param>
         /// <param name="initialClock">Initial value for the clock.</param>
         /// <param name="comparer">Comparer to determine causality of events based on absolute time.</param>
         /// <param name="comparer">Comparer to determine causality of events based on absolute time.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="comparer"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="comparer"/> is <c>null</c>.</exception>
         protected VirtualTimeSchedulerBase(TAbsolute initialClock, IComparer<TAbsolute> comparer)
         protected VirtualTimeSchedulerBase(TAbsolute initialClock, IComparer<TAbsolute> comparer)
         {
         {
             if (comparer == null)
             if (comparer == null)
@@ -64,20 +64,12 @@ namespace System.Reactive.Concurrency
         /// <summary>
         /// <summary>
         /// Gets whether the scheduler is enabled to run work.
         /// Gets whether the scheduler is enabled to run work.
         /// </summary>
         /// </summary>
-        public bool IsEnabled
-        {
-            get;
-            private set;
-        }
+        public bool IsEnabled { get; private set; }
 
 
         /// <summary>
         /// <summary>
         /// Gets the comparer used to compare absolute time values.
         /// Gets the comparer used to compare absolute time values.
         /// </summary>
         /// </summary>
-        protected IComparer<TAbsolute> Comparer
-        {
-            get;
-            private set;
-        }
+        protected IComparer<TAbsolute> Comparer { get; }
 
 
         /// <summary>
         /// <summary>
         /// Schedules an action to be executed at dueTime.
         /// Schedules an action to be executed at dueTime.
@@ -114,7 +106,7 @@ namespace System.Reactive.Concurrency
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
         public IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
         {
         {
             if (action == null)
             if (action == null)
@@ -131,7 +123,7 @@ namespace System.Reactive.Concurrency
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
         public IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
         {
         {
             if (action == null)
             if (action == null)
@@ -148,7 +140,7 @@ namespace System.Reactive.Concurrency
         /// <param name="dueTime">Absolute time at which to execute the action.</param>
         /// <param name="dueTime">Absolute time at which to execute the action.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public IDisposable Schedule<TState>(TState state, DateTimeOffset dueTime, Func<IScheduler, TState, IDisposable> action)
         public IDisposable Schedule<TState>(TState state, DateTimeOffset dueTime, Func<IScheduler, TState, IDisposable> action)
         {
         {
             if (action == null)
             if (action == null)
@@ -171,11 +163,16 @@ namespace System.Reactive.Concurrency
                     if (next != null)
                     if (next != null)
                     {
                     {
                         if (Comparer.Compare(next.DueTime, Clock) > 0)
                         if (Comparer.Compare(next.DueTime, Clock) > 0)
+                        {
                             Clock = next.DueTime;
                             Clock = next.DueTime;
+                        }
+
                         next.Invoke();
                         next.Invoke();
                     }
                     }
                     else
                     else
+                    {
                         IsEnabled = false;
                         IsEnabled = false;
+                    }
                 } while (IsEnabled);
                 } while (IsEnabled);
             }
             }
         }
         }
@@ -212,18 +209,23 @@ namespace System.Reactive.Concurrency
                     if (next != null && Comparer.Compare(next.DueTime, time) <= 0)
                     if (next != null && Comparer.Compare(next.DueTime, time) <= 0)
                     {
                     {
                         if (Comparer.Compare(next.DueTime, Clock) > 0)
                         if (Comparer.Compare(next.DueTime, Clock) > 0)
+                        {
                             Clock = next.DueTime;
                             Clock = next.DueTime;
+                        }
+
                         next.Invoke();
                         next.Invoke();
                     }
                     }
                     else
                     else
+                    {
                         IsEnabled = false;
                         IsEnabled = false;
+                    }
                 } while (IsEnabled);
                 } while (IsEnabled);
 
 
                 Clock = time;
                 Clock = time;
             }
             }
             else
             else
             {
             {
-                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Strings_Linq.CANT_ADVANCE_WHILE_RUNNING, "AdvanceTo"));
+                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Strings_Linq.CANT_ADVANCE_WHILE_RUNNING, nameof(AdvanceTo)));
             }
             }
         }
         }
 
 
@@ -250,7 +252,7 @@ namespace System.Reactive.Concurrency
             }
             }
             else
             else
             {
             {
-                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Strings_Linq.CANT_ADVANCE_WHILE_RUNNING, "AdvanceBy"));
+                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Strings_Linq.CANT_ADVANCE_WHILE_RUNNING, nameof(AdvanceBy)));
             }
             }
         }
         }
 
 
@@ -282,10 +284,7 @@ namespace System.Reactive.Concurrency
         /// <summary>
         /// <summary>
         /// Gets the scheduler's notion of current time.
         /// Gets the scheduler's notion of current time.
         /// </summary>
         /// </summary>
-        public DateTimeOffset Now
-        {
-            get { return ToDateTimeOffset(Clock); }
-        }
+        public DateTimeOffset Now => ToDateTimeOffset(Clock);
 
 
         /// <summary>
         /// <summary>
         /// Gets the next scheduled item to be executed.
         /// Gets the next scheduled item to be executed.
@@ -294,10 +293,7 @@ namespace System.Reactive.Concurrency
         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "By design. Side-effecting operation to retrieve the next element.")]
         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "By design. Side-effecting operation to retrieve the next element.")]
         protected abstract IScheduledItem<TAbsolute> GetNext();
         protected abstract IScheduledItem<TAbsolute> GetNext();
 
 
-        object IServiceProvider.GetService(Type serviceType)
-        {
-            return GetService(serviceType);
-        }
+        object IServiceProvider.GetService(Type serviceType) => GetService(serviceType);
 
 
         /// <summary>
         /// <summary>
         /// Discovers scheduler services by interface type. The base class implementation supports
         /// Discovers scheduler services by interface type. The base class implementation supports
@@ -324,7 +320,7 @@ namespace System.Reactive.Concurrency
             return new VirtualTimeStopwatch(() => ToDateTimeOffset(Clock) - start);
             return new VirtualTimeStopwatch(() => ToDateTimeOffset(Clock) - start);
         }
         }
 
 
-        class VirtualTimeStopwatch : IStopwatch
+        private sealed class VirtualTimeStopwatch : IStopwatch
         {
         {
             private readonly Func<TimeSpan> _getElapsed;
             private readonly Func<TimeSpan> _getElapsed;
 
 
@@ -333,10 +329,7 @@ namespace System.Reactive.Concurrency
                 _getElapsed = getElapsed;
                 _getElapsed = getElapsed;
             }
             }
 
 
-            public TimeSpan Elapsed
-            {
-                get { return _getElapsed(); }
-            }
+            public TimeSpan Elapsed => _getElapsed();
         }
         }
     }
     }
 
 
@@ -363,7 +356,7 @@ namespace System.Reactive.Concurrency
         /// </summary>
         /// </summary>
         /// <param name="initialClock">Initial value for the clock.</param>
         /// <param name="initialClock">Initial value for the clock.</param>
         /// <param name="comparer">Comparer to determine causality of events based on absolute time.</param>
         /// <param name="comparer">Comparer to determine causality of events based on absolute time.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="comparer"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="comparer"/> is <c>null</c>.</exception>
         protected VirtualTimeScheduler(TAbsolute initialClock, IComparer<TAbsolute> comparer)
         protected VirtualTimeScheduler(TAbsolute initialClock, IComparer<TAbsolute> comparer)
             : base(initialClock, comparer)
             : base(initialClock, comparer)
         {
         {
@@ -381,9 +374,13 @@ namespace System.Reactive.Concurrency
                 {
                 {
                     var next = queue.Peek();
                     var next = queue.Peek();
                     if (next.IsCanceled)
                     if (next.IsCanceled)
+                    {
                         queue.Dequeue();
                         queue.Dequeue();
+                    }
                     else
                     else
+                    {
                         return next;
                         return next;
+                    }
                 }
                 }
             }
             }
 
 
@@ -398,7 +395,7 @@ namespace System.Reactive.Concurrency
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="dueTime">Absolute time at which to execute the action.</param>
         /// <param name="dueTime">Absolute time at which to execute the action.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public override IDisposable ScheduleAbsolute<TState>(TState state, TAbsolute dueTime, Func<IScheduler, TState, IDisposable> action)
         public override IDisposable ScheduleAbsolute<TState>(TState state, TAbsolute dueTime, Func<IScheduler, TState, IDisposable> action)
         {
         {
             if (action == null)
             if (action == null)

+ 5 - 10
Rx.NET/Source/src/System.Reactive/Internal/AnonymousEnumerable.cs

@@ -2,27 +2,22 @@
 // The .NET Foundation licenses this file to you under the Apache 2.0 License.
 // The .NET Foundation licenses this file to you under the Apache 2.0 License.
 // See the LICENSE file in the project root for more information. 
 // See the LICENSE file in the project root for more information. 
 
 
+using System.Collections;
 using System.Collections.Generic;
 using System.Collections.Generic;
 
 
 namespace System.Reactive
 namespace System.Reactive
 {
 {
     internal sealed class AnonymousEnumerable<T> : IEnumerable<T>
     internal sealed class AnonymousEnumerable<T> : IEnumerable<T>
     {
     {
-        private readonly Func<IEnumerator<T>> getEnumerator;
+        private readonly Func<IEnumerator<T>> _getEnumerator;
 
 
         public AnonymousEnumerable(Func<IEnumerator<T>> getEnumerator)
         public AnonymousEnumerable(Func<IEnumerator<T>> getEnumerator)
         {
         {
-            this.getEnumerator = getEnumerator;
+            _getEnumerator = getEnumerator;
         }
         }
 
 
-        public IEnumerator<T> GetEnumerator()
-        {
-            return getEnumerator();
-        }
+        public IEnumerator<T> GetEnumerator() => _getEnumerator();
 
 
-        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
-        {
-            return this.GetEnumerator();
-        }
+        IEnumerator IEnumerable.GetEnumerator() => _getEnumerator();
     }
     }
 }
 }

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Internal/AsyncLockObserver.cs

@@ -6,7 +6,7 @@ using System.Reactive.Concurrency;
 
 
 namespace System.Reactive
 namespace System.Reactive
 {
 {
-    internal class AsyncLockObserver<T> : ObserverBase<T>
+    internal sealed class AsyncLockObserver<T> : ObserverBase<T>
     {
     {
         private readonly AsyncLock _gate;
         private readonly AsyncLock _gate;
         private readonly IObserver<T> _observer;
         private readonly IObserver<T> _observer;

+ 14 - 10
Rx.NET/Source/src/System.Reactive/Internal/AutoDetachObserver.cs

@@ -6,19 +6,19 @@ using System.Reactive.Disposables;
 
 
 namespace System.Reactive
 namespace System.Reactive
 {
 {
-    class AutoDetachObserver<T> : ObserverBase<T>
+    internal sealed class AutoDetachObserver<T> : ObserverBase<T>
     {
     {
-        private readonly IObserver<T> observer;
-        private readonly SingleAssignmentDisposable m = new SingleAssignmentDisposable();
+        private readonly IObserver<T> _observer;
+        private readonly SingleAssignmentDisposable _disposable = new SingleAssignmentDisposable();
 
 
         public AutoDetachObserver(IObserver<T> observer)
         public AutoDetachObserver(IObserver<T> observer)
         {
         {
-            this.observer = observer;
+            _observer = observer;
         }
         }
 
 
         public IDisposable Disposable
         public IDisposable Disposable
         {
         {
-            set { m.Disposable = value; }
+            set { _disposable.Disposable = value; }
         }
         }
 
 
         protected override void OnNextCore(T value)
         protected override void OnNextCore(T value)
@@ -57,13 +57,15 @@ namespace System.Reactive
             var __noError = false;
             var __noError = false;
             try
             try
             {
             {
-                observer.OnNext(value);
+                _observer.OnNext(value);
                 __noError = true;
                 __noError = true;
             }
             }
             finally
             finally
             {
             {
                 if (!__noError)
                 if (!__noError)
+                {
                     Dispose();
                     Dispose();
+                }
             }
             }
         }
         }
 
 
@@ -71,7 +73,7 @@ namespace System.Reactive
         {
         {
             try
             try
             {
             {
-                observer.OnError(exception);
+                _observer.OnError(exception);
             }
             }
             finally
             finally
             {
             {
@@ -83,7 +85,7 @@ namespace System.Reactive
         {
         {
             try
             try
             {
             {
-                observer.OnCompleted();
+                _observer.OnCompleted();
             }
             }
             finally
             finally
             {
             {
@@ -96,7 +98,9 @@ namespace System.Reactive
             base.Dispose(disposing);
             base.Dispose(disposing);
 
 
             if (disposing)
             if (disposing)
-                m.Dispose();
+            {
+                _disposable.Dispose();
+            }
         }
         }
     }
     }
-}
+}

+ 3 - 3
Rx.NET/Source/src/System.Reactive/Internal/BinaryObserver.cs

@@ -4,7 +4,7 @@
 
 
 namespace System.Reactive
 namespace System.Reactive
 {
 {
-    class BinaryObserver<TLeft, TRight> : IObserver<Either<Notification<TLeft>, Notification<TRight>>>
+    internal sealed class BinaryObserver<TLeft, TRight> : IObserver<Either<Notification<TLeft>, Notification<TRight>>>
     {
     {
         public BinaryObserver(IObserver<TLeft> leftObserver, IObserver<TRight> rightObserver)
         public BinaryObserver(IObserver<TLeft> leftObserver, IObserver<TRight> rightObserver)
         {
         {
@@ -17,8 +17,8 @@ namespace System.Reactive
         {
         {
         }
         }
 
 
-        public IObserver<TLeft> LeftObserver { get; private set; }
-        public IObserver<TRight> RightObserver { get; private set; }
+        public IObserver<TLeft> LeftObserver { get; }
+        public IObserver<TRight> RightObserver { get; }
 
 
         void IObserver<Either<Notification<TLeft>, Notification<TRight>>>.OnNext(Either<Notification<TLeft>, Notification<TRight>> value)
         void IObserver<Either<Notification<TLeft>, Notification<TRight>>>.OnNext(Either<Notification<TLeft>, Notification<TRight>> value)
         {
         {

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Internal/CheckedObserver.cs

@@ -6,7 +6,7 @@ using System.Threading;
 
 
 namespace System.Reactive
 namespace System.Reactive
 {
 {
-    internal class CheckedObserver<T> : IObserver<T>
+    internal sealed class CheckedObserver<T> : IObserver<T>
     {
     {
         private readonly IObserver<T> _observer;
         private readonly IObserver<T> _observer;
         private int _state;
         private int _state;

+ 4 - 14
Rx.NET/Source/src/System.Reactive/Internal/ConcatSink.cs

@@ -6,25 +6,15 @@ using System.Collections.Generic;
 
 
 namespace System.Reactive
 namespace System.Reactive
 {
 {
-    abstract class ConcatSink<TSource> : TailRecursiveSink<TSource>
+    internal abstract class ConcatSink<TSource> : TailRecursiveSink<TSource>
     {
     {
         public ConcatSink(IObserver<TSource> observer, IDisposable cancel)
         public ConcatSink(IObserver<TSource> observer, IDisposable cancel)
-                : base(observer, cancel)
+            : base(observer, cancel)
         {
         {
         }
         }
 
 
-        protected override IEnumerable<IObservable<TSource>> Extract(IObservable<TSource> source)
-        {
-            var concat = source as IConcatenatable<TSource>;
-            if (concat != null)
-                return concat.GetSources();
-
-            return null;
-        }
+        protected override IEnumerable<IObservable<TSource>> Extract(IObservable<TSource> source) => (source as IConcatenatable<TSource>)?.GetSources();
 
 
-        public override void OnCompleted()
-        {
-            _recurse();
-        }
+        public override void OnCompleted() => _recurse();
     }
     }
 }
 }

+ 2 - 2
Rx.NET/Source/src/System.Reactive/Internal/Constants.cs

@@ -6,7 +6,7 @@ namespace System.Reactive
 {
 {
     // We can't make those based on the Strings_Core.resx file, because the ObsoleteAttribute needs a compile-time constant.
     // We can't make those based on the Strings_Core.resx file, because the ObsoleteAttribute needs a compile-time constant.
 
 
-    class Constants_Core
+    internal static class Constants_Core
     {
     {
         private const string OBSOLETE_REFACTORING = "This property is no longer supported due to refactoring of the API surface and elimination of platform-specific dependencies.";
         private const string OBSOLETE_REFACTORING = "This property is no longer supported due to refactoring of the API surface and elimination of platform-specific dependencies.";
 
 
@@ -19,7 +19,7 @@ namespace System.Reactive
 
 
     // We can't make those based on the Strings_*.resx file, because the ObsoleteAttribute needs a compile-time constant.
     // We can't make those based on the Strings_*.resx file, because the ObsoleteAttribute needs a compile-time constant.
 
 
-    class Constants_Linq
+    internal static class Constants_Linq
     {
     {
 #if PREFER_ASYNC
 #if PREFER_ASYNC
         public const string USE_ASYNC = "This blocking operation is no longer supported. Instead, use the async version in combination with C# and Visual Basic async/await support. In case you need a blocking operation, use Wait or convert the resulting observable sequence to a Task object and block.";
         public const string USE_ASYNC = "This blocking operation is no longer supported. Instead, use the async version in combination with C# and Visual Basic async/await support. In case you need a blocking operation, use Wait or convert the resulting observable sequence to a Task object and block.";

+ 4 - 2
Rx.NET/Source/src/System.Reactive/Internal/CurrentPlatformEnlightenmentProvider.cs

@@ -24,7 +24,7 @@ namespace System.Reactive.PlatformServices
         /// </summary>
         /// </summary>
         /// <typeparam name="T">Service type.</typeparam>
         /// <typeparam name="T">Service type.</typeparam>
         /// <param name="args">Optional set of arguments.</param>
         /// <param name="args">Optional set of arguments.</param>
-        /// <returns>Service instance or null if not found.</returns>
+        /// <returns>Service instance or <c>null</c> if not found.</returns>
         public virtual T GetService<T>(object[] args) where T : class
         public virtual T GetService<T>(object[] args) where T : class
         {
         {
             var t = typeof(T);
             var t = typeof(T);
@@ -94,7 +94,9 @@ namespace System.Reactive.PlatformServices
 
 
                     var dbg = Type.GetType(name, false);
                     var dbg = Type.GetType(name, false);
                     if (dbg != null)
                     if (dbg != null)
-                        return (T)(object)Activator.CreateInstance(dbg);
+                    {
+                        return (T)Activator.CreateInstance(dbg);
+                    }
                 }
                 }
             }
             }
 
 

+ 19 - 50
Rx.NET/Source/src/System.Reactive/Internal/Either.Generic.cs

@@ -7,43 +7,31 @@ using System.Globalization;
 
 
 namespace System.Reactive
 namespace System.Reactive
 {
 {
-    abstract class Either<TLeft, TRight>
+    internal abstract class Either<TLeft, TRight>
     {
     {
-        Either()
+        private Either()
         {
         {
         }
         }
 
 
-        public static Either<TLeft, TRight> CreateLeft(TLeft value)
-        {
-            return new Either<TLeft, TRight>.Left(value);
-        }
+        public static Either<TLeft, TRight> CreateLeft(TLeft value) =>  new Left(value);
 
 
-        public static Either<TLeft, TRight> CreateRight(TRight value)
-        {
-            return new Either<TLeft, TRight>.Right(value);
-        }
+        public static Either<TLeft, TRight> CreateRight(TRight value) => new Right(value);
 
 
         public abstract TResult Switch<TResult>(Func<TLeft, TResult> caseLeft, Func<TRight, TResult> caseRight);
         public abstract TResult Switch<TResult>(Func<TLeft, TResult> caseLeft, Func<TRight, TResult> caseRight);
         public abstract void Switch(Action<TLeft> caseLeft, Action<TRight> caseRight);
         public abstract void Switch(Action<TLeft> caseLeft, Action<TRight> caseRight);
 
 
         public sealed class Left : Either<TLeft, TRight>, IEquatable<Left>
         public sealed class Left : Either<TLeft, TRight>, IEquatable<Left>
         {
         {
-            public TLeft Value { get; private set; }
-
             public Left(TLeft value)
             public Left(TLeft value)
             {
             {
                 Value = value;
                 Value = value;
             }
             }
 
 
-            public override TResult Switch<TResult>(Func<TLeft, TResult> caseLeft, Func<TRight, TResult> caseRight)
-            {
-                return caseLeft(Value);
-            }
+            public TLeft Value { get; }
 
 
-            public override void Switch(Action<TLeft> caseLeft, Action<TRight> caseRight)
-            {
-                caseLeft(Value);
-            }
+            public override TResult Switch<TResult>(Func<TLeft, TResult> caseLeft, Func<TRight, TResult> caseRight) => caseLeft(Value);
+
+            public override void Switch(Action<TLeft> caseLeft, Action<TRight> caseRight) => caseLeft(Value);
 
 
             public bool Equals(Left other)
             public bool Equals(Left other)
             {
             {
@@ -51,18 +39,13 @@ namespace System.Reactive
                     return true;
                     return true;
                 if (other == null)
                 if (other == null)
                     return false;
                     return false;
+
                 return EqualityComparer<TLeft>.Default.Equals(Value, other.Value);
                 return EqualityComparer<TLeft>.Default.Equals(Value, other.Value);
             }
             }
 
 
-            public override bool Equals(object obj)
-            {
-                return Equals(obj as Left);
-            }
+            public override bool Equals(object obj) => Equals(obj as Left);
 
 
-            public override int GetHashCode()
-            {
-                return EqualityComparer<TLeft>.Default.GetHashCode(Value);
-            }
+            public override int GetHashCode() => EqualityComparer<TLeft>.Default.GetHashCode(Value);
 
 
             public override string ToString()
             public override string ToString()
             {
             {
@@ -72,22 +55,16 @@ namespace System.Reactive
 
 
         public sealed class Right : Either<TLeft, TRight>, IEquatable<Right>
         public sealed class Right : Either<TLeft, TRight>, IEquatable<Right>
         {
         {
-            public TRight Value { get; private set; }
-
             public Right(TRight value)
             public Right(TRight value)
             {
             {
                 Value = value;
                 Value = value;
             }
             }
 
 
-            public override TResult Switch<TResult>(Func<TLeft, TResult> caseLeft, Func<TRight, TResult> caseRight)
-            {
-                return caseRight(Value);
-            }
+            public TRight Value { get; }
 
 
-            public override void Switch(Action<TLeft> caseLeft, Action<TRight> caseRight)
-            {
-                caseRight(Value);
-            }
+            public override TResult Switch<TResult>(Func<TLeft, TResult> caseLeft, Func<TRight, TResult> caseRight) => caseRight(Value);
+
+            public override void Switch(Action<TLeft> caseLeft, Action<TRight> caseRight) => caseRight(Value);
 
 
             public bool Equals(Right other)
             public bool Equals(Right other)
             {
             {
@@ -95,23 +72,15 @@ namespace System.Reactive
                     return true;
                     return true;
                 if (other == null)
                 if (other == null)
                     return false;
                     return false;
+
                 return EqualityComparer<TRight>.Default.Equals(Value, other.Value);
                 return EqualityComparer<TRight>.Default.Equals(Value, other.Value);
             }
             }
 
 
-            public override bool Equals(object obj)
-            {
-                return Equals(obj as Right);
-            }
+            public override bool Equals(object obj) => Equals(obj as Right);
 
 
-            public override int GetHashCode()
-            {
-                return EqualityComparer<TRight>.Default.GetHashCode(Value);
-            }
+            public override int GetHashCode() => EqualityComparer<TRight>.Default.GetHashCode(Value);
 
 
-            public override string ToString()
-            {
-                return string.Format(CultureInfo.CurrentCulture, "Right({0})", Value);
-            }
+            public override string ToString() => string.Format(CultureInfo.CurrentCulture, "Right({0})", Value);
         }
         }
     }
     }
 }
 }

+ 3 - 4
Rx.NET/Source/src/System.Reactive/Internal/ExceptionServices.Default.cs

@@ -2,6 +2,8 @@
 // The .NET Foundation licenses this file to you under the Apache 2.0 License.
 // The .NET Foundation licenses this file to you under the Apache 2.0 License.
 // See the LICENSE file in the project root for more information. 
 // See the LICENSE file in the project root for more information. 
 
 
+using System.Runtime.ExceptionServices;
+
 namespace System.Reactive.PlatformServices
 namespace System.Reactive.PlatformServices
 {
 {
     //
     //
@@ -11,9 +13,6 @@ namespace System.Reactive.PlatformServices
     //
     //
     internal class DefaultExceptionServices/*Impl*/ : IExceptionServices
     internal class DefaultExceptionServices/*Impl*/ : IExceptionServices
     {
     {
-        public void Rethrow(Exception exception)
-        {
-            System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(exception).Throw();
-        }
+        public void Rethrow(Exception exception) => ExceptionDispatchInfo.Capture(exception).Throw();
     }
     }
 }
 }

+ 3 - 4
Rx.NET/Source/src/System.Reactive/Internal/ExceptionServices.cs

@@ -11,15 +11,14 @@ namespace System.Reactive
     {
     {
         private static Lazy<IExceptionServices> s_services = new Lazy<IExceptionServices>(Initialize);
         private static Lazy<IExceptionServices> s_services = new Lazy<IExceptionServices>(Initialize);
 
 
-        public static void Throw(this Exception exception)
-        {
-            s_services.Value.Rethrow(exception);
-        }
+        public static void Throw(this Exception exception) => s_services.Value.Rethrow(exception);
 
 
         public static void ThrowIfNotNull(this Exception exception)
         public static void ThrowIfNotNull(this Exception exception)
         {
         {
             if (exception != null)
             if (exception != null)
+            {
                 s_services.Value.Rethrow(exception);
                 s_services.Value.Rethrow(exception);
+            }
         }
         }
 
 
         private static IExceptionServices Initialize()
         private static IExceptionServices Initialize()

+ 3 - 4
Rx.NET/Source/src/System.Reactive/Internal/ExceptionServicesImpl.cs

@@ -2,6 +2,8 @@
 // The .NET Foundation licenses this file to you under the Apache 2.0 License.
 // The .NET Foundation licenses this file to you under the Apache 2.0 License.
 // See the LICENSE file in the project root for more information. 
 // See the LICENSE file in the project root for more information. 
 
 
+using System.Runtime.ExceptionServices;
+
 namespace System.Reactive.PlatformServices
 namespace System.Reactive.PlatformServices
 {
 {
     //
     //
@@ -11,9 +13,6 @@ namespace System.Reactive.PlatformServices
     //
     //
     internal class /*Default*/ExceptionServicesImpl : IExceptionServices
     internal class /*Default*/ExceptionServicesImpl : IExceptionServices
     {
     {
-        public void Rethrow(Exception exception)
-        {
-            System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(exception).Throw();
-        }
+        public void Rethrow(Exception exception) => ExceptionDispatchInfo.Capture(exception).Throw();
     }
     }
 }
 }

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Internal/IConcatenatable.cs

@@ -6,7 +6,7 @@ using System.Collections.Generic;
 
 
 namespace System.Reactive
 namespace System.Reactive
 {
 {
-    interface IConcatenatable<TSource>
+    internal interface IConcatenatable<out TSource>
     {
     {
         IEnumerable<IObservable<TSource>> GetSources();
         IEnumerable<IObservable<TSource>> GetSources();
     }
     }

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Internal/IEvaluatableObservable.cs

@@ -4,7 +4,7 @@
 
 
 namespace System.Reactive
 namespace System.Reactive
 {
 {
-    interface IEvaluatableObservable<T>
+    internal interface IEvaluatableObservable<out T>
     {
     {
         IObservable<T> Eval();
         IObservable<T> Eval();
     }
     }

+ 10 - 8
Rx.NET/Source/src/System.Reactive/Internal/ImmutableList.cs

@@ -4,7 +4,7 @@
 
 
 namespace System.Reactive
 namespace System.Reactive
 {
 {
-    internal class ImmutableList<T>
+    internal sealed class ImmutableList<T>
     {
     {
         public static readonly ImmutableList<T> Empty = new ImmutableList<T>();
         public static readonly ImmutableList<T> Empty = new ImmutableList<T>();
 
 
@@ -20,13 +20,7 @@ namespace System.Reactive
             _data = data;
             _data = data;
         }
         }
 
 
-        public T[] Data
-        {
-            get
-            {
-                return _data;
-            }
-        }
+        public T[] Data => _data;
 
 
         public ImmutableList<T> Add(T value)
         public ImmutableList<T> Add(T value)
         {
         {
@@ -42,11 +36,15 @@ namespace System.Reactive
         {
         {
             var i = IndexOf(value);
             var i = IndexOf(value);
             if (i < 0)
             if (i < 0)
+            {
                 return this;
                 return this;
+            }
 
 
             var length = _data.Length;
             var length = _data.Length;
             if (length == 1)
             if (length == 1)
+            {
                 return Empty;
                 return Empty;
+            }
 
 
             var newData = new T[length - 1];
             var newData = new T[length - 1];
 
 
@@ -59,8 +57,12 @@ namespace System.Reactive
         private int IndexOf(T value)
         private int IndexOf(T value)
         {
         {
             for (var i = 0; i < _data.Length; ++i)
             for (var i = 0; i < _data.Length; ++i)
+            {
                 if (object.Equals(_data[i], value))
                 if (object.Equals(_data[i], value))
+                {
                     return i;
                     return i;
+                }
+            }
 
 
             return -1;
             return -1;
         }
         }

+ 24 - 36
Rx.NET/Source/src/System.Reactive/Internal/Lookup.cs

@@ -8,34 +8,30 @@ using System.Linq;
 
 
 namespace System.Reactive
 namespace System.Reactive
 {
 {
-    class Lookup<K, E> : ILookup<K, E>
+    internal sealed class Lookup<K, E> : ILookup<K, E>
     {
     {
-        private readonly Dictionary<K, List<E>> d;
+        private readonly Dictionary<K, List<E>> _dictionary;
 
 
         public Lookup(IEqualityComparer<K> comparer)
         public Lookup(IEqualityComparer<K> comparer)
         {
         {
-            d = new Dictionary<K, List<E>>(comparer);
+            _dictionary = new Dictionary<K, List<E>>(comparer);
         }
         }
 
 
         public void Add(K key, E element)
         public void Add(K key, E element)
         {
         {
             var list = default(List<E>);
             var list = default(List<E>);
 
 
-            if (!d.TryGetValue(key, out list))
-                d[key] = list = new List<E>();
+            if (!_dictionary.TryGetValue(key, out list))
+            {
+                _dictionary[key] = list = new List<E>();
+            }
 
 
             list.Add(element);
             list.Add(element);
         }
         }
 
 
-        public bool Contains(K key)
-        {
-            return d.ContainsKey(key);
-        }
+        public bool Contains(K key) => _dictionary.ContainsKey(key);
 
 
-        public int Count
-        {
-            get { return d.Count; }
-        }
+        public int Count => _dictionary.Count;
 
 
         public IEnumerable<E> this[K key]
         public IEnumerable<E> this[K key]
         {
         {
@@ -43,7 +39,7 @@ namespace System.Reactive
             {
             {
                 var list = default(List<E>);
                 var list = default(List<E>);
 
 
-                if (!d.TryGetValue(key, out list))
+                if (!_dictionary.TryGetValue(key, out list))
                     return Enumerable.Empty<E>();
                     return Enumerable.Empty<E>();
 
 
                 return Hide(list);
                 return Hide(list);
@@ -53,43 +49,35 @@ namespace System.Reactive
         private IEnumerable<E> Hide(List<E> elements)
         private IEnumerable<E> Hide(List<E> elements)
         {
         {
             foreach (var x in elements)
             foreach (var x in elements)
+            {
                 yield return x;
                 yield return x;
+            }
         }
         }
 
 
         public IEnumerator<IGrouping<K, E>> GetEnumerator()
         public IEnumerator<IGrouping<K, E>> GetEnumerator()
         {
         {
-            foreach (var kv in d)
+            foreach (var kv in _dictionary)
+            {
                 yield return new Grouping(kv);
                 yield return new Grouping(kv);
+            }
         }
         }
 
 
-        class Grouping : IGrouping<K, E>
+        private sealed class Grouping : IGrouping<K, E>
         {
         {
-            KeyValuePair<K, List<E>> kv;
+            private readonly KeyValuePair<K, List<E>> _keyValuePair;
 
 
-            public Grouping(KeyValuePair<K, List<E>> kv)
+            public Grouping(KeyValuePair<K, List<E>> keyValuePair)
             {
             {
-                this.kv = kv;
+                _keyValuePair = keyValuePair;
             }
             }
 
 
-            public K Key
-            {
-                get { return kv.Key; }
-            }
+            public K Key => _keyValuePair.Key;
 
 
-            public IEnumerator<E> GetEnumerator()
-            {
-                return kv.Value.GetEnumerator();
-            }
+            public IEnumerator<E> GetEnumerator() => _keyValuePair.Value.GetEnumerator();
 
 
-            IEnumerator IEnumerable.GetEnumerator()
-            {
-                return GetEnumerator();
-            }
+            IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
         }
         }
 
 
-        IEnumerator IEnumerable.GetEnumerator()
-        {
-            return GetEnumerator();
-        }
+        IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
     }
     }
-}
+}

+ 19 - 26
Rx.NET/Source/src/System.Reactive/Internal/Observers.cs

@@ -4,43 +4,31 @@
 
 
 namespace System.Reactive
 namespace System.Reactive
 {
 {
-    internal class NopObserver<T> : IObserver<T>
+    internal sealed class NopObserver<T> : IObserver<T>
     {
     {
         public static readonly IObserver<T> Instance = new NopObserver<T>();
         public static readonly IObserver<T> Instance = new NopObserver<T>();
 
 
-        public void OnCompleted()
-        {
-        }
+        public void OnCompleted() { }
 
 
-        public void OnError(Exception error)
-        {
-        }
+        public void OnError(Exception error) { }
 
 
-        public void OnNext(T value)
-        {
-        }
+        public void OnNext(T value) { }
     }
     }
 
 
-    internal class DoneObserver<T> : IObserver<T>
+    internal sealed class DoneObserver<T> : IObserver<T>
     {
     {
         public static readonly IObserver<T> Completed = new DoneObserver<T>();
         public static readonly IObserver<T> Completed = new DoneObserver<T>();
 
 
         public Exception Exception { get; set; }
         public Exception Exception { get; set; }
 
 
-        public void OnCompleted()
-        {
-        }
+        public void OnCompleted() { }
 
 
-        public void OnError(Exception error)
-        {
-        }
+        public void OnError(Exception error) { }
 
 
-        public void OnNext(T value)
-        {
-        }
+        public void OnNext(T value) { }
     }
     }
 
 
-    internal class DisposedObserver<T> : IObserver<T>
+    internal sealed class DisposedObserver<T> : IObserver<T>
     {
     {
         public static readonly IObserver<T> Instance = new DisposedObserver<T>();
         public static readonly IObserver<T> Instance = new DisposedObserver<T>();
 
 
@@ -60,7 +48,7 @@ namespace System.Reactive
         }
         }
     }
     }
 
 
-    internal class Observer<T> : IObserver<T>
+    internal sealed class Observer<T> : IObserver<T>
     {
     {
         private readonly ImmutableList<IObserver<T>> _observers;
         private readonly ImmutableList<IObserver<T>> _observers;
 
 
@@ -72,31 +60,36 @@ namespace System.Reactive
         public void OnCompleted()
         public void OnCompleted()
         {
         {
             foreach (var observer in _observers.Data)
             foreach (var observer in _observers.Data)
+            {
                 observer.OnCompleted();
                 observer.OnCompleted();
+            }
         }
         }
 
 
         public void OnError(Exception error)
         public void OnError(Exception error)
         {
         {
             foreach (var observer in _observers.Data)
             foreach (var observer in _observers.Data)
+            {
                 observer.OnError(error);
                 observer.OnError(error);
+            }
         }
         }
 
 
         public void OnNext(T value)
         public void OnNext(T value)
         {
         {
             foreach (var observer in _observers.Data)
             foreach (var observer in _observers.Data)
+            {
                 observer.OnNext(value);
                 observer.OnNext(value);
+            }
         }
         }
 
 
-        internal IObserver<T> Add(IObserver<T> observer)
-        {
-            return new Observer<T>(_observers.Add(observer));
-        }
+        internal IObserver<T> Add(IObserver<T> observer) => new Observer<T>(_observers.Add(observer));
 
 
         internal IObserver<T> Remove(IObserver<T> observer)
         internal IObserver<T> Remove(IObserver<T> observer)
         {
         {
             var i = Array.IndexOf(_observers.Data, observer);
             var i = Array.IndexOf(_observers.Data, observer);
             if (i < 0)
             if (i < 0)
+            {
                 return this;
                 return this;
+            }
 
 
             if (_observers.Data.Length == 2)
             if (_observers.Data.Length == 2)
             {
             {

+ 5 - 5
Rx.NET/Source/src/System.Reactive/Internal/PlatformEnlightenmentProvider.cs

@@ -49,17 +49,17 @@ namespace System.Reactive.PlatformServices
             {
             {
                 return s_current;
                 return s_current;
             }
             }
+
             set
             set
             {
             {
-                if (value == null) throw new ArgumentNullException(nameof(value));
+                if (value == null)
+                    throw new ArgumentNullException(nameof(value));
+
                 s_current = value;
                 s_current = value;
             }
             }
             
             
         }
         }
 
 
-        private static IPlatformEnlightenmentProvider CreatePlatformProvider()
-        {
-            return new CurrentPlatformEnlightenmentProvider();
-        }
+        private static IPlatformEnlightenmentProvider CreatePlatformProvider() => new CurrentPlatformEnlightenmentProvider();
     }
     }
 }
 }

+ 22 - 7
Rx.NET/Source/src/System.Reactive/Internal/PriorityQueue.cs

@@ -7,7 +7,7 @@ using System.Collections.Generic;
 
 
 namespace System.Reactive
 namespace System.Reactive
 {
 {
-    internal class PriorityQueue<T> where T : IComparable<T>
+    internal sealed class PriorityQueue<T> where T : IComparable<T>
     {
     {
         private static long _count = long.MinValue;
         private static long _count = long.MinValue;
         private IndexedItem[] _items;
         private IndexedItem[] _items;
@@ -32,10 +32,15 @@ namespace System.Reactive
         private void Percolate(int index)
         private void Percolate(int index)
         {
         {
             if (index >= _size || index < 0)
             if (index >= _size || index < 0)
+            {
                 return;
                 return;
+            }
+
             var parent = (index - 1) / 2;
             var parent = (index - 1) / 2;
             if (parent < 0 || parent == index)
             if (parent < 0 || parent == index)
+            {
                 return;
                 return;
+            }
 
 
             if (IsHigherPriority(index, parent))
             if (IsHigherPriority(index, parent))
             {
             {
@@ -46,24 +51,29 @@ namespace System.Reactive
             }
             }
         }
         }
 
 
-        private void Heapify()
-        {
-            Heapify(0);
-        }
+        private void Heapify() => Heapify(index: 0);
 
 
         private void Heapify(int index)
         private void Heapify(int index)
         {
         {
             if (index >= _size || index < 0)
             if (index >= _size || index < 0)
+            {
                 return;
                 return;
+            }
 
 
             var left = 2 * index + 1;
             var left = 2 * index + 1;
             var right = 2 * index + 2;
             var right = 2 * index + 2;
             var first = index;
             var first = index;
 
 
             if (left < _size && IsHigherPriority(left, first))
             if (left < _size && IsHigherPriority(left, first))
+            {
                 first = left;
                 first = left;
+            }
+
             if (right < _size && IsHigherPriority(right, first))
             if (right < _size && IsHigherPriority(right, first))
+            {
                 first = right;
                 first = right;
+            }
+
             if (first != index)
             if (first != index)
             {
             {
                 var temp = _items[index];
                 var temp = _items[index];
@@ -73,7 +83,7 @@ namespace System.Reactive
             }
             }
         }
         }
 
 
-        public int Count { get { return _size; } }
+        public int Count => _size;
 
 
         public T Peek()
         public T Peek()
         {
         {
@@ -87,7 +97,9 @@ namespace System.Reactive
         {
         {
             _items[index] = _items[--_size];
             _items[index] = _items[--_size];
             _items[_size] = default(IndexedItem);
             _items[_size] = default(IndexedItem);
+
             Heapify();
             Heapify();
+
             if (_size < _items.Length / 4)
             if (_size < _items.Length / 4)
             {
             {
                 var temp = _items;
                 var temp = _items;
@@ -131,7 +143,7 @@ namespace System.Reactive
             return false;
             return false;
         }
         }
 
 
-        struct IndexedItem : IComparable<IndexedItem>
+        private struct IndexedItem : IComparable<IndexedItem>
         {
         {
             public T Value;
             public T Value;
             public long Id;
             public long Id;
@@ -140,7 +152,10 @@ namespace System.Reactive
             {
             {
                 var c = Value.CompareTo(other.Value);
                 var c = Value.CompareTo(other.Value);
                 if (c == 0)
                 if (c == 0)
+                {
                     c = Id.CompareTo(other.Id);
                     c = Id.CompareTo(other.Id);
+                }
+
                 return c;
                 return c;
             }
             }
         }
         }

+ 2 - 2
Rx.NET/Source/src/System.Reactive/Internal/Producer.cs

@@ -59,13 +59,13 @@ namespace System.Reactive
             }
             }
             else
             else
             {
             {
-                state.subscription.Disposable = this.Run(state.observer, state.subscription, state.Assign);
+                state.subscription.Disposable = Run(state.observer, state.subscription, state.Assign);
             }
             }
 
 
             return d;
             return d;
         }
         }
 
 
-        struct State
+        private struct State
         {
         {
             public SingleAssignmentDisposable sink;
             public SingleAssignmentDisposable sink;
             public SingleAssignmentDisposable subscription;
             public SingleAssignmentDisposable subscription;

+ 4 - 10
Rx.NET/Source/src/System.Reactive/Internal/QueryServices.cs

@@ -8,12 +8,9 @@ namespace System.Reactive.Linq
 {
 {
     internal static class QueryServices
     internal static class QueryServices
     {
     {
-        private static IQueryServices s_services = Initialize();
+        private static readonly IQueryServices s_services = Initialize();
 
 
-        public static T GetQueryImpl<T>(T defaultInstance)
-        {
-            return s_services.Extend(defaultInstance);
-        }
+        public static T GetQueryImpl<T>(T defaultInstance) => s_services.Extend(defaultInstance);
 
 
         private static IQueryServices Initialize()
         private static IQueryServices Initialize()
         {
         {
@@ -28,11 +25,8 @@ namespace System.Reactive.Linq
         T Extend<T>(T baseImpl);
         T Extend<T>(T baseImpl);
     }
     }
 
 
-    class DefaultQueryServices : IQueryServices
+    internal sealed class DefaultQueryServices : IQueryServices
     {
     {
-        public T Extend<T>(T baseImpl)
-        {
-            return baseImpl;
-        }
+        public T Extend<T>(T baseImpl) => baseImpl;
     }
     }
 }
 }

+ 11 - 18
Rx.NET/Source/src/System.Reactive/Internal/ReflectionUtils.cs

@@ -2,7 +2,6 @@
 // The .NET Foundation licenses this file to you under the Apache 2.0 License.
 // The .NET Foundation licenses this file to you under the Apache 2.0 License.
 // See the LICENSE file in the project root for more information. 
 // See the LICENSE file in the project root for more information. 
 
 
-using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Globalization;
 using System.Globalization;
 using System.Reflection;
 using System.Reflection;
@@ -13,7 +12,7 @@ using System.Runtime.InteropServices.WindowsRuntime;
 
 
 namespace System.Reactive
 namespace System.Reactive
 {
 {
-    static class ReflectionUtils
+    internal static class ReflectionUtils
     {
     {
         public static TDelegate CreateDelegate<TDelegate>(object o, MethodInfo method)
         public static TDelegate CreateDelegate<TDelegate>(object o, MethodInfo method)
         {
         {
@@ -111,13 +110,19 @@ namespace System.Reactive
 
 
                 var e = t.GetDeclaredEvent(name);
                 var e = t.GetDeclaredEvent(name);
                 if (e != null)
                 if (e != null)
+                {
                     return e;
                     return e;
+                }
 
 
                 foreach (var i in t.ImplementedInterfaces)
                 foreach (var i in t.ImplementedInterfaces)
+                {
                     q.Enqueue(i.GetTypeInfo());
                     q.Enqueue(i.GetTypeInfo());
+                }
 
 
                 if (t.BaseType != null)
                 if (t.BaseType != null)
+                {
                     q.Enqueue(t.BaseType.GetTypeInfo());
                     q.Enqueue(t.BaseType.GetTypeInfo());
+                }
             }
             }
 
 
             return null;
             return null;
@@ -127,25 +132,13 @@ namespace System.Reactive
         }
         }
 
 
 #if (CRIPPLED_REFLECTION && HAS_WINRT)
 #if (CRIPPLED_REFLECTION && HAS_WINRT)
-        public static MethodInfo GetMethod(this Type type, string name)
-        {
-            return type.GetTypeInfo().GetDeclaredMethod(name);
-        }
+        public static MethodInfo GetMethod(this Type type, string name) => type.GetTypeInfo().GetDeclaredMethod(name);
 
 
-        public static MethodInfo GetAddMethod(this EventInfo eventInfo)
-        {
-            return eventInfo.AddMethod;
-        }
+        public static MethodInfo GetAddMethod(this EventInfo eventInfo) => eventInfo.AddMethod;
 
 
-        public static MethodInfo GetRemoveMethod(this EventInfo eventInfo)
-        {
-            return eventInfo.RemoveMethod;
-        }
+        public static MethodInfo GetRemoveMethod(this EventInfo eventInfo) => eventInfo.RemoveMethod;
 
 
-        public static bool IsAssignableFrom(this Type type1, Type type2)
-        {
-            return type1.GetTypeInfo().IsAssignableFrom(type2.GetTypeInfo());
-        }
+        public static bool IsAssignableFrom(this Type type1, Type type2) => type1.GetTypeInfo().IsAssignableFrom(type2.GetTypeInfo());
 #endif
 #endif
     }
     }
 }
 }

+ 7 - 1
Rx.NET/Source/src/System.Reactive/Internal/SafeObserver.cs

@@ -9,7 +9,7 @@ namespace System.Reactive
     // its implementation aspects.
     // its implementation aspects.
     //
     //
 
 
-    class SafeObserver<TSource> : IObserver<TSource>
+    internal sealed class SafeObserver<TSource> : IObserver<TSource>
     {
     {
         private readonly IObserver<TSource> _observer;
         private readonly IObserver<TSource> _observer;
         private readonly IDisposable _disposable;
         private readonly IDisposable _disposable;
@@ -18,9 +18,13 @@ namespace System.Reactive
         {
         {
             var a = observer as AnonymousObserver<TSource>;
             var a = observer as AnonymousObserver<TSource>;
             if (a != null)
             if (a != null)
+            {
                 return a.MakeSafe(disposable);
                 return a.MakeSafe(disposable);
+            }
             else
             else
+            {
                 return new SafeObserver<TSource>(observer, disposable);
                 return new SafeObserver<TSource>(observer, disposable);
+            }
         }
         }
 
 
         private SafeObserver(IObserver<TSource> observer, IDisposable disposable)
         private SafeObserver(IObserver<TSource> observer, IDisposable disposable)
@@ -40,7 +44,9 @@ namespace System.Reactive
             finally
             finally
             {
             {
                 if (!__noError)
                 if (!__noError)
+                {
                     _disposable.Dispose();
                     _disposable.Dispose();
+                }
             }
             }
         }
         }
 
 

+ 7 - 11
Rx.NET/Source/src/System.Reactive/Internal/ScheduledObserver.cs

@@ -115,17 +115,16 @@ namespace System.Reactive
             }
             }
         }
         }
 
 
-        public void EnsureActive()
-        {
-            EnsureActive(1);
-        }
+        public void EnsureActive() => EnsureActive(1);
 
 
         public void EnsureActive(int n)
         public void EnsureActive(int n)
         {
         {
             if (_longRunning != null)
             if (_longRunning != null)
             {
             {
                 if (n > 0)
                 if (n > 0)
+                {
                     _dispatcherEvent.Release(n);
                     _dispatcherEvent.Release(n);
+                }
 
 
                 EnsureDispatcher();
                 EnsureDispatcher();
             }
             }
@@ -261,6 +260,7 @@ namespace System.Reactive
                 var nop = default(T);
                 var nop = default(T);
                 while (_queue.TryDequeue(out nop))
                 while (_queue.TryDequeue(out nop))
                     ;
                     ;
+
                 throw;
                 throw;
             }
             }
 
 
@@ -294,7 +294,7 @@ namespace System.Reactive
         }
         }
     }
     }
 
 
-    class ObserveOnObserver<T> : ScheduledObserver<T>
+    internal sealed class ObserveOnObserver<T> : ScheduledObserver<T>
     {
     {
         private IDisposable _cancel;
         private IDisposable _cancel;
 
 
@@ -328,16 +328,12 @@ namespace System.Reactive
 
 
             if (disposing)
             if (disposing)
             {
             {
-                var cancel = Interlocked.Exchange(ref _cancel, null);
-                if (cancel != null)
-                {
-                    cancel.Dispose();
-                }
+                Interlocked.Exchange(ref _cancel, null)?.Dispose();
             }
             }
         }
         }
     }
     }
 
 
-    interface IScheduledObserver<T> : IObserver<T>, IDisposable
+    internal interface IScheduledObserver<T> : IObserver<T>, IDisposable
     {
     {
         void EnsureActive();
         void EnsureActive();
         void EnsureActive(int count);
         void EnsureActive(int count);

+ 3 - 10
Rx.NET/Source/src/System.Reactive/Internal/Sink.cs

@@ -26,19 +26,12 @@ namespace System.Reactive
         {
         {
             _observer = NopObserver<TSource>.Instance;
             _observer = NopObserver<TSource>.Instance;
 
 
-            var cancel = Interlocked.Exchange(ref _cancel, null);
-            if (cancel != null)
-            {
-                cancel.Dispose();
-            }
+            Interlocked.Exchange(ref _cancel, null)?.Dispose();
         }
         }
 
 
-        public IObserver<TSource> GetForwarder()
-        {
-            return new _(this);
-        }
+        public IObserver<TSource> GetForwarder() => new _(this);
 
 
-        class _ : IObserver<TSource>
+        private sealed class _ : IObserver<TSource>
         {
         {
             private readonly Sink<TSource> _forward;
             private readonly Sink<TSource> _forward;
 
 

+ 1 - 4
Rx.NET/Source/src/System.Reactive/Internal/StopwatchImpl.cs

@@ -20,9 +20,6 @@ namespace System.Reactive.Concurrency
             _sw = Stopwatch.StartNew();
             _sw = Stopwatch.StartNew();
         }
         }
 
 
-        public TimeSpan Elapsed
-        {
-            get { return _sw.Elapsed; }
-        }
+        public TimeSpan Elapsed => _sw.Elapsed;
     }
     }
 }
 }

+ 0 - 4
Rx.NET/Source/src/System.Reactive/Internal/SynchronizationContextExtensions.cs

@@ -2,10 +2,6 @@
 // The .NET Foundation licenses this file to you under the Apache 2.0 License.
 // The .NET Foundation licenses this file to you under the Apache 2.0 License.
 // See the LICENSE file in the project root for more information. 
 // See the LICENSE file in the project root for more information. 
 
 
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
 using System.Threading;
 using System.Threading;
 
 
 namespace System.Reactive.Concurrency
 namespace System.Reactive.Concurrency

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Internal/SynchronizedObserver.cs

@@ -4,7 +4,7 @@
 
 
 namespace System.Reactive
 namespace System.Reactive
 {
 {
-    internal class SynchronizedObserver<T> : ObserverBase<T>
+    internal sealed class SynchronizedObserver<T> : ObserverBase<T>
     {
     {
         private readonly object _gate;
         private readonly object _gate;
         private readonly IObserver<T> _observer;
         private readonly IObserver<T> _observer;

+ 1 - 4
Rx.NET/Source/src/System.Reactive/Internal/SystemClock.Default.cs

@@ -17,10 +17,7 @@ namespace System.Reactive.PlatformServices
         /// <summary>
         /// <summary>
         /// Gets the current time.
         /// Gets the current time.
         /// </summary>
         /// </summary>
-        public DateTimeOffset UtcNow
-        {
-            get { return DateTimeOffset.UtcNow; }
-        }
+        public DateTimeOffset UtcNow => DateTimeOffset.UtcNow;
     }
     }
 
 
     internal class DefaultSystemClockMonitor : PeriodicTimerSystemClockMonitor
     internal class DefaultSystemClockMonitor : PeriodicTimerSystemClockMonitor

+ 3 - 6
Rx.NET/Source/src/System.Reactive/Internal/SystemClock.cs

@@ -29,10 +29,7 @@ namespace System.Reactive.PlatformServices
         /// <summary>
         /// <summary>
         /// Gets the local system clock time.
         /// Gets the local system clock time.
         /// </summary>
         /// </summary>
-        public static DateTimeOffset UtcNow
-        {
-            get { return s_serviceSystemClock.Value.UtcNow; }
-        }
+        public static DateTimeOffset UtcNow => s_serviceSystemClock.Value.UtcNow;
 
 
         /// <summary>
         /// <summary>
         /// Adds a reference to the system clock monitor, causing it to be sending notifications.
         /// Adds a reference to the system clock monitor, causing it to be sending notifications.
@@ -220,11 +217,11 @@ namespace System.Reactive.PlatformServices
         /// <summary>
         /// <summary>
         /// Gets the time before the system clock changed, or DateTimeOffset.MinValue if not known.
         /// Gets the time before the system clock changed, or DateTimeOffset.MinValue if not known.
         /// </summary>
         /// </summary>
-        public DateTimeOffset OldTime { get; private set; }
+        public DateTimeOffset OldTime { get; }
 
 
         /// <summary>
         /// <summary>
         /// Gets the time after the system clock changed, or DateTimeOffset.MaxValue if not known.
         /// Gets the time after the system clock changed, or DateTimeOffset.MaxValue if not known.
         /// </summary>
         /// </summary>
-        public DateTimeOffset NewTime { get; private set; }
+        public DateTimeOffset NewTime { get; }
     }
     }
 }
 }

+ 7 - 5
Rx.NET/Source/src/System.Reactive/Internal/TailRecursiveSink.cs

@@ -8,7 +8,7 @@ using System.Reactive.Disposables;
 
 
 namespace System.Reactive
 namespace System.Reactive
 {
 {
-    abstract class TailRecursiveSink<TSource> : Sink<TSource>, IObserver<TSource>
+    internal abstract class TailRecursiveSink<TSource> : Sink<TSource>, IObserver<TSource>
     {
     {
         public TailRecursiveSink(IObserver<TSource> observer, IDisposable cancel)
         public TailRecursiveSink(IObserver<TSource> observer, IDisposable cancel)
             : base(observer, cancel)
             : base(observer, cancel)
@@ -69,7 +69,9 @@ namespace System.Reactive
                 {
                 {
                     hasNext = e.MoveNext();
                     hasNext = e.MoveNext();
                     if (hasNext)
                     if (hasNext)
+                    {
                         current = e.Current;
                         current = e.Current;
+                    }
                 }
                 }
                 catch (Exception ex)
                 catch (Exception ex)
                 {
                 {
@@ -81,7 +83,7 @@ namespace System.Reactive
                     // enumerating to find the next observable sequence. Therefore,
                     // enumerating to find the next observable sequence. Therefore,
                     // we feed those errors directly to the observer.
                     // we feed those errors directly to the observer.
                     //
                     //
-                    base._observer.OnError(ex);
+                    _observer.OnError(ex);
                     base.Dispose();
                     base.Dispose();
                     return;
                     return;
                 }
                 }
@@ -188,7 +190,7 @@ namespace System.Reactive
                 // enumerating to find the next observable sequence. Therefore,
                 // enumerating to find the next observable sequence. Therefore,
                 // we feed those errors directly to the observer.
                 // we feed those errors directly to the observer.
                 //
                 //
-                base._observer.OnError(exception);
+                _observer.OnError(exception);
                 base.Dispose();
                 base.Dispose();
 
 
                 result = null;
                 result = null;
@@ -202,13 +204,13 @@ namespace System.Reactive
 
 
         protected virtual void Done()
         protected virtual void Done()
         {
         {
-            base._observer.OnCompleted();
+            _observer.OnCompleted();
             base.Dispose();
             base.Dispose();
         }
         }
 
 
         protected virtual bool Fail(Exception error)
         protected virtual bool Fail(Exception error)
         {
         {
-            base._observer.OnError(error);
+            _observer.OnError(error);
             base.Dispose();
             base.Dispose();
 
 
             return false;
             return false;

+ 28 - 30
Rx.NET/Source/src/System.Reactive/Platforms/Windows/Concurrency/CoreDispatcherScheduler.cs

@@ -13,7 +13,7 @@ using Windows.UI.Xaml;
 namespace System.Reactive.Concurrency
 namespace System.Reactive.Concurrency
 {
 {
     /// <summary>
     /// <summary>
-    /// Represents an object that schedules units of work on a Windows.UI.Core.CoreDispatcher.
+    /// Represents an object that schedules units of work on a <see cref="Windows.UI.Core.CoreDispatcher"/>.
     /// </summary>
     /// </summary>
     /// <remarks>
     /// <remarks>
     /// This scheduler type is typically used indirectly through the <see cref="System.Reactive.Linq.DispatcherObservable.ObserveOnDispatcher{TSource}(IObservable{TSource})"/> and <see cref="System.Reactive.Linq.DispatcherObservable.SubscribeOnDispatcher{TSource}(IObservable{TSource})"/> methods that use the current Dispatcher.
     /// This scheduler type is typically used indirectly through the <see cref="System.Reactive.Linq.DispatcherObservable.ObserveOnDispatcher{TSource}(IObservable{TSource})"/> and <see cref="System.Reactive.Linq.DispatcherObservable.SubscribeOnDispatcher{TSource}(IObservable{TSource})"/> methods that use the current Dispatcher.
@@ -21,40 +21,37 @@ namespace System.Reactive.Concurrency
     [CLSCompliant(false)]
     [CLSCompliant(false)]
     public sealed class CoreDispatcherScheduler : LocalScheduler, ISchedulerPeriodic
     public sealed class CoreDispatcherScheduler : LocalScheduler, ISchedulerPeriodic
     {
     {
-        private readonly CoreDispatcher _dispatcher;
-        private readonly CoreDispatcherPriority _priority;
-
         /// <summary>
         /// <summary>
-        /// Constructs a CoreDispatcherScheduler that schedules units of work on the given Windows.UI.Core.CoreDispatcher.
+        /// Constructs a <see cref="CoreDispatcherScheduler"/> that schedules units of work on the given <see cref="Windows.UI.Core.CoreDispatcher"/>.
         /// </summary>
         /// </summary>
         /// <param name="dispatcher">Dispatcher to schedule work on.</param>
         /// <param name="dispatcher">Dispatcher to schedule work on.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="dispatcher"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="dispatcher"/> is <c>null</c>.</exception>
         public CoreDispatcherScheduler(CoreDispatcher dispatcher)
         public CoreDispatcherScheduler(CoreDispatcher dispatcher)
         {
         {
             if (dispatcher == null)
             if (dispatcher == null)
                 throw new ArgumentNullException(nameof(dispatcher));
                 throw new ArgumentNullException(nameof(dispatcher));
 
 
-            _dispatcher = dispatcher;
-            _priority = CoreDispatcherPriority.Normal;
+            Dispatcher = dispatcher;
+            Priority = CoreDispatcherPriority.Normal;
         }
         }
 
 
         /// <summary>
         /// <summary>
-        /// Constructs a CoreDispatcherScheduler that schedules units of work on the given Windows.UI.Core.CoreDispatcher with the given priority.
+        /// Constructs a <see cref="CoreDispatcherScheduler"/> that schedules units of work on the given <see cref="Windows.UI.Core.CoreDispatcher"/> with the given priority.
         /// </summary>
         /// </summary>
         /// <param name="dispatcher">Dispatcher to schedule work on.</param>
         /// <param name="dispatcher">Dispatcher to schedule work on.</param>
         /// <param name="priority">Priority for scheduled units of work.</param>
         /// <param name="priority">Priority for scheduled units of work.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="dispatcher"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="dispatcher"/> is <c>null</c>.</exception>
         public CoreDispatcherScheduler(CoreDispatcher dispatcher, CoreDispatcherPriority priority)
         public CoreDispatcherScheduler(CoreDispatcher dispatcher, CoreDispatcherPriority priority)
         {
         {
             if (dispatcher == null)
             if (dispatcher == null)
                 throw new ArgumentNullException(nameof(dispatcher));
                 throw new ArgumentNullException(nameof(dispatcher));
 
 
-            _dispatcher = dispatcher;
-            _priority = priority;
+            Dispatcher = dispatcher;
+            Priority = priority;
         }
         }
 
 
         /// <summary>
         /// <summary>
-        /// Gets the scheduler that schedules work on the Windows.UI.Core.CoreDispatcher associated with the current Window.
+        /// Gets the scheduler that schedules work on the <see cref="Windows.UI.Core.CoreDispatcher"/> associated with the current Window.
         /// </summary>
         /// </summary>
         public static CoreDispatcherScheduler Current
         public static CoreDispatcherScheduler Current
         {
         {
@@ -69,20 +66,14 @@ namespace System.Reactive.Concurrency
         }
         }
 
 
         /// <summary>
         /// <summary>
-        /// Gets the Windows.UI.Core.CoreDispatcher associated with the CoreDispatcherScheduler.
+        /// Gets the <see cref="Windows.UI.Core.CoreDispatcher"/> associated with the <see cref="CoreDispatcherScheduler"/>.
         /// </summary>
         /// </summary>
-        public CoreDispatcher Dispatcher
-        {
-            get { return _dispatcher; }
-        }
+        public CoreDispatcher Dispatcher { get; }
 
 
         /// <summary>
         /// <summary>
         /// Gets the priority at which work is scheduled.
         /// Gets the priority at which work is scheduled.
         /// </summary>
         /// </summary>
-        public CoreDispatcherPriority Priority
-        {
-            get { return _priority; }
-        }
+        public CoreDispatcherPriority Priority { get; }
 
 
         /// <summary>
         /// <summary>
         /// Schedules an action to be executed on the dispatcher.
         /// Schedules an action to be executed on the dispatcher.
@@ -91,7 +82,7 @@ namespace System.Reactive.Concurrency
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public override IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
         public override IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
         {
         {
             if (action == null)
             if (action == null)
@@ -99,7 +90,7 @@ namespace System.Reactive.Concurrency
 
 
             var d = new SingleAssignmentDisposable();
             var d = new SingleAssignmentDisposable();
 
 
-            var res = _dispatcher.RunAsync(_priority, () =>
+            var res = Dispatcher.RunAsync(Priority, () =>
             {
             {
                 if (!d.IsDisposed)
                 if (!d.IsDisposed)
                 {
                 {
@@ -140,14 +131,14 @@ namespace System.Reactive.Concurrency
         }
         }
 
 
         /// <summary>
         /// <summary>
-        /// Schedules an action to be executed after dueTime on the dispatcher, using a Windows.UI.Xaml.DispatcherTimer object.
+        /// Schedules an action to be executed after <paramref name="dueTime"/> on the dispatcher, using a <see cref="Windows.UI.Xaml.DispatcherTimer"/> object.
         /// </summary>
         /// </summary>
         /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
         /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public override IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
         public override IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
         {
         {
             if (action == null)
             if (action == null)
@@ -155,8 +146,15 @@ namespace System.Reactive.Concurrency
 
 
             var dt = Scheduler.Normalize(dueTime);
             var dt = Scheduler.Normalize(dueTime);
             if (dt.Ticks == 0)
             if (dt.Ticks == 0)
+            {
                 return Schedule(state, action);
                 return Schedule(state, action);
+            }
 
 
+            return ScheduleSlow(state, dt, action);
+        }
+
+        private IDisposable ScheduleSlow<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
+        {
             var d = new MultipleAssignmentDisposable();
             var d = new MultipleAssignmentDisposable();
 
 
             var timer = new DispatcherTimer();
             var timer = new DispatcherTimer();
@@ -178,7 +176,7 @@ namespace System.Reactive.Concurrency
                 }
                 }
             };
             };
 
 
-            timer.Interval = dt;
+            timer.Interval = dueTime;
             timer.Start();
             timer.Start();
 
 
             d.Disposable = Disposable.Create(() =>
             d.Disposable = Disposable.Create(() =>
@@ -195,15 +193,15 @@ namespace System.Reactive.Concurrency
         }
         }
 
 
         /// <summary>
         /// <summary>
-        /// Schedules a periodic piece of work on the dispatcher, using a Windows.UI.Xaml.DispatcherTimer object.
+        /// Schedules a periodic piece of work on the dispatcher, using a <see cref="Windows.UI.Xaml.DispatcherTimer"/> object.
         /// </summary>
         /// </summary>
         /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
         /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
         /// <param name="state">Initial state passed to the action upon the first iteration.</param>
         /// <param name="state">Initial state passed to the action upon the first iteration.</param>
         /// <param name="period">Period for running the work periodically.</param>
         /// <param name="period">Period for running the work periodically.</param>
         /// <param name="action">Action to be executed, potentially updating the state.</param>
         /// <param name="action">Action to be executed, potentially updating the state.</param>
         /// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
-        /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than TimeSpan.Zero.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
+        /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than <see cref="TimeSpan.Zero"/>.</exception>
         public IDisposable SchedulePeriodic<TState>(TState state, TimeSpan period, Func<TState, TState> action)
         public IDisposable SchedulePeriodic<TState>(TState state, TimeSpan period, Func<TState, TState> action)
         {
         {
             //
             //

+ 35 - 52
Rx.NET/Source/src/System.Reactive/Platforms/Windows/Concurrency/DispatcherScheduler.cs

@@ -20,16 +20,7 @@ namespace System.Reactive.Concurrency
         /// Gets the scheduler that schedules work on the current <see cref="System.Windows.Threading.Dispatcher"/>.
         /// Gets the scheduler that schedules work on the current <see cref="System.Windows.Threading.Dispatcher"/>.
         /// </summary>
         /// </summary>
         [Obsolete(Constants_WindowsThreading.OBSOLETE_INSTANCE_PROPERTY)]
         [Obsolete(Constants_WindowsThreading.OBSOLETE_INSTANCE_PROPERTY)]
-        public static DispatcherScheduler Instance
-        {
-            get
-            {
-                return new DispatcherScheduler(
-
-                    System.Windows.Threading.Dispatcher.CurrentDispatcher
-                );
-            }
-        }
+        public static DispatcherScheduler Instance => new DispatcherScheduler(System.Windows.Threading.Dispatcher.CurrentDispatcher);
 
 
         /// <summary>
         /// <summary>
         /// Gets the scheduler that schedules work on the <see cref="System.Windows.Threading.Dispatcher"/> for the current thread.
         /// Gets the scheduler that schedules work on the <see cref="System.Windows.Threading.Dispatcher"/> for the current thread.
@@ -43,61 +34,48 @@ namespace System.Reactive.Concurrency
                     throw new InvalidOperationException(Strings_WindowsThreading.NO_DISPATCHER_CURRENT_THREAD);
                     throw new InvalidOperationException(Strings_WindowsThreading.NO_DISPATCHER_CURRENT_THREAD);
 
 
                 return new DispatcherScheduler(dispatcher);
                 return new DispatcherScheduler(dispatcher);
-
             }
             }
         }
         }
 
 
-        System.Windows.Threading.Dispatcher _dispatcher;
-        System.Windows.Threading.DispatcherPriority _priority;
-
-
         /// <summary>
         /// <summary>
-        /// Constructs a DispatcherScheduler that schedules units of work on the given <see cref="System.Windows.Threading.Dispatcher"/>.
+        /// Constructs a <see cref="DispatcherScheduler"/> that schedules units of work on the given <see cref="System.Windows.Threading.Dispatcher"/>.
         /// </summary>
         /// </summary>
-        /// <param name="dispatcher">Dispatcher to schedule work on.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="dispatcher"/> is null.</exception>
+        /// <param name="dispatcher"><see cref="DispatcherScheduler"/> to schedule work on.</param>
+        /// <exception cref="ArgumentNullException"><paramref name="dispatcher"/> is <c>null</c>.</exception>
         public DispatcherScheduler(System.Windows.Threading.Dispatcher dispatcher)
         public DispatcherScheduler(System.Windows.Threading.Dispatcher dispatcher)
         {
         {
             if (dispatcher == null)
             if (dispatcher == null)
                 throw new ArgumentNullException(nameof(dispatcher));
                 throw new ArgumentNullException(nameof(dispatcher));
 
 
-            _dispatcher = dispatcher;
-            _priority = Windows.Threading.DispatcherPriority.Normal;
+            Dispatcher = dispatcher;
+            Priority = Windows.Threading.DispatcherPriority.Normal;
 
 
         }
         }
         
         
         /// <summary>
         /// <summary>
-        /// Constructs a DispatcherScheduler that schedules units of work on the given <see cref="System.Windows.Threading.Dispatcher"/> at the given priority.
+        /// Constructs a <see cref="DispatcherScheduler"/> that schedules units of work on the given <see cref="System.Windows.Threading.Dispatcher"/> at the given priority.
         /// </summary>
         /// </summary>
-        /// <param name="dispatcher">Dispatcher to schedule work on.</param>
+        /// <param name="dispatcher"><see cref="DispatcherScheduler"/> to schedule work on.</param>
         /// <param name="priority">Priority at which units of work are scheduled.</param>
         /// <param name="priority">Priority at which units of work are scheduled.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="dispatcher"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="dispatcher"/> is <c>null</c>.</exception>
         public DispatcherScheduler(System.Windows.Threading.Dispatcher dispatcher, System.Windows.Threading.DispatcherPriority priority)
         public DispatcherScheduler(System.Windows.Threading.Dispatcher dispatcher, System.Windows.Threading.DispatcherPriority priority)
         {
         {
             if (dispatcher == null)
             if (dispatcher == null)
                 throw new ArgumentNullException(nameof(dispatcher));
                 throw new ArgumentNullException(nameof(dispatcher));
 
 
-            _dispatcher = dispatcher;
-            _priority = priority;
+            Dispatcher = dispatcher;
+            Priority = priority;
         }
         }
 
 
-
         /// <summary>
         /// <summary>
-        /// Gets the <see cref="System.Windows.Threading.Dispatcher"/> associated with the DispatcherScheduler.
+        /// Gets the <see cref="System.Windows.Threading.Dispatcher"/> associated with the <see cref="DispatcherScheduler"/>.
         /// </summary>
         /// </summary>
-        public System.Windows.Threading.Dispatcher Dispatcher
-        {
-            get { return _dispatcher; }
-        }
+        public System.Windows.Threading.Dispatcher Dispatcher { get; }
         
         
         /// <summary>
         /// <summary>
         /// Gets the priority at which work items will be dispatched.
         /// Gets the priority at which work items will be dispatched.
         /// </summary>
         /// </summary>
-        public System.Windows.Threading.DispatcherPriority Priority
-        {
-            get { return _priority; }
-        }
-
+        public System.Windows.Threading.DispatcherPriority Priority { get; }
 
 
         /// <summary>
         /// <summary>
         /// Schedules an action to be executed on the dispatcher.
         /// Schedules an action to be executed on the dispatcher.
@@ -106,7 +84,7 @@ namespace System.Reactive.Concurrency
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public override IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
         public override IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
         {
         {
             if (action == null)
             if (action == null)
@@ -114,27 +92,29 @@ namespace System.Reactive.Concurrency
 
 
             var d = new SingleAssignmentDisposable();
             var d = new SingleAssignmentDisposable();
 
 
-            _dispatcher.BeginInvoke(
+            Dispatcher.BeginInvoke(
                 new Action(() =>
                 new Action(() =>
                 {
                 {
                     if (!d.IsDisposed)
                     if (!d.IsDisposed)
+                    {
                         d.Disposable = action(this, state);
                         d.Disposable = action(this, state);
-                })
-                , _priority
+                    }
+                }),
+                Priority
             );
             );
 
 
             return d;
             return d;
         }
         }
 
 
         /// <summary>
         /// <summary>
-        /// Schedules an action to be executed after dueTime on the dispatcher, using a <see cref="System.Windows.Threading.DispatcherTimer"/> object.
+        /// Schedules an action to be executed after <paramref name="dueTime"/> on the dispatcher, using a <see cref="System.Windows.Threading.DispatcherTimer"/> object.
         /// </summary>
         /// </summary>
         /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
         /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="state">State passed to the action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="action">Action to be executed.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <param name="dueTime">Relative time after which to execute the action.</param>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
         public override IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
         public override IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
         {
         {
             if (action == null)
             if (action == null)
@@ -142,13 +122,18 @@ namespace System.Reactive.Concurrency
 
 
             var dt = Scheduler.Normalize(dueTime);
             var dt = Scheduler.Normalize(dueTime);
             if (dt.Ticks == 0)
             if (dt.Ticks == 0)
+            {
                 return Schedule(state, action);
                 return Schedule(state, action);
+            }
+
+            return ScheduleSlow(state, dt, action);
+        }
 
 
+        private IDisposable ScheduleSlow<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
+        {
             var d = new MultipleAssignmentDisposable();
             var d = new MultipleAssignmentDisposable();
 
 
-            var timer = new System.Windows.Threading.DispatcherTimer(
-                _priority, _dispatcher
-            );
+            var timer = new System.Windows.Threading.DispatcherTimer(Priority, Dispatcher);
 
 
             timer.Tick += (s, e) =>
             timer.Tick += (s, e) =>
             {
             {
@@ -167,7 +152,7 @@ namespace System.Reactive.Concurrency
                 }
                 }
             };
             };
 
 
-            timer.Interval = dt;
+            timer.Interval = dueTime;
             timer.Start();
             timer.Start();
 
 
             d.Disposable = Disposable.Create(() =>
             d.Disposable = Disposable.Create(() =>
@@ -191,8 +176,8 @@ namespace System.Reactive.Concurrency
         /// <param name="period">Period for running the work periodically.</param>
         /// <param name="period">Period for running the work periodically.</param>
         /// <param name="action">Action to be executed, potentially updating the state.</param>
         /// <param name="action">Action to be executed, potentially updating the state.</param>
         /// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns>
         /// <returns>The disposable object used to cancel the scheduled recurring action (best effort).</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="action"/> is null.</exception>
-        /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than TimeSpan.Zero.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="action"/> is <c>null</c>.</exception>
+        /// <exception cref="ArgumentOutOfRangeException"><paramref name="period"/> is less than <see cref="TimeSpan.Zero"/>.</exception>
         public IDisposable SchedulePeriodic<TState>(TState state, TimeSpan period, Func<TState, TState> action)
         public IDisposable SchedulePeriodic<TState>(TState state, TimeSpan period, Func<TState, TState> action)
         {
         {
             if (period < TimeSpan.Zero)
             if (period < TimeSpan.Zero)
@@ -200,9 +185,7 @@ namespace System.Reactive.Concurrency
             if (action == null)
             if (action == null)
                 throw new ArgumentNullException(nameof(action));
                 throw new ArgumentNullException(nameof(action));
 
 
-            var timer = new System.Windows.Threading.DispatcherTimer(
-                _priority, _dispatcher
-            );
+            var timer = new System.Windows.Threading.DispatcherTimer(Priority, Dispatcher);
 
 
             var state1 = state;
             var state1 = state;
 
 
@@ -226,4 +209,4 @@ namespace System.Reactive.Concurrency
         }
         }
     }
     }
 }
 }
-#endif
+#endif

+ 21 - 28
Rx.NET/Source/src/System.Reactive/Subjects/AsyncSubject.cs

@@ -45,14 +45,7 @@ namespace System.Reactive.Subjects
         /// <summary>
         /// <summary>
         /// Indicates whether the subject has observers subscribed to it.
         /// Indicates whether the subject has observers subscribed to it.
         /// </summary>
         /// </summary>
-        public override bool HasObservers
-        {
-            get
-            {
-                var observers = _observers;
-                return observers != null && observers.Data.Length > 0;
-            }
-        }
+        public override bool HasObservers => _observers?.Data.Length > 0;
 
 
         /// <summary>
         /// <summary>
         /// Indicates whether the subject has been disposed.
         /// Indicates whether the subject has been disposed.
@@ -108,8 +101,12 @@ namespace System.Reactive.Subjects
                     }
                     }
                 }
                 }
                 else
                 else
+                {
                     foreach (var o in os)
                     foreach (var o in os)
+                    {
                         o.OnCompleted();
                         o.OnCompleted();
+                    }
+                }
             }
             }
         }
         }
 
 
@@ -117,7 +114,7 @@ namespace System.Reactive.Subjects
         /// Notifies all subscribed observers about the exception.
         /// Notifies all subscribed observers about the exception.
         /// </summary>
         /// </summary>
         /// <param name="error">The exception to send to all observers.</param>
         /// <param name="error">The exception to send to all observers.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="error"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="error"/> is <c>null</c>.</exception>
         public override void OnError(Exception error)
         public override void OnError(Exception error)
         {
         {
             if (error == null)
             if (error == null)
@@ -138,8 +135,12 @@ namespace System.Reactive.Subjects
             }
             }
 
 
             if (os != null)
             if (os != null)
+            {
                 foreach (var o in os)
                 foreach (var o in os)
+                {
                     o.OnError(error);
                     o.OnError(error);
+                }
+            }
         }
         }
 
 
         /// <summary>
         /// <summary>
@@ -169,7 +170,7 @@ namespace System.Reactive.Subjects
         /// </summary>
         /// </summary>
         /// <param name="observer">Observer to subscribe to the subject.</param>
         /// <param name="observer">Observer to subscribe to the subject.</param>
         /// <returns>Disposable object that can be used to unsubscribe the observer from the subject.</returns>
         /// <returns>Disposable object that can be used to unsubscribe the observer from the subject.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="observer"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="observer"/> is <c>null</c>.</exception>
         public override IDisposable Subscribe(IObserver<T> observer)
         public override IDisposable Subscribe(IObserver<T> observer)
         {
         {
             if (observer == null)
             if (observer == null)
@@ -211,7 +212,7 @@ namespace System.Reactive.Subjects
             return Disposable.Empty;
             return Disposable.Empty;
         }
         }
 
 
-        class Subscription : IDisposable
+        private sealed class Subscription : IDisposable
         {
         {
             private readonly AsyncSubject<T> _subject;
             private readonly AsyncSubject<T> _subject;
             private IObserver<T> _observer;
             private IObserver<T> _observer;
@@ -276,13 +277,13 @@ namespace System.Reactive.Subjects
         /// Specifies a callback action that will be invoked when the subject completes.
         /// Specifies a callback action that will be invoked when the subject completes.
         /// </summary>
         /// </summary>
         /// <param name="continuation">Callback action that will be invoked when the subject completes.</param>
         /// <param name="continuation">Callback action that will be invoked when the subject completes.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="continuation"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="continuation"/> is <c>null</c>.</exception>
         public void OnCompleted(Action continuation)
         public void OnCompleted(Action continuation)
         {
         {
             if (continuation == null)
             if (continuation == null)
                 throw new ArgumentNullException(nameof(continuation));
                 throw new ArgumentNullException(nameof(continuation));
 
 
-            OnCompleted(continuation, true);
+            OnCompleted(continuation, originalContext: true);
         }
         }
 
 
         private void OnCompleted(Action continuation, bool originalContext)
         private void OnCompleted(Action continuation, bool originalContext)
@@ -293,7 +294,7 @@ namespace System.Reactive.Subjects
             this.Subscribe/*Unsafe*/(new AwaitObserver(continuation, originalContext));
             this.Subscribe/*Unsafe*/(new AwaitObserver(continuation, originalContext));
         }
         }
 
 
-        class AwaitObserver : IObserver<T>
+        private sealed class AwaitObserver : IObserver<T>
         {
         {
             private readonly SynchronizationContext _context;
             private readonly SynchronizationContext _context;
             private readonly Action _callback;
             private readonly Action _callback;
@@ -302,23 +303,15 @@ namespace System.Reactive.Subjects
             {
             {
                 if (originalContext)
                 if (originalContext)
                     _context = SynchronizationContext.Current;
                     _context = SynchronizationContext.Current;
-                
+
                 _callback = callback;
                 _callback = callback;
             }
             }
 
 
-            public void OnCompleted()
-            {
-                InvokeOnOriginalContext();
-            }
+            public void OnCompleted() => InvokeOnOriginalContext();
 
 
-            public void OnError(Exception error)
-            {
-                InvokeOnOriginalContext();
-            }
+            public void OnError(Exception error) => InvokeOnOriginalContext();
 
 
-            public void OnNext(T value)
-            {
-            }
+            public void OnNext(T value) { }
 
 
             private void InvokeOnOriginalContext()
             private void InvokeOnOriginalContext()
             {
             {
@@ -355,8 +348,8 @@ namespace System.Reactive.Subjects
         {
         {
             if (!_isStopped)
             if (!_isStopped)
             {
             {
-                var e = new ManualResetEvent(false);
-                OnCompleted(() => e.Set(), false);
+                var e = new ManualResetEvent(initialState: false);
+                OnCompleted(() => e.Set(), originalContext: false);
                 e.WaitOne();
                 e.WaitOne();
             }
             }
 
 

+ 14 - 11
Rx.NET/Source/src/System.Reactive/Subjects/BehaviorSubject.cs

@@ -44,14 +44,7 @@ namespace System.Reactive.Subjects
         /// <summary>
         /// <summary>
         /// Indicates whether the subject has observers subscribed to it.
         /// Indicates whether the subject has observers subscribed to it.
         /// </summary>
         /// </summary>
-        public override bool HasObservers
-        {
-            get
-            {
-                var observers = _observers;
-                return observers != null && observers.Data.Length > 0;
-            }
-        }
+        public override bool HasObservers => _observers?.Data.Length > 0;
 
 
         /// <summary>
         /// <summary>
         /// Indicates whether the subject has been disposed.
         /// Indicates whether the subject has been disposed.
@@ -160,7 +153,9 @@ namespace System.Reactive.Subjects
             if (os != null)
             if (os != null)
             {
             {
                 foreach (var o in os)
                 foreach (var o in os)
+                {
                     o.OnCompleted();
                     o.OnCompleted();
+                }
             }
             }
         }
         }
 
 
@@ -168,7 +163,7 @@ namespace System.Reactive.Subjects
         /// Notifies all subscribed observers about the exception.
         /// Notifies all subscribed observers about the exception.
         /// </summary>
         /// </summary>
         /// <param name="error">The exception to send to all observers.</param>
         /// <param name="error">The exception to send to all observers.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="error"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="error"/> is <c>null</c>.</exception>
         public override void OnError(Exception error)
         public override void OnError(Exception error)
         {
         {
             if (error == null)
             if (error == null)
@@ -191,7 +186,9 @@ namespace System.Reactive.Subjects
             if (os != null)
             if (os != null)
             {
             {
                 foreach (var o in os)
                 foreach (var o in os)
+                {
                     o.OnError(error);
                     o.OnError(error);
+                }
             }
             }
         }
         }
 
 
@@ -216,7 +213,9 @@ namespace System.Reactive.Subjects
             if (os != null)
             if (os != null)
             {
             {
                 foreach (var o in os)
                 foreach (var o in os)
+                {
                     o.OnNext(value);
                     o.OnNext(value);
+                }
             }
             }
         }
         }
 
 
@@ -229,7 +228,7 @@ namespace System.Reactive.Subjects
         /// </summary>
         /// </summary>
         /// <param name="observer">Observer to subscribe to the subject.</param>
         /// <param name="observer">Observer to subscribe to the subject.</param>
         /// <returns>Disposable object that can be used to unsubscribe the observer from the subject.</returns>
         /// <returns>Disposable object that can be used to unsubscribe the observer from the subject.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="observer"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="observer"/> is <c>null</c>.</exception>
         public override IDisposable Subscribe(IObserver<T> observer)
         public override IDisposable Subscribe(IObserver<T> observer)
         {
         {
             if (observer == null)
             if (observer == null)
@@ -252,9 +251,13 @@ namespace System.Reactive.Subjects
             }
             }
 
 
             if (ex != null)
             if (ex != null)
+            {
                 observer.OnError(ex);
                 observer.OnError(ex);
+            }
             else
             else
+            {
                 observer.OnCompleted();
                 observer.OnCompleted();
+            }
 
 
             return Disposable.Empty;
             return Disposable.Empty;
         }
         }
@@ -285,7 +288,7 @@ namespace System.Reactive.Subjects
 
 
         #endregion
         #endregion
 
 
-        class Subscription : IDisposable
+        private sealed class Subscription : IDisposable
         {
         {
             private readonly BehaviorSubject<T> _subject;
             private readonly BehaviorSubject<T> _subject;
             private IObserver<T> _observer;
             private IObserver<T> _observer;

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

@@ -50,7 +50,7 @@ namespace System.Reactive.Subjects
             }
             }
         }
         }
 
 
-        class Connection : IDisposable
+        private sealed class Connection : IDisposable
         {
         {
             private readonly ConnectableObservable<TSource, TResult> _parent;
             private readonly ConnectableObservable<TSource, TResult> _parent;
             private IDisposable _subscription;
             private IDisposable _subscription;

+ 42 - 81
Rx.NET/Source/src/System.Reactive/Subjects/ReplaySubject.cs

@@ -41,7 +41,7 @@ namespace System.Reactive.Subjects
         /// Initializes a new instance of the <see cref="ReplaySubject{T}" /> class with the specified scheduler.
         /// Initializes a new instance of the <see cref="ReplaySubject{T}" /> class with the specified scheduler.
         /// </summary>
         /// </summary>
         /// <param name="scheduler">Scheduler the observers are invoked on.</param>
         /// <param name="scheduler">Scheduler the observers are invoked on.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is <c>null</c>.</exception>
         public ReplaySubject(IScheduler scheduler)
         public ReplaySubject(IScheduler scheduler)
         {
         {
             _implementation = new ReplayByTime(scheduler);
             _implementation = new ReplayByTime(scheduler);
@@ -77,7 +77,7 @@ namespace System.Reactive.Subjects
         /// </summary>
         /// </summary>
         /// <param name="bufferSize">Maximum element count of the replay buffer.</param>
         /// <param name="bufferSize">Maximum element count of the replay buffer.</param>
         /// <param name="scheduler">Scheduler the observers are invoked on.</param>
         /// <param name="scheduler">Scheduler the observers are invoked on.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is <c>null</c>.</exception>
         /// <exception cref="ArgumentOutOfRangeException"><paramref name="bufferSize"/> is less than zero.</exception>
         /// <exception cref="ArgumentOutOfRangeException"><paramref name="bufferSize"/> is less than zero.</exception>
         public ReplaySubject(int bufferSize, IScheduler scheduler)
         public ReplaySubject(int bufferSize, IScheduler scheduler)
         {
         {
@@ -92,7 +92,7 @@ namespace System.Reactive.Subjects
         /// Initializes a new instance of the <see cref="ReplaySubject{T}" /> class with the specified window.
         /// Initializes a new instance of the <see cref="ReplaySubject{T}" /> class with the specified window.
         /// </summary>
         /// </summary>
         /// <param name="window">Maximum time length of the replay buffer.</param>
         /// <param name="window">Maximum time length of the replay buffer.</param>
-        /// <exception cref="ArgumentOutOfRangeException"><paramref name="window"/> is less than TimeSpan.Zero.</exception>
+        /// <exception cref="ArgumentOutOfRangeException"><paramref name="window"/> is less than <see cref="TimeSpan.Zero"/>.</exception>
         public ReplaySubject(TimeSpan window)
         public ReplaySubject(TimeSpan window)
         {
         {
             _implementation = new ReplayByTime(window);
             _implementation = new ReplayByTime(window);
@@ -103,8 +103,8 @@ namespace System.Reactive.Subjects
         /// </summary>
         /// </summary>
         /// <param name="window">Maximum time length of the replay buffer.</param>
         /// <param name="window">Maximum time length of the replay buffer.</param>
         /// <param name="scheduler">Scheduler the observers are invoked on.</param>
         /// <param name="scheduler">Scheduler the observers are invoked on.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
-        /// <exception cref="ArgumentOutOfRangeException"><paramref name="window"/> is less than TimeSpan.Zero.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is <c>null</c>.</exception>
+        /// <exception cref="ArgumentOutOfRangeException"><paramref name="window"/> is less than <see cref="TimeSpan.Zero"/>.</exception>
         public ReplaySubject(TimeSpan window, IScheduler scheduler)
         public ReplaySubject(TimeSpan window, IScheduler scheduler)
         {
         {
             _implementation = new ReplayByTime(window, scheduler);
             _implementation = new ReplayByTime(window, scheduler);
@@ -119,7 +119,7 @@ namespace System.Reactive.Subjects
         /// </summary>
         /// </summary>
         /// <param name="bufferSize">Maximum element count of the replay buffer.</param>
         /// <param name="bufferSize">Maximum element count of the replay buffer.</param>
         /// <param name="window">Maximum time length of the replay buffer.</param>
         /// <param name="window">Maximum time length of the replay buffer.</param>
-        /// <exception cref="ArgumentOutOfRangeException"><paramref name="bufferSize"/> is less than zero. -or- <paramref name="window"/> is less than TimeSpan.Zero.</exception>
+        /// <exception cref="ArgumentOutOfRangeException"><paramref name="bufferSize"/> is less than zero. -or- <paramref name="window"/> is less than <see cref="TimeSpan.Zero"/>.</exception>
         public ReplaySubject(int bufferSize, TimeSpan window)
         public ReplaySubject(int bufferSize, TimeSpan window)
         {
         {
             _implementation = new ReplayByTime(bufferSize, window);
             _implementation = new ReplayByTime(bufferSize, window);
@@ -131,8 +131,8 @@ namespace System.Reactive.Subjects
         /// <param name="bufferSize">Maximum element count of the replay buffer.</param>
         /// <param name="bufferSize">Maximum element count of the replay buffer.</param>
         /// <param name="window">Maximum time length of the replay buffer.</param>
         /// <param name="window">Maximum time length of the replay buffer.</param>
         /// <param name="scheduler">Scheduler the observers are invoked on.</param>
         /// <param name="scheduler">Scheduler the observers are invoked on.</param>
-        /// <exception cref="ArgumentOutOfRangeException"><paramref name="bufferSize"/> is less than zero. -or- <paramref name="window"/> is less than TimeSpan.Zero.</exception>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
+        /// <exception cref="ArgumentOutOfRangeException"><paramref name="bufferSize"/> is less than zero. -or- <paramref name="window"/> is less than <see cref="TimeSpan.Zero"/>.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is <c>null</c>.</exception>
         public ReplaySubject(int bufferSize, TimeSpan window, IScheduler scheduler)
         public ReplaySubject(int bufferSize, TimeSpan window, IScheduler scheduler)
         {
         {
             _implementation = new ReplayByTime(bufferSize, window, scheduler);
             _implementation = new ReplayByTime(bufferSize, window, scheduler);
@@ -147,18 +147,12 @@ namespace System.Reactive.Subjects
         /// <summary>
         /// <summary>
         /// Indicates whether the subject has observers subscribed to it.
         /// Indicates whether the subject has observers subscribed to it.
         /// </summary>
         /// </summary>
-        public override bool HasObservers
-        {
-            get { return _implementation.HasObservers; }
-        }
+        public override bool HasObservers => _implementation.HasObservers;
 
 
         /// <summary>
         /// <summary>
         /// Indicates whether the subject has been disposed.
         /// Indicates whether the subject has been disposed.
         /// </summary>
         /// </summary>
-        public override bool IsDisposed
-        {
-            get { return _implementation.IsDisposed; }
-        }
+        public override bool IsDisposed => _implementation.IsDisposed;
 
 
         #endregion
         #endregion
 
 
@@ -170,16 +164,13 @@ namespace System.Reactive.Subjects
         /// Notifies all subscribed and future observers about the arrival of the specified element in the sequence.
         /// Notifies all subscribed and future observers about the arrival of the specified element in the sequence.
         /// </summary>
         /// </summary>
         /// <param name="value">The value to send to all observers.</param>
         /// <param name="value">The value to send to all observers.</param>
-        public override void OnNext(T value)
-        {
-            _implementation.OnNext(value);
-        }
+        public override void OnNext(T value) => _implementation.OnNext(value);
 
 
         /// <summary>
         /// <summary>
         /// Notifies all subscribed and future observers about the specified exception.
         /// Notifies all subscribed and future observers about the specified exception.
         /// </summary>
         /// </summary>
         /// <param name="error">The exception to send to all observers.</param>
         /// <param name="error">The exception to send to all observers.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="error"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="error"/> is <c>null</c>.</exception>
         public override void OnError(Exception error)
         public override void OnError(Exception error)
         {
         {
             if (error == null)
             if (error == null)
@@ -191,10 +182,7 @@ namespace System.Reactive.Subjects
         /// <summary>
         /// <summary>
         /// Notifies all subscribed and future observers about the end of the sequence.
         /// Notifies all subscribed and future observers about the end of the sequence.
         /// </summary>
         /// </summary>
-        public override void OnCompleted()
-        {
-            _implementation.OnCompleted();
-        }
+        public override void OnCompleted() => _implementation.OnCompleted();
 
 
         #endregion
         #endregion
 
 
@@ -205,7 +193,7 @@ namespace System.Reactive.Subjects
         /// </summary>
         /// </summary>
         /// <param name="observer">Observer to subscribe to the subject.</param>
         /// <param name="observer">Observer to subscribe to the subject.</param>
         /// <returns>Disposable object that can be used to unsubscribe the observer from the subject.</returns>
         /// <returns>Disposable object that can be used to unsubscribe the observer from the subject.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="observer"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="observer"/> is <c>null</c>.</exception>
         public override IDisposable Subscribe(IObserver<T> observer)
         public override IDisposable Subscribe(IObserver<T> observer)
         {
         {
             if (observer == null)
             if (observer == null)
@@ -221,10 +209,7 @@ namespace System.Reactive.Subjects
         /// <summary>
         /// <summary>
         /// Releases all resources used by the current instance of the <see cref="ReplaySubject{T}"/> class and unsubscribe all observers.
         /// Releases all resources used by the current instance of the <see cref="ReplaySubject{T}"/> class and unsubscribe all observers.
         /// </summary>
         /// </summary>
-        public override void Dispose()
-        {
-            _implementation.Dispose();
-        }
+        public override void Dispose() => _implementation.Dispose();
 
 
         #endregion
         #endregion
 
 
@@ -248,14 +233,7 @@ namespace System.Reactive.Subjects
                 _error = null;
                 _error = null;
             }
             }
 
 
-            public override bool HasObservers
-            {
-                get
-                {
-                    var observers = _observers;
-                    return observers != null && observers.Data.Length > 0;
-                }
-            }
+            public override bool HasObservers => _observers?.Data.Length > 0;
 
 
             public override bool IsDisposed
             public override bool IsDisposed
             {
             {
@@ -282,14 +260,18 @@ namespace System.Reactive.Subjects
 
 
                         o = _observers.Data;
                         o = _observers.Data;
                         foreach (var observer in o)
                         foreach (var observer in o)
+                        {
                             observer.OnNext(value);
                             observer.OnNext(value);
+                        }
                     }
                     }
                 }
                 }
 
 
                 if (o != null)
                 if (o != null)
                 {
                 {
                     foreach (var observer in o)
                     foreach (var observer in o)
+                    {
                         observer.EnsureActive();
                         observer.EnsureActive();
+                    }
                 }
                 }
             }
             }
 
 
@@ -308,7 +290,9 @@ namespace System.Reactive.Subjects
 
 
                         o = _observers.Data;
                         o = _observers.Data;
                         foreach (var observer in o)
                         foreach (var observer in o)
+                        {
                             observer.OnError(error);
                             observer.OnError(error);
+                        }
 
 
                         _observers = ImmutableList<IScheduledObserver<T>>.Empty;
                         _observers = ImmutableList<IScheduledObserver<T>>.Empty;
                     }
                     }
@@ -317,7 +301,9 @@ namespace System.Reactive.Subjects
                 if (o != null)
                 if (o != null)
                 {
                 {
                     foreach (var observer in o)
                     foreach (var observer in o)
+                    {
                         observer.EnsureActive();
                         observer.EnsureActive();
+                    }
                 }
                 }
             }
             }
 
 
@@ -335,7 +321,9 @@ namespace System.Reactive.Subjects
 
 
                         o = _observers.Data;
                         o = _observers.Data;
                         foreach (var observer in o)
                         foreach (var observer in o)
+                        {
                             observer.OnCompleted();
                             observer.OnCompleted();
+                        }
 
 
                         _observers = ImmutableList<IScheduledObserver<T>>.Empty;
                         _observers = ImmutableList<IScheduledObserver<T>>.Empty;
                     }
                     }
@@ -344,7 +332,9 @@ namespace System.Reactive.Subjects
                 if (o != null)
                 if (o != null)
                 {
                 {
                     foreach (var observer in o)
                     foreach (var observer in o)
+                    {
                         observer.EnsureActive();
                         observer.EnsureActive();
+                    }
                 }
                 }
             }
             }
 
 
@@ -443,46 +433,6 @@ namespace System.Reactive.Subjects
                 }
                 }
             }
             }
 
 
-#if NOTYET // TODO: Expose internal notifications similar to BehaviorSubject<T>.TryGetValue?
-
-            public bool TryGetNotifications(out IList<Notification<T>> notifications)
-            {
-                lock (_gate)
-                {
-                    if (_isDisposed)
-                    {
-                        notifications = null;
-                        return false;
-                    }
-                    else
-                    {
-                        var res = new List<Notification<T>>();
-
-                        var materializer = Observer.Create<T>(
-                            x => res.Add(Notification.CreateOnNext(x)),
-                            ex => res.Add(Notification.CreateOnError<T>(ex)),
-                            () => res.Add(Notification.CreateOnCompleted<T>())
-                        );
-
-                        Replay(materializer);
-
-                        if (_error != null)
-                        {
-                            materializer.OnError(_error);
-                        }
-                        else if (_isStopped)
-                        {
-                            materializer.OnCompleted();
-                        }
-
-                        notifications = res;
-                        return true;
-                    }
-                }
-            }
-
-#endif
-
             private sealed class Subscription : IDisposable
             private sealed class Subscription : IDisposable
             {
             {
                 private readonly ReplayBase _subject;
                 private readonly ReplayBase _subject;
@@ -580,7 +530,9 @@ namespace System.Reactive.Subjects
                 var n = _queue.Count;
                 var n = _queue.Count;
 
 
                 foreach (var item in _queue)
                 foreach (var item in _queue)
+                {
                     observer.OnNext(item.Value);
                     observer.OnNext(item.Value);
+                }
 
 
                 return n;
                 return n;
             }
             }
@@ -590,14 +542,19 @@ namespace System.Reactive.Subjects
                 var now = _stopwatch.Elapsed;
                 var now = _stopwatch.Elapsed;
 
 
                 while (_queue.Count > _bufferSize)
                 while (_queue.Count > _bufferSize)
+                {
                     _queue.Dequeue();
                     _queue.Dequeue();
+                }
+
                 while (_queue.Count > 0 && now.Subtract(_queue.Peek().Interval).CompareTo(_window) > 0)
                 while (_queue.Count > 0 && now.Subtract(_queue.Peek().Interval).CompareTo(_window) > 0)
+                {
                     _queue.Dequeue();
                     _queue.Dequeue();
+                }
             }
             }
         }
         }
 
 
         //
         //
-        // Below are the non-time based implementations. 
+        // Below are the non-time based implementations.
         // These removed the need for the scheduler indirection, SchedulerObservers, stopwatch, TimeInterval and ensuring the scheduled observers are active after each action.
         // These removed the need for the scheduler indirection, SchedulerObservers, stopwatch, TimeInterval and ensuring the scheduled observers are active after each action.
         // The ReplayOne implementation also removes the need to even have a queue.
         // The ReplayOne implementation also removes the need to even have a queue.
         //
         //
@@ -652,7 +609,9 @@ namespace System.Reactive.Subjects
             protected override void Trim()
             protected override void Trim()
             {
             {
                 while (_queue.Count > _bufferSize)
                 while (_queue.Count > _bufferSize)
+                {
                     _queue.Dequeue();
                     _queue.Dequeue();
+                }
             }
             }
         }
         }
 
 
@@ -703,7 +662,9 @@ namespace System.Reactive.Subjects
                 var n = _queue.Count;
                 var n = _queue.Count;
 
 
                 foreach (var item in _queue)
                 foreach (var item in _queue)
+                {
                     observer.OnNext(item);
                     observer.OnNext(item);
+                }
 
 
                 return n;
                 return n;
             }
             }
@@ -719,7 +680,7 @@ namespace System.Reactive.Subjects
     /// Specialized scheduled observer similar to a scheduled observer for the immediate scheduler.
     /// Specialized scheduled observer similar to a scheduled observer for the immediate scheduler.
     /// </summary>
     /// </summary>
     /// <typeparam name="T">Type of the elements processed by the observer.</typeparam>
     /// <typeparam name="T">Type of the elements processed by the observer.</typeparam>
-    class FastImmediateObserver<T> : IScheduledObserver<T>
+    internal sealed class FastImmediateObserver<T> : IScheduledObserver<T>
     {
     {
         /// <summary>
         /// <summary>
         /// Gate to control ownership transfer and protect data structures.
         /// Gate to control ownership transfer and protect data structures.
@@ -985,4 +946,4 @@ namespace System.Reactive.Subjects
             return Interlocked.Exchange(ref _observer, NopObserver<T>.Instance);
             return Interlocked.Exchange(ref _observer, NopObserver<T>.Instance);
         }
         }
     }
     }
-}
+}

+ 10 - 16
Rx.NET/Source/src/System.Reactive/Subjects/Subject.Extensions.cs

@@ -20,7 +20,7 @@ namespace System.Reactive.Subjects
         /// <param name="observer">The observer used to send messages to the subject.</param>
         /// <param name="observer">The observer used to send messages to the subject.</param>
         /// <param name="observable">The observable used to subscribe to messages sent from the subject.</param>
         /// <param name="observable">The observable used to subscribe to messages sent from the subject.</param>
         /// <returns>Subject implemented using the given observer and observable.</returns>
         /// <returns>Subject implemented using the given observer and observable.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="observer"/> or <paramref name="observable"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="observer"/> or <paramref name="observable"/> is <c>null</c>.</exception>
         public static ISubject<TSource, TResult> Create<TSource, TResult>(IObserver<TSource> observer, IObservable<TResult> observable)
         public static ISubject<TSource, TResult> Create<TSource, TResult>(IObserver<TSource> observer, IObservable<TResult> observable)
         {
         {
             if (observer == null)
             if (observer == null)
@@ -38,7 +38,7 @@ namespace System.Reactive.Subjects
         /// <param name="observer">The observer used to send messages to the subject.</param>
         /// <param name="observer">The observer used to send messages to the subject.</param>
         /// <param name="observable">The observable used to subscribe to messages sent from the subject.</param>
         /// <param name="observable">The observable used to subscribe to messages sent from the subject.</param>
         /// <returns>Subject implemented using the given observer and observable.</returns>
         /// <returns>Subject implemented using the given observer and observable.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="observer"/> or <paramref name="observable"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="observer"/> or <paramref name="observable"/> is <c>null</c>.</exception>
         public static ISubject<T> Create<T>(IObserver<T> observer, IObservable<T> observable)
         public static ISubject<T> Create<T>(IObserver<T> observer, IObservable<T> observable)
         {
         {
             if (observer == null)
             if (observer == null)
@@ -56,7 +56,7 @@ namespace System.Reactive.Subjects
         /// <typeparam name="TResult">The type of the elements produced by the subject.</typeparam>
         /// <typeparam name="TResult">The type of the elements produced by the subject.</typeparam>
         /// <param name="subject">The subject to synchronize.</param>
         /// <param name="subject">The subject to synchronize.</param>
         /// <returns>Subject whose messages are synchronized.</returns>
         /// <returns>Subject whose messages are synchronized.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="subject"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="subject"/> is <c>null</c>.</exception>
         public static ISubject<TSource, TResult> Synchronize<TSource, TResult>(ISubject<TSource, TResult> subject)
         public static ISubject<TSource, TResult> Synchronize<TSource, TResult>(ISubject<TSource, TResult> subject)
         {
         {
             if (subject == null)
             if (subject == null)
@@ -71,7 +71,7 @@ namespace System.Reactive.Subjects
         /// <typeparam name="TSource">The type of the elements received and produced by the subject.</typeparam>
         /// <typeparam name="TSource">The type of the elements received and produced by the subject.</typeparam>
         /// <param name="subject">The subject to synchronize.</param>
         /// <param name="subject">The subject to synchronize.</param>
         /// <returns>Subject whose messages are synchronized.</returns>
         /// <returns>Subject whose messages are synchronized.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="subject"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="subject"/> is <c>null</c>.</exception>
         public static ISubject<TSource> Synchronize<TSource>(ISubject<TSource> subject)
         public static ISubject<TSource> Synchronize<TSource>(ISubject<TSource> subject)
         {
         {
             if (subject == null)
             if (subject == null)
@@ -88,7 +88,7 @@ namespace System.Reactive.Subjects
         /// <param name="subject">The subject to synchronize.</param>
         /// <param name="subject">The subject to synchronize.</param>
         /// <param name="scheduler">Scheduler to notify observers on.</param>
         /// <param name="scheduler">Scheduler to notify observers on.</param>
         /// <returns>Subject whose messages are synchronized and whose observers are notified on the given scheduler.</returns>
         /// <returns>Subject whose messages are synchronized and whose observers are notified on the given scheduler.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="subject"/> or <paramref name="scheduler"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="subject"/> or <paramref name="scheduler"/> is <c>null</c>.</exception>
         public static ISubject<TSource, TResult> Synchronize<TSource, TResult>(ISubject<TSource, TResult> subject, IScheduler scheduler)
         public static ISubject<TSource, TResult> Synchronize<TSource, TResult>(ISubject<TSource, TResult> subject, IScheduler scheduler)
         {
         {
             if (subject == null)
             if (subject == null)
@@ -106,7 +106,7 @@ namespace System.Reactive.Subjects
         /// <param name="subject">The subject to synchronize.</param>
         /// <param name="subject">The subject to synchronize.</param>
         /// <param name="scheduler">Scheduler to notify observers on.</param>
         /// <param name="scheduler">Scheduler to notify observers on.</param>
         /// <returns>Subject whose messages are synchronized and whose observers are notified on the given scheduler.</returns>
         /// <returns>Subject whose messages are synchronized and whose observers are notified on the given scheduler.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="subject"/> or <paramref name="scheduler"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="subject"/> or <paramref name="scheduler"/> is <c>null</c>.</exception>
         public static ISubject<TSource> Synchronize<TSource>(ISubject<TSource> subject, IScheduler scheduler)
         public static ISubject<TSource> Synchronize<TSource>(ISubject<TSource> subject, IScheduler scheduler)
         {
         {
             if (subject == null)
             if (subject == null)
@@ -117,7 +117,7 @@ namespace System.Reactive.Subjects
             return new AnonymousSubject<TSource>(Observer.Synchronize(subject), subject.ObserveOn(scheduler));
             return new AnonymousSubject<TSource>(Observer.Synchronize(subject), subject.ObserveOn(scheduler));
         }
         }
 
 
-        class AnonymousSubject<T, U> : ISubject<T, U>
+        private class AnonymousSubject<T, U> : ISubject<T, U>
         {
         {
             private readonly IObserver<T> _observer;
             private readonly IObserver<T> _observer;
             private readonly IObservable<U> _observable;
             private readonly IObservable<U> _observable;
@@ -128,10 +128,7 @@ namespace System.Reactive.Subjects
                 _observable = observable;
                 _observable = observable;
             }
             }
 
 
-            public void OnCompleted()
-            {
-                _observer.OnCompleted();
-            }
+            public void OnCompleted() => _observer.OnCompleted();
 
 
             public void OnError(Exception error)
             public void OnError(Exception error)
             {
             {
@@ -141,10 +138,7 @@ namespace System.Reactive.Subjects
                 _observer.OnError(error);
                 _observer.OnError(error);
             }
             }
 
 
-            public void OnNext(T value)
-            {
-                _observer.OnNext(value);
-            }
+            public void OnNext(T value) => _observer.OnNext(value);
 
 
             public IDisposable Subscribe(IObserver<U> observer)
             public IDisposable Subscribe(IObserver<U> observer)
             {
             {
@@ -158,7 +152,7 @@ namespace System.Reactive.Subjects
             }
             }
         }
         }
 
 
-        class AnonymousSubject<T> : AnonymousSubject<T, T>, ISubject<T>
+        private sealed class AnonymousSubject<T> : AnonymousSubject<T, T>, ISubject<T>
         {
         {
             public AnonymousSubject(IObserver<T> observer, IObservable<T> observable)
             public AnonymousSubject(IObserver<T> observer, IObservable<T> observable)
                 : base(observer, observable)
                 : base(observer, observable)

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Subjects/Subject.cs

@@ -169,7 +169,7 @@ namespace System.Reactive.Subjects
             return new Subscription(this, observer);
             return new Subscription(this, observer);
         }
         }
 
 
-        class Subscription : IDisposable
+        private sealed class Subscription : IDisposable
         {
         {
             private Subject<T> _subject;
             private Subject<T> _subject;
             private IObserver<T> _observer;
             private IObserver<T> _observer;

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

@@ -5,7 +5,7 @@
 namespace System.Reactive.Subjects
 namespace System.Reactive.Subjects
 {
 {
     /// <summary>
     /// <summary>
-    /// Base calss for objects that are both an observable sequence as well as an observer.
+    /// Base class for objects that are both an observable sequence as well as an observer.
     /// </summary>
     /// </summary>
     /// <typeparam name="T">The type of the elements processed by the subject.</typeparam>
     /// <typeparam name="T">The type of the elements processed by the subject.</typeparam>
     public abstract class SubjectBase<T> : ISubject<T>, IDisposable
     public abstract class SubjectBase<T> : ISubject<T>, IDisposable
@@ -34,7 +34,7 @@ namespace System.Reactive.Subjects
         /// Notifies all subscribed observers about the specified exception.
         /// Notifies all subscribed observers about the specified exception.
         /// </summary>
         /// </summary>
         /// <param name="error">The exception to send to all currently subscribed observers.</param>
         /// <param name="error">The exception to send to all currently subscribed observers.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="error"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="error"/> is <c>null</c>.</exception>
         public abstract void OnError(Exception error);
         public abstract void OnError(Exception error);
 
 
         /// <summary>
         /// <summary>
@@ -48,7 +48,7 @@ namespace System.Reactive.Subjects
         /// </summary>
         /// </summary>
         /// <param name="observer">Observer to subscribe to the subject.</param>
         /// <param name="observer">Observer to subscribe to the subject.</param>
         /// <returns>Disposable object that can be used to unsubscribe the observer from the subject.</returns>
         /// <returns>Disposable object that can be used to unsubscribe the observer from the subject.</returns>
-        /// <exception cref="ArgumentNullException"><paramref name="observer"/> is null.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="observer"/> is <c>null</c>.</exception>
         public abstract IDisposable Subscribe(IObserver<T> observer);
         public abstract IDisposable Subscribe(IObserver<T> observer);
     }
     }
 }
 }