Ver código fonte

Merge pull request #380 from Reactive-Extensions/MiscInternalImprovements

Some improvements to internal types
Bart J.F. De Smet 8 anos atrás
pai
commit
83798145ef
32 arquivos alterados com 194 adições e 268 exclusões
  1. 5 10
      Rx.NET/Source/src/System.Reactive/Internal/AnonymousEnumerable.cs
  2. 1 1
      Rx.NET/Source/src/System.Reactive/Internal/AsyncLockObserver.cs
  3. 14 10
      Rx.NET/Source/src/System.Reactive/Internal/AutoDetachObserver.cs
  4. 3 3
      Rx.NET/Source/src/System.Reactive/Internal/BinaryObserver.cs
  5. 1 1
      Rx.NET/Source/src/System.Reactive/Internal/CheckedObserver.cs
  6. 4 14
      Rx.NET/Source/src/System.Reactive/Internal/ConcatSink.cs
  7. 2 2
      Rx.NET/Source/src/System.Reactive/Internal/Constants.cs
  8. 4 2
      Rx.NET/Source/src/System.Reactive/Internal/CurrentPlatformEnlightenmentProvider.cs
  9. 19 50
      Rx.NET/Source/src/System.Reactive/Internal/Either.Generic.cs
  10. 3 4
      Rx.NET/Source/src/System.Reactive/Internal/ExceptionServices.Default.cs
  11. 3 4
      Rx.NET/Source/src/System.Reactive/Internal/ExceptionServices.cs
  12. 3 4
      Rx.NET/Source/src/System.Reactive/Internal/ExceptionServicesImpl.cs
  13. 1 1
      Rx.NET/Source/src/System.Reactive/Internal/Helpers.cs
  14. 1 1
      Rx.NET/Source/src/System.Reactive/Internal/IConcatenatable.cs
  15. 1 1
      Rx.NET/Source/src/System.Reactive/Internal/IEvaluatableObservable.cs
  16. 10 8
      Rx.NET/Source/src/System.Reactive/Internal/ImmutableList.cs
  17. 24 36
      Rx.NET/Source/src/System.Reactive/Internal/Lookup.cs
  18. 19 26
      Rx.NET/Source/src/System.Reactive/Internal/Observers.cs
  19. 5 5
      Rx.NET/Source/src/System.Reactive/Internal/PlatformEnlightenmentProvider.cs
  20. 22 7
      Rx.NET/Source/src/System.Reactive/Internal/PriorityQueue.cs
  21. 3 3
      Rx.NET/Source/src/System.Reactive/Internal/Producer.cs
  22. 4 10
      Rx.NET/Source/src/System.Reactive/Internal/QueryServices.cs
  23. 11 18
      Rx.NET/Source/src/System.Reactive/Internal/ReflectionUtils.cs
  24. 7 1
      Rx.NET/Source/src/System.Reactive/Internal/SafeObserver.cs
  25. 7 11
      Rx.NET/Source/src/System.Reactive/Internal/ScheduledObserver.cs
  26. 4 11
      Rx.NET/Source/src/System.Reactive/Internal/Sink.cs
  27. 1 4
      Rx.NET/Source/src/System.Reactive/Internal/StopwatchImpl.cs
  28. 0 4
      Rx.NET/Source/src/System.Reactive/Internal/SynchronizationContextExtensions.cs
  29. 1 1
      Rx.NET/Source/src/System.Reactive/Internal/SynchronizedObserver.cs
  30. 1 4
      Rx.NET/Source/src/System.Reactive/Internal/SystemClock.Default.cs
  31. 3 6
      Rx.NET/Source/src/System.Reactive/Internal/SystemClock.cs
  32. 7 5
      Rx.NET/Source/src/System.Reactive/Internal/TailRecursiveSink.cs

+ 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.
 // See the LICENSE file in the project root for more information. 
 
+using System.Collections;
 using System.Collections.Generic;
 
 namespace System.Reactive
 {
     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)
         {
-            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
 {
-    internal class AsyncLockObserver<T> : ObserverBase<T>
+    internal sealed class AsyncLockObserver<T> : ObserverBase<T>
     {
         private readonly AsyncLock _gate;
         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
 {
-    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)
         {
-            this.observer = observer;
+            _observer = observer;
         }
 
         public IDisposable Disposable
         {
-            set { m.Disposable = value; }
+            set { _disposable.Disposable = value; }
         }
 
         protected override void OnNextCore(T value)
@@ -57,13 +57,15 @@ namespace System.Reactive
             var __noError = false;
             try
             {
-                observer.OnNext(value);
+                _observer.OnNext(value);
                 __noError = true;
             }
             finally
             {
                 if (!__noError)
+                {
                     Dispose();
+                }
             }
         }
 
@@ -71,7 +73,7 @@ namespace System.Reactive
         {
             try
             {
-                observer.OnError(exception);
+                _observer.OnError(exception);
             }
             finally
             {
@@ -83,7 +85,7 @@ namespace System.Reactive
         {
             try
             {
-                observer.OnCompleted();
+                _observer.OnCompleted();
             }
             finally
             {
@@ -96,7 +98,9 @@ namespace System.Reactive
             base.Dispose(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
 {
-    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)
         {
@@ -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)
         {

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

@@ -6,7 +6,7 @@ using System.Threading;
 
 namespace System.Reactive
 {
-    internal class CheckedObserver<T> : IObserver<T>
+    internal sealed class CheckedObserver<T> : IObserver<T>
     {
         private readonly IObserver<T> _observer;
         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
 {
-    abstract class ConcatSink<TSource> : TailRecursiveSink<TSource>
+    internal abstract class ConcatSink<TSource> : TailRecursiveSink<TSource>
     {
         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.
 
-    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.";
 
@@ -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.
 
-    class Constants_Linq
+    internal static class Constants_Linq
     {
 #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.";

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

@@ -24,7 +24,7 @@ namespace System.Reactive.PlatformServices
         /// </summary>
         /// <typeparam name="T">Service type.</typeparam>
         /// <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
         {
             var t = typeof(T);
@@ -94,7 +94,9 @@ namespace System.Reactive.PlatformServices
 
                     var dbg = Type.GetType(name, false);
                     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
 {
-    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 void Switch(Action<TLeft> caseLeft, Action<TRight> caseRight);
 
         public sealed class Left : Either<TLeft, TRight>, IEquatable<Left>
         {
-            public TLeft Value { get; private set; }
-
             public Left(TLeft 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)
             {
@@ -51,18 +39,13 @@ namespace System.Reactive
                     return true;
                 if (other == null)
                     return false;
+
                 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()
             {
@@ -72,22 +55,16 @@ namespace System.Reactive
 
         public sealed class Right : Either<TLeft, TRight>, IEquatable<Right>
         {
-            public TRight Value { get; private set; }
-
             public Right(TRight 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)
             {
@@ -95,23 +72,15 @@ namespace System.Reactive
                     return true;
                 if (other == null)
                     return false;
+
                 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.
 // See the LICENSE file in the project root for more information. 
 
+using System.Runtime.ExceptionServices;
+
 namespace System.Reactive.PlatformServices
 {
     //
@@ -11,9 +13,6 @@ namespace System.Reactive.PlatformServices
     //
     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);
 
-        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)
         {
             if (exception != null)
+            {
                 s_services.Value.Rethrow(exception);
+            }
         }
 
         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.
 // See the LICENSE file in the project root for more information. 
 
+using System.Runtime.ExceptionServices;
+
 namespace System.Reactive.PlatformServices
 {
     //
@@ -11,9 +13,6 @@ namespace System.Reactive.PlatformServices
     //
     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/Helpers.cs

@@ -42,4 +42,4 @@ namespace System.Reactive
         }
     }
 }
-#endif
+#endif

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

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

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

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

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

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

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

@@ -8,34 +8,30 @@ using System.Linq;
 
 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)
         {
-            d = new Dictionary<K, List<E>>(comparer);
+            _dictionary = new Dictionary<K, List<E>>(comparer);
         }
 
         public void Add(K key, E element)
         {
             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);
         }
 
-        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]
         {
@@ -43,7 +39,7 @@ namespace System.Reactive
             {
                 var list = default(List<E>);
 
-                if (!d.TryGetValue(key, out list))
+                if (!_dictionary.TryGetValue(key, out list))
                     return Enumerable.Empty<E>();
 
                 return Hide(list);
@@ -53,43 +49,35 @@ namespace System.Reactive
         private IEnumerable<E> Hide(List<E> elements)
         {
             foreach (var x in elements)
+            {
                 yield return x;
+            }
         }
 
         public IEnumerator<IGrouping<K, E>> GetEnumerator()
         {
-            foreach (var kv in d)
+            foreach (var kv in _dictionary)
+            {
                 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
 {
-    internal class NopObserver<T> : IObserver<T>
+    internal sealed class NopObserver<T> : IObserver<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 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>();
 
@@ -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;
 
@@ -72,31 +60,36 @@ namespace System.Reactive
         public void OnCompleted()
         {
             foreach (var observer in _observers.Data)
+            {
                 observer.OnCompleted();
+            }
         }
 
         public void OnError(Exception error)
         {
             foreach (var observer in _observers.Data)
+            {
                 observer.OnError(error);
+            }
         }
 
         public void OnNext(T value)
         {
             foreach (var observer in _observers.Data)
+            {
                 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)
         {
             var i = Array.IndexOf(_observers.Data, observer);
             if (i < 0)
+            {
                 return this;
+            }
 
             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;
             }
+
             set
             {
-                if (value == null) throw new ArgumentNullException(nameof(value));
+                if (value == null)
+                    throw new ArgumentNullException(nameof(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
 {
-    internal class PriorityQueue<T> where T : IComparable<T>
+    internal sealed class PriorityQueue<T> where T : IComparable<T>
     {
         private static long _count = long.MinValue;
         private IndexedItem[] _items;
@@ -32,10 +32,15 @@ namespace System.Reactive
         private void Percolate(int index)
         {
             if (index >= _size || index < 0)
+            {
                 return;
+            }
+
             var parent = (index - 1) / 2;
             if (parent < 0 || parent == index)
+            {
                 return;
+            }
 
             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)
         {
             if (index >= _size || index < 0)
+            {
                 return;
+            }
 
             var left = 2 * index + 1;
             var right = 2 * index + 2;
             var first = index;
 
             if (left < _size && IsHigherPriority(left, first))
+            {
                 first = left;
+            }
+
             if (right < _size && IsHigherPriority(right, first))
+            {
                 first = right;
+            }
+
             if (first != 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()
         {
@@ -87,7 +97,9 @@ namespace System.Reactive
         {
             _items[index] = _items[--_size];
             _items[_size] = default(IndexedItem);
+
             Heapify();
+
             if (_size < _items.Length / 4)
             {
                 var temp = _items;
@@ -131,7 +143,7 @@ namespace System.Reactive
             return false;
         }
 
-        struct IndexedItem : IComparable<IndexedItem>
+        private struct IndexedItem : IComparable<IndexedItem>
         {
             public T Value;
             public long Id;
@@ -140,7 +152,10 @@ namespace System.Reactive
             {
                 var c = Value.CompareTo(other.Value);
                 if (c == 0)
+                {
                     c = Id.CompareTo(other.Id);
+                }
+
                 return c;
             }
         }

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

@@ -60,13 +60,13 @@ namespace System.Reactive
             }
             else
             {
-                state.subscription.Disposable = this.Run(state.observer, state.subscription, state.Assign);
+                state.subscription.Disposable = Run(state.observer, state.subscription, state.Assign);
             }
 
             return d;
         }
 
-        struct State
+        private struct State
         {
             public SingleAssignmentDisposable sink;
             public SingleAssignmentDisposable subscription;
@@ -95,4 +95,4 @@ namespace System.Reactive
         protected abstract IDisposable Run(IObserver<TSource> observer, IDisposable cancel, Action<IDisposable> setSink);
     }
 }
-#endif
+#endif

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

@@ -8,12 +8,9 @@ namespace System.Reactive.Linq
 {
     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()
         {
@@ -28,11 +25,8 @@ namespace System.Reactive.Linq
         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.
 // See the LICENSE file in the project root for more information. 
 
-using System;
 using System.Collections.Generic;
 using System.Globalization;
 using System.Reflection;
@@ -13,7 +12,7 @@ using System.Runtime.InteropServices.WindowsRuntime;
 
 namespace System.Reactive
 {
-    static class ReflectionUtils
+    internal static class ReflectionUtils
     {
         public static TDelegate CreateDelegate<TDelegate>(object o, MethodInfo method)
         {
@@ -111,13 +110,19 @@ namespace System.Reactive
 
                 var e = t.GetDeclaredEvent(name);
                 if (e != null)
+                {
                     return e;
+                }
 
                 foreach (var i in t.ImplementedInterfaces)
+                {
                     q.Enqueue(i.GetTypeInfo());
+                }
 
                 if (t.BaseType != null)
+                {
                     q.Enqueue(t.BaseType.GetTypeInfo());
+                }
             }
 
             return null;
@@ -127,25 +132,13 @@ namespace System.Reactive
         }
 
 #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
     }
 }

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

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

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

@@ -116,17 +116,16 @@ namespace System.Reactive
             }
         }
 
-        public void EnsureActive()
-        {
-            EnsureActive(1);
-        }
+        public void EnsureActive() => EnsureActive(1);
 
         public void EnsureActive(int n)
         {
             if (_longRunning != null)
             {
                 if (n > 0)
+                {
                     _dispatcherEvent.Release(n);
+                }
 
                 EnsureDispatcher();
             }
@@ -262,6 +261,7 @@ namespace System.Reactive
                 var nop = default(T);
                 while (_queue.TryDequeue(out nop))
                     ;
+
                 throw;
             }
 
@@ -395,7 +395,7 @@ namespace System.Reactive
     }
 #endif
 
-    class ObserveOnObserver<T> : ScheduledObserver<T>
+    internal sealed class ObserveOnObserver<T> : ScheduledObserver<T>
     {
         private IDisposable _cancel;
 
@@ -429,16 +429,12 @@ namespace System.Reactive
 
             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(int count);

+ 4 - 11
Rx.NET/Source/src/System.Reactive/Internal/Sink.cs

@@ -27,19 +27,12 @@ namespace System.Reactive
         {
             _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;
 
@@ -67,4 +60,4 @@ namespace System.Reactive
         }
     }
 }
-#endif
+#endif

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

@@ -20,9 +20,6 @@ namespace System.Reactive.Concurrency
             _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.
 // 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;
 
 namespace System.Reactive.Concurrency

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

@@ -4,7 +4,7 @@
 
 namespace System.Reactive
 {
-    internal class SynchronizedObserver<T> : ObserverBase<T>
+    internal sealed class SynchronizedObserver<T> : ObserverBase<T>
     {
         private readonly object _gate;
         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>
         /// Gets the current time.
         /// </summary>
-        public DateTimeOffset UtcNow
-        {
-            get { return DateTimeOffset.UtcNow; }
-        }
+        public DateTimeOffset UtcNow => DateTimeOffset.UtcNow;
     }
 
     internal class DefaultSystemClockMonitor : PeriodicTimerSystemClockMonitor

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

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

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

@@ -9,7 +9,7 @@ using System.Reactive.Disposables;
 
 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)
             : base(observer, cancel)
@@ -70,7 +70,9 @@ namespace System.Reactive
                 {
                     hasNext = e.MoveNext();
                     if (hasNext)
+                    {
                         current = e.Current;
+                    }
                 }
                 catch (Exception ex)
                 {
@@ -82,7 +84,7 @@ namespace System.Reactive
                     // enumerating to find the next observable sequence. Therefore,
                     // we feed those errors directly to the observer.
                     //
-                    base._observer.OnError(ex);
+                    _observer.OnError(ex);
                     base.Dispose();
                     return;
                 }
@@ -189,7 +191,7 @@ namespace System.Reactive
                 // enumerating to find the next observable sequence. Therefore,
                 // we feed those errors directly to the observer.
                 //
-                base._observer.OnError(exception);
+                _observer.OnError(exception);
                 base.Dispose();
 
                 result = null;
@@ -203,13 +205,13 @@ namespace System.Reactive
 
         protected virtual void Done()
         {
-            base._observer.OnCompleted();
+            _observer.OnCompleted();
             base.Dispose();
         }
 
         protected virtual bool Fail(Exception error)
         {
-            base._observer.OnError(error);
+            _observer.OnError(error);
             base.Dispose();
 
             return false;