From 331ad59db7a3a11343914daac4cddc6b2a777449 Mon Sep 17 00:00:00 2001 From: Daniel Weber Date: Mon, 2 Jul 2018 18:56:24 +0200 Subject: [PATCH] Remove code redundancies as suggested by ReSharper. --- Rx.NET/Source/src/AssemblyInfo.cs | 3 - .../ConcurrencyAbstractionLayerImpl.cs | 6 +- .../Concurrency/LocalScheduler.cs | 8 ++- .../Scheduler.Services.Emulation.cs | 21 ++++--- .../Concurrency/Scheduler.Services.cs | 2 +- .../Synchronization.Synchronize.cs | 4 +- .../Concurrency/ThreadPoolScheduler.cs | 6 +- .../Concurrency/VirtualTimeScheduler.cs | 2 +- .../System.Reactive/ExperimentalAttribute.cs | 2 +- .../System.Reactive/Internal/SafeObserver.cs | 6 +- .../Internal/ScheduledObserver.cs | 2 +- .../Internal/TailRecursiveSink.cs | 58 +++++++++---------- .../System.Reactive/Linq/GroupedObservable.cs | 12 ++-- ...lQueryMethodImplementationTypeAttribute.cs | 2 +- .../Linq/Observable/AppendPrepend.cs | 36 +++++------- .../Linq/Observable/CombineLatest.cs | 6 -- .../Linq/Observable/FromEventPattern.cs | 2 +- .../Linq/Observable/PushToPullAdapter.cs | 8 +-- .../System.Reactive/Linq/Observable/Skip.cs | 6 +- .../Linq/Observable/SkipUntil.cs | 6 +- .../System.Reactive/Linq/Observable/Take.cs | 12 ++-- .../Linq/Observable/TakeLast.cs | 12 ++-- .../Linq/Observable/TakeUntil.cs | 6 +- .../System.Reactive/Linq/Observable/Zip.cs | 5 -- .../Linq/QueryLanguage.Async.cs | 16 ++--- .../Linq/QueryLanguage.Events.cs | 6 +- .../Linq/QueryLanguage.Single.cs | 3 +- .../src/System.Reactive/Notification.cs | 3 +- .../src/System.Reactive/ObservableBase.cs | 1 - .../src/System.Reactive/ObservableQuery.cs | 9 ++- .../System.Reactive/Observer.Extensions.cs | 6 +- .../TaskObservableMethodBuilder.cs | 12 ++-- .../Subjects/BehaviorSubject.cs | 11 ++-- .../System.Reactive/Subjects/ReplaySubject.cs | 3 +- .../Tasks/TaskObservableExtensions.cs | 6 +- .../Api/ApiApprovalTests.Core.approved.txt | 4 +- 36 files changed, 125 insertions(+), 188 deletions(-) diff --git a/Rx.NET/Source/src/AssemblyInfo.cs b/Rx.NET/Source/src/AssemblyInfo.cs index c58daae750..43710c7696 100644 --- a/Rx.NET/Source/src/AssemblyInfo.cs +++ b/Rx.NET/Source/src/AssemblyInfo.cs @@ -1,9 +1,6 @@ using System; using System.Resources; using System.Runtime.InteropServices; -using System.Security; - - [assembly: ComVisible(false)] [assembly: CLSCompliant(true)] diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/ConcurrencyAbstractionLayerImpl.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/ConcurrencyAbstractionLayerImpl.cs index 142d973841..e381f5104e 100644 --- a/Rx.NET/Source/src/System.Reactive/Concurrency/ConcurrencyAbstractionLayerImpl.cs +++ b/Rx.NET/Source/src/System.Reactive/Concurrency/ConcurrencyAbstractionLayerImpl.cs @@ -44,10 +44,8 @@ public IDisposable StartPeriodicTimer(Action action, TimeSpan period) { return new FastPeriodicTimer(action); } - else - { - return new PeriodicTimer(action, period); - } + + return new PeriodicTimer(action, period); } public IDisposable QueueUserWorkItem(Action action, object state) diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/LocalScheduler.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/LocalScheduler.cs index 7023acff6a..8a778be863 100644 --- a/Rx.NET/Source/src/System.Reactive/Concurrency/LocalScheduler.cs +++ b/Rx.NET/Source/src/System.Reactive/Concurrency/LocalScheduler.cs @@ -84,13 +84,15 @@ protected virtual object GetService(Type serviceType) { if (serviceType == typeof(IStopwatchProvider)) { - return this as IStopwatchProvider; + return this; } - else if (serviceType == typeof(ISchedulerLongRunning)) + + if (serviceType == typeof(ISchedulerLongRunning)) { return this as ISchedulerLongRunning; } - else if (serviceType == typeof(ISchedulerPeriodic)) + + if (serviceType == typeof(ISchedulerPeriodic)) { return this as ISchedulerPeriodic; } diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.Emulation.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.Emulation.cs index 012dfbcd32..f1577ef660 100644 --- a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.Emulation.cs +++ b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.Emulation.cs @@ -411,7 +411,8 @@ private void Tick(Action, TimeSpan> recurse) next = Normalize(_nextDue - (_stopwatch.Elapsed - _inactiveTime)); break; } - else if (_runState == DISPOSED) + + if (_runState == DISPOSED) { // // In case the periodic job gets disposed but we are currently @@ -422,16 +423,14 @@ private void Tick(Action, TimeSpan> recurse) // return; } - else - { - // - // This is the least common case where we got suspended and need - // to block such that future reevaluations of the next due time - // will pick up the cumulative inactive time delta. - // - Debug.Assert(_runState == SUSPENDED); - shouldWaitForResume = true; - } + + // + // This is the least common case where we got suspended and need + // to block such that future reevaluations of the next due time + // will pick up the cumulative inactive time delta. + // + Debug.Assert(_runState == SUSPENDED); + shouldWaitForResume = true; } // diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.cs index 4eb166069e..6979a46eb5 100644 --- a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.cs +++ b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.cs @@ -10,7 +10,7 @@ namespace System.Reactive.Concurrency // public static partial class Scheduler { - internal static Type[] OPTIMIZATIONS = new Type[] { + internal static Type[] OPTIMIZATIONS = { typeof(ISchedulerLongRunning), typeof(IStopwatchProvider), typeof(ISchedulerPeriodic), diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/Synchronization.Synchronize.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/Synchronization.Synchronize.cs index f6622c8cf7..441b695f45 100644 --- a/Rx.NET/Source/src/System.Reactive/Concurrency/Synchronization.Synchronize.cs +++ b/Rx.NET/Source/src/System.Reactive/Concurrency/Synchronization.Synchronize.cs @@ -27,14 +27,12 @@ public Synchronize(IObservable source) internal sealed class _ : IdentitySink { - private readonly Synchronize _parent; private readonly object _gate; public _(Synchronize parent, IObserver observer) : base(observer) { - _parent = parent; - _gate = _parent._gate ?? new object(); + _gate = parent._gate ?? new object(); } public override void OnNext(TSource value) diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/ThreadPoolScheduler.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/ThreadPoolScheduler.cs index 4470aeee78..bd03382bd3 100644 --- a/Rx.NET/Source/src/System.Reactive/Concurrency/ThreadPoolScheduler.cs +++ b/Rx.NET/Source/src/System.Reactive/Concurrency/ThreadPoolScheduler.cs @@ -141,10 +141,8 @@ public IDisposable SchedulePeriodic(TState state, TimeSpan period, Func< { return new FastPeriodicTimer(state, action); } - else - { - return new PeriodicTimer(state, period, action); - } + + return new PeriodicTimer(state, period, action); } private sealed class FastPeriodicTimer : IDisposable diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/VirtualTimeScheduler.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/VirtualTimeScheduler.cs index 68e91765ad..d94a22cbfc 100644 --- a/Rx.NET/Source/src/System.Reactive/Concurrency/VirtualTimeScheduler.cs +++ b/Rx.NET/Source/src/System.Reactive/Concurrency/VirtualTimeScheduler.cs @@ -320,7 +320,7 @@ protected virtual object GetService(Type serviceType) { if (serviceType == typeof(IStopwatchProvider)) { - return this as IStopwatchProvider; + return this; } return null; diff --git a/Rx.NET/Source/src/System.Reactive/ExperimentalAttribute.cs b/Rx.NET/Source/src/System.Reactive/ExperimentalAttribute.cs index de3fccded8..ad41a1fb7b 100644 --- a/Rx.NET/Source/src/System.Reactive/ExperimentalAttribute.cs +++ b/Rx.NET/Source/src/System.Reactive/ExperimentalAttribute.cs @@ -7,7 +7,7 @@ namespace System.Reactive /// /// Marks the program elements that are experimental. This class cannot be inherited. /// - [Experimental, AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = true)] + [Experimental, AttributeUsage(AttributeTargets.All)] public sealed class ExperimentalAttribute : Attribute { } diff --git a/Rx.NET/Source/src/System.Reactive/Internal/SafeObserver.cs b/Rx.NET/Source/src/System.Reactive/Internal/SafeObserver.cs index 9838f264c7..1b6dd263ec 100644 --- a/Rx.NET/Source/src/System.Reactive/Internal/SafeObserver.cs +++ b/Rx.NET/Source/src/System.Reactive/Internal/SafeObserver.cs @@ -62,10 +62,8 @@ public static ISafeObserver Wrap(IObserver observer) { return a.MakeSafe(); } - else - { - return new WrappingSafeObserver(observer); - } + + return new WrappingSafeObserver(observer); } private IDisposable _disposable; diff --git a/Rx.NET/Source/src/System.Reactive/Internal/ScheduledObserver.cs b/Rx.NET/Source/src/System.Reactive/Internal/ScheduledObserver.cs index 950caa6f3d..33acd71ab2 100644 --- a/Rx.NET/Source/src/System.Reactive/Internal/ScheduledObserver.cs +++ b/Rx.NET/Source/src/System.Reactive/Internal/ScheduledObserver.cs @@ -602,7 +602,7 @@ private bool DrainStep(ConcurrentQueue q, IObserver downstream, bool delay } return true; } - else + // the queue is empty and the upstream hasn't completed yet if (empty) { diff --git a/Rx.NET/Source/src/System.Reactive/Internal/TailRecursiveSink.cs b/Rx.NET/Source/src/System.Reactive/Internal/TailRecursiveSink.cs index b9b5090fd8..c2ac0ca982 100644 --- a/Rx.NET/Source/src/System.Reactive/Internal/TailRecursiveSink.cs +++ b/Rx.NET/Source/src/System.Reactive/Internal/TailRecursiveSink.cs @@ -109,44 +109,40 @@ private void Drain() _stack.Push(nextEnumerator); continue; } - else - { - Volatile.Write(ref _isDisposed, true); - continue; - } + + Volatile.Write(ref _isDisposed, true); + continue; } - else - { - // we need an unique indicator for this as - // Subscribe could return a Disposable.Empty or - // a BooleanDisposable - var sad = ReadyToken.Ready; - // Swap in the Ready indicator so we know the sequence hasn't been disposed - if (Disposable.TrySetSingle(ref _currentSubscription, sad) == TrySetSingleResult.Success) - { - // subscribe to the source - var d = next.SubscribeSafe(this); + // we need an unique indicator for this as + // Subscribe could return a Disposable.Empty or + // a BooleanDisposable + var sad = ReadyToken.Ready; - // Try to swap in the returned disposable in place of the Ready indicator - // Since this drain loop is the only one to use Ready, this should - // be unambiguous - var u = Interlocked.CompareExchange(ref _currentSubscription, d, sad); + // Swap in the Ready indicator so we know the sequence hasn't been disposed + if (Disposable.TrySetSingle(ref _currentSubscription, sad) == TrySetSingleResult.Success) + { + // subscribe to the source + var d = next.SubscribeSafe(this); - // sequence disposed or completed synchronously - if (u != sad) + // Try to swap in the returned disposable in place of the Ready indicator + // Since this drain loop is the only one to use Ready, this should + // be unambiguous + var u = Interlocked.CompareExchange(ref _currentSubscription, d, sad); + + // sequence disposed or completed synchronously + if (u != sad) + { + d.Dispose(); + if (u == BooleanDisposable.True) { - d.Dispose(); - if (u == BooleanDisposable.True) - { - continue; - } + continue; } } - else - { - continue; - } + } + else + { + continue; } } else diff --git a/Rx.NET/Source/src/System.Reactive/Linq/GroupedObservable.cs b/Rx.NET/Source/src/System.Reactive/Linq/GroupedObservable.cs index 146ae370c2..61556afcb6 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/GroupedObservable.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/GroupedObservable.cs @@ -38,13 +38,11 @@ protected override IDisposable SubscribeCore(IObserver observer) var subscription = _subject.Subscribe/*Unsafe*/(observer); return StableCompositeDisposable.Create(release, subscription); } - else - { - // - // [OK] Use of unsafe Subscribe: called on a known subject implementation. - // - return _subject.Subscribe/*Unsafe*/(observer); - } + + // + // [OK] Use of unsafe Subscribe: called on a known subject implementation. + // + return _subject.Subscribe/*Unsafe*/(observer); } } } diff --git a/Rx.NET/Source/src/System.Reactive/Linq/LocalQueryMethodImplementationTypeAttribute.cs b/Rx.NET/Source/src/System.Reactive/Linq/LocalQueryMethodImplementationTypeAttribute.cs index f4aa56862f..db9eb44827 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/LocalQueryMethodImplementationTypeAttribute.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/LocalQueryMethodImplementationTypeAttribute.cs @@ -12,7 +12,7 @@ namespace System.Reactive.Linq /// target class type. /// [EditorBrowsable(EditorBrowsableState.Never)] - [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] + [AttributeUsage(AttributeTargets.Class, Inherited = false)] public sealed class LocalQueryMethodImplementationTypeAttribute : Attribute { private readonly Type _targetType; diff --git a/Rx.NET/Source/src/System.Reactive/Linq/Observable/AppendPrepend.cs b/Rx.NET/Source/src/System.Reactive/Linq/Observable/AppendPrepend.cs index 774174fd7a..388833261d 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/Observable/AppendPrepend.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/Observable/AppendPrepend.cs @@ -41,11 +41,9 @@ public IAppendPrepend Append(TSource value) return new AppendPrependMultiple(_source, null, new Node(prev, value), Scheduler); } - else - { - return new AppendPrependMultiple(_source, - prev, new Node(value), Scheduler); - } + + return new AppendPrependMultiple(_source, + prev, new Node(value), Scheduler); } public IAppendPrepend Prepend(TSource value) @@ -57,11 +55,9 @@ public IAppendPrepend Prepend(TSource value) return new AppendPrependMultiple(_source, new Node(value), prev, Scheduler); } - else - { - return new AppendPrependMultiple(_source, - new Node(prev, value), null, Scheduler); - } + + return new AppendPrependMultiple(_source, + new Node(prev, value), null, Scheduler); } protected override _ CreateSink(IObserver observer) => new _(this, observer); @@ -239,17 +235,15 @@ private IDisposable Schedule(TSource[] array, Action<_> continueWith) // return longRunning.ScheduleLongRunning(new State(null, this, array, continueWith), Loop); } - else - { - // - // We never allow the scheduled work to be cancelled. Instead, the flag - // is used to have LoopRec bail out and perform proper clean-up of the - // enumerator. - // - var flag = new BooleanDisposable(); - _scheduler.Schedule(new State(flag, this, array, continueWith), LoopRec); - return flag; - } + + // + // We never allow the scheduled work to be cancelled. Instead, the flag + // is used to have LoopRec bail out and perform proper clean-up of the + // enumerator. + // + var flag = new BooleanDisposable(); + _scheduler.Schedule(new State(flag, this, array, continueWith), LoopRec); + return flag; } private struct State diff --git a/Rx.NET/Source/src/System.Reactive/Linq/Observable/CombineLatest.cs b/Rx.NET/Source/src/System.Reactive/Linq/Observable/CombineLatest.cs index 3a7df02801..2fc6a03c01 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/Observable/CombineLatest.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/Observable/CombineLatest.cs @@ -108,7 +108,6 @@ public void OnNext(TFirst value) else if (_other.Done) { _parent.ForwardOnCompleted(); - return; } } } @@ -130,7 +129,6 @@ public void OnCompleted() if (_other.Done) { _parent.ForwardOnCompleted(); - return; } else { @@ -203,7 +201,6 @@ public void OnCompleted() if (_other.Done) { _parent.ForwardOnCompleted(); - return; } else { @@ -323,7 +320,6 @@ public void Done(int index) if (allDone) { ForwardOnCompleted(); - return; } } } @@ -472,7 +468,6 @@ private void OnNext(int index, TSource value) else if (_isDone.AllExcept(index)) { ForwardOnCompleted(); - return; } } } @@ -494,7 +489,6 @@ private void OnCompleted(int index) if (_isDone.All()) { ForwardOnCompleted(); - return; } else { diff --git a/Rx.NET/Source/src/System.Reactive/Linq/Observable/FromEventPattern.cs b/Rx.NET/Source/src/System.Reactive/Linq/Observable/FromEventPattern.cs index 8d83209c3f..2323979b3a 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/Observable/FromEventPattern.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/Observable/FromEventPattern.cs @@ -151,7 +151,7 @@ private Action AddHandlerCore(Delegate handler) private Action AddHandlerCoreWinRT(Delegate handler) { var token = _addMethod.Invoke(_target, new object[] { handler }); - return () => _removeMethod.Invoke(_target, new object[] { token }); + return () => _removeMethod.Invoke(_target, new[] { token }); } #endif } diff --git a/Rx.NET/Source/src/System.Reactive/Linq/Observable/PushToPullAdapter.cs b/Rx.NET/Source/src/System.Reactive/Linq/Observable/PushToPullAdapter.cs index 1646461658..f1048c1945 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/Observable/PushToPullAdapter.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/Observable/PushToPullAdapter.cs @@ -50,11 +50,9 @@ public bool MoveNext() Current = current; return true; } - else - { - _done = true; - Dispose(); - } + + _done = true; + Dispose(); } return false; diff --git a/Rx.NET/Source/src/System.Reactive/Linq/Observable/Skip.cs b/Rx.NET/Source/src/System.Reactive/Linq/Observable/Skip.cs index 451d68598c..6b539c527c 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/Observable/Skip.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/Observable/Skip.cs @@ -88,10 +88,8 @@ public IObservable Combine(TimeSpan duration) { return this; } - else - { - return new Time(_source, duration, _scheduler); - } + + return new Time(_source, duration, _scheduler); } protected override _ CreateSink(IObserver observer) => new _(observer); diff --git a/Rx.NET/Source/src/System.Reactive/Linq/Observable/SkipUntil.cs b/Rx.NET/Source/src/System.Reactive/Linq/Observable/SkipUntil.cs index bb3e2c634f..4611b7a247 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/Observable/SkipUntil.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/Observable/SkipUntil.cs @@ -147,10 +147,8 @@ public IObservable Combine(DateTimeOffset startTime) { return this; } - else - { - return new SkipUntil(_source, startTime, _scheduler); - } + + return new SkipUntil(_source, startTime, _scheduler); } protected override _ CreateSink(IObserver observer) => new _(observer); diff --git a/Rx.NET/Source/src/System.Reactive/Linq/Observable/Take.cs b/Rx.NET/Source/src/System.Reactive/Linq/Observable/Take.cs index 7bcd0030dd..77e592faae 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/Observable/Take.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/Observable/Take.cs @@ -33,10 +33,8 @@ public IObservable Combine(int count) { return this; } - else - { - return new Count(_source, count); - } + + return new Count(_source, count); } protected override _ CreateSink(IObserver observer) => new _(_count, observer); @@ -97,10 +95,8 @@ public IObservable Combine(TimeSpan duration) { return this; } - else - { - return new Time(_source, duration, _scheduler); - } + + return new Time(_source, duration, _scheduler); } protected override _ CreateSink(IObserver observer) => new _(observer); diff --git a/Rx.NET/Source/src/System.Reactive/Linq/Observable/TakeLast.cs b/Rx.NET/Source/src/System.Reactive/Linq/Observable/TakeLast.cs index 4664646ba7..e58d9e5c02 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/Observable/TakeLast.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/Observable/TakeLast.cs @@ -106,10 +106,8 @@ private void Loop(ICancelable cancel) ForwardOnCompleted(); break; } - else - { - ForwardOnNext(_queue.Dequeue()); - } + + ForwardOnNext(_queue.Dequeue()); n--; } @@ -223,10 +221,8 @@ private void Loop(ICancelable cancel) ForwardOnCompleted(); break; } - else - { - ForwardOnNext(_queue.Dequeue().Value); - } + + ForwardOnNext(_queue.Dequeue().Value); n--; } diff --git a/Rx.NET/Source/src/System.Reactive/Linq/Observable/TakeUntil.cs b/Rx.NET/Source/src/System.Reactive/Linq/Observable/TakeUntil.cs index 03dc4ec69d..ec4dd6fb9d 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/Observable/TakeUntil.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/Observable/TakeUntil.cs @@ -124,10 +124,8 @@ public IObservable Combine(DateTimeOffset endTime) { return this; } - else - { - return new TakeUntil(_source, endTime, _scheduler); - } + + return new TakeUntil(_source, endTime, _scheduler); } protected override _ CreateSink(IObserver observer) => new _(observer); diff --git a/Rx.NET/Source/src/System.Reactive/Linq/Observable/Zip.cs b/Rx.NET/Source/src/System.Reactive/Linq/Observable/Zip.cs index 9cf3416ace..c082489ce0 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/Observable/Zip.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/Observable/Zip.cs @@ -149,7 +149,6 @@ public void OnCompleted() if (_other.Done) { _parent.ForwardOnCompleted(); - return; } else { @@ -232,7 +231,6 @@ public void OnCompleted() if (_other.Done) { _parent.ForwardOnCompleted(); - return; } else { @@ -471,7 +469,6 @@ public void Done(int index) if (allDone) { ForwardOnCompleted(); - return; } } } @@ -642,7 +639,6 @@ private void OnNext(int index, TSource value) else if (_isDone.AllExcept(index)) { ForwardOnCompleted(); - return; } } } @@ -664,7 +660,6 @@ private void OnCompleted(int index) if (_isDone.All()) { ForwardOnCompleted(); - return; } else { diff --git a/Rx.NET/Source/src/System.Reactive/Linq/QueryLanguage.Async.cs b/Rx.NET/Source/src/System.Reactive/Linq/QueryLanguage.Async.cs index 4a8d98d3df..b6cb7fe5c3 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/QueryLanguage.Async.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/QueryLanguage.Async.cs @@ -684,10 +684,8 @@ private IObservable StartAsyncImpl(Func> functio { return task.ToObservable(scheduler); } - else - { - return task.ToObservable(); - } + + return task.ToObservable(); } public virtual IObservable StartAsync(Func> functionAsync) @@ -789,10 +787,8 @@ private IObservable StartAsyncImpl(Func actionAsync, IScheduler sche { return task.ToObservable(scheduler); } - else - { - return task.ToObservable(); - } + + return task.ToObservable(); } public virtual IObservable StartAsync(Func actionAsync) @@ -929,7 +925,7 @@ public virtual Func> ToAsync(Func> ToAsync(Func function, IScheduler scheduler) { - return (first) => + return first => { var subject = new AsyncSubject(); scheduler.ScheduleAction((function, subject, first), state => @@ -1426,7 +1422,7 @@ public virtual Func> ToAsync(Action public virtual Func> ToAsync(Action action, IScheduler scheduler) { - return (first) => + return first => { var subject = new AsyncSubject(); scheduler.ScheduleAction((subject, action, first), state => diff --git a/Rx.NET/Source/src/System.Reactive/Linq/QueryLanguage.Events.cs b/Rx.NET/Source/src/System.Reactive/Linq/QueryLanguage.Events.cs index defbffce56..7ab69fcca7 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/QueryLanguage.Events.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/QueryLanguage.Events.cs @@ -368,10 +368,8 @@ private static IScheduler GetSchedulerForCurrentContext() { return new SynchronizationContextScheduler(context, false); } - else - { - return SchedulerDefaults.ConstantTimeOperations; - } + + return SchedulerDefaults.ConstantTimeOperations; } #endregion diff --git a/Rx.NET/Source/src/System.Reactive/Linq/QueryLanguage.Single.cs b/Rx.NET/Source/src/System.Reactive/Linq/QueryLanguage.Single.cs index 30b022f62b..058d205bd4 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/QueryLanguage.Single.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/QueryLanguage.Single.cs @@ -63,7 +63,8 @@ public virtual IObservable> Buffer(IObservable { return new Buffer.CountOverlap(source, count, skip); } - else if (count < skip) + + if (count < skip) { return new Buffer.CountSkip(source, count, skip); } diff --git a/Rx.NET/Source/src/System.Reactive/Notification.cs b/Rx.NET/Source/src/System.Reactive/Notification.cs index 1e6bcb6e05..a42293ea3b 100644 --- a/Rx.NET/Source/src/System.Reactive/Notification.cs +++ b/Rx.NET/Source/src/System.Reactive/Notification.cs @@ -6,7 +6,6 @@ using System.Diagnostics; using System.Globalization; using System.Reactive.Concurrency; -using System.Reactive.Disposables; #pragma warning disable 0659 #pragma warning disable 0661 @@ -31,7 +30,7 @@ public enum NotificationKind /// /// Represents an OnCompleted notification. /// - OnCompleted, + OnCompleted } /// diff --git a/Rx.NET/Source/src/System.Reactive/ObservableBase.cs b/Rx.NET/Source/src/System.Reactive/ObservableBase.cs index dd01df7a61..d0eded953f 100644 --- a/Rx.NET/Source/src/System.Reactive/ObservableBase.cs +++ b/Rx.NET/Source/src/System.Reactive/ObservableBase.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Reactive.Concurrency; -using System.Reactive.Disposables; namespace System.Reactive { diff --git a/Rx.NET/Source/src/System.Reactive/ObservableQuery.cs b/Rx.NET/Source/src/System.Reactive/ObservableQuery.cs index 2e9f65eead..5179c1c97b 100644 --- a/Rx.NET/Source/src/System.Reactive/ObservableQuery.cs +++ b/Rx.NET/Source/src/System.Reactive/ObservableQuery.cs @@ -177,10 +177,8 @@ protected override Expression VisitConstant(ConstantExpression/*!*/ node) { return Expression.Constant(source); } - else - { - return Visit(query.Expression); - } + + return Visit(query.Expression); } return node; @@ -208,7 +206,8 @@ protected override Expression VisitMethodCall(MethodCallExpression/*!*/ node) var then = Expression.Call(pattern, "Then", method.GetGenericArguments(), arguments); return then; } - else if (method.Name == "And") + + if (method.Name == "And") { // // Retarget And to the corresponding pattern. diff --git a/Rx.NET/Source/src/System.Reactive/Observer.Extensions.cs b/Rx.NET/Source/src/System.Reactive/Observer.Extensions.cs index 1b24b3f43a..e6c5847c70 100644 --- a/Rx.NET/Source/src/System.Reactive/Observer.Extensions.cs +++ b/Rx.NET/Source/src/System.Reactive/Observer.Extensions.cs @@ -226,10 +226,8 @@ public static IObserver Synchronize(IObserver observer, bool preventRee { return new AsyncLockObserver(observer, new AsyncLock()); } - else - { - return new SynchronizedObserver(observer, new object()); - } + + return new SynchronizedObserver(observer, new object()); } /// diff --git a/Rx.NET/Source/src/System.Reactive/Runtime/CompilerServices/TaskObservableMethodBuilder.cs b/Rx.NET/Source/src/System.Reactive/Runtime/CompilerServices/TaskObservableMethodBuilder.cs index 6141b14a59..8624a6a8c7 100644 --- a/Rx.NET/Source/src/System.Reactive/Runtime/CompilerServices/TaskObservableMethodBuilder.cs +++ b/Rx.NET/Source/src/System.Reactive/Runtime/CompilerServices/TaskObservableMethodBuilder.cs @@ -5,7 +5,6 @@ using System.Reactive; using System.Reactive.Concurrency; using System.Reactive.Disposables; -using System.Reactive.Linq; using System.Reactive.Subjects; using System.Security; @@ -296,16 +295,15 @@ public IDisposable Subscribe(IObserver observer) { return _subject.Subscribe(observer); } - else if (_exception != null) + + if (_exception != null) { observer.OnError(_exception); return Disposable.Empty; } - else - { - observer.OnNext(_result); - return Disposable.Empty; - } + + observer.OnNext(_result); + return Disposable.Empty; } /// diff --git a/Rx.NET/Source/src/System.Reactive/Subjects/BehaviorSubject.cs b/Rx.NET/Source/src/System.Reactive/Subjects/BehaviorSubject.cs index 5ccfd4f58b..02dc28467f 100644 --- a/Rx.NET/Source/src/System.Reactive/Subjects/BehaviorSubject.cs +++ b/Rx.NET/Source/src/System.Reactive/Subjects/BehaviorSubject.cs @@ -118,15 +118,14 @@ public bool TryGetValue(out T value) value = default; return false; } - else if (_exception != null) + + if (_exception != null) { throw _exception; } - else - { - value = _value; - return true; - } + + value = _value; + return true; } } diff --git a/Rx.NET/Source/src/System.Reactive/Subjects/ReplaySubject.cs b/Rx.NET/Source/src/System.Reactive/Subjects/ReplaySubject.cs index be12c756a9..d9efc46667 100644 --- a/Rx.NET/Source/src/System.Reactive/Subjects/ReplaySubject.cs +++ b/Rx.NET/Source/src/System.Reactive/Subjects/ReplaySubject.cs @@ -880,7 +880,8 @@ public void EnsureActive(int count) observer.OnError(error); break; } - else if (done) + + if (done) { var observer = Done(); observer.OnCompleted(); diff --git a/Rx.NET/Source/src/System.Reactive/Threading/Tasks/TaskObservableExtensions.cs b/Rx.NET/Source/src/System.Reactive/Threading/Tasks/TaskObservableExtensions.cs index 3f6c249b0c..85011cea22 100644 --- a/Rx.NET/Source/src/System.Reactive/Threading/Tasks/TaskObservableExtensions.cs +++ b/Rx.NET/Source/src/System.Reactive/Threading/Tasks/TaskObservableExtensions.cs @@ -246,10 +246,8 @@ private static IObservable ToObservableResult(AsyncSubject diff --git a/Rx.NET/Source/tests/Tests.System.Reactive.ApiApprovals/Api/ApiApprovalTests.Core.approved.txt b/Rx.NET/Source/tests/Tests.System.Reactive.ApiApprovals/Api/ApiApprovalTests.Core.approved.txt index d019b166f5..ebe99b93ce 100644 --- a/Rx.NET/Source/tests/Tests.System.Reactive.ApiApprovals/Api/ApiApprovalTests.Core.approved.txt +++ b/Rx.NET/Source/tests/Tests.System.Reactive.ApiApprovals/Api/ApiApprovalTests.Core.approved.txt @@ -58,7 +58,7 @@ namespace System.Reactive protected void Add(System.Delegate handler, System.Action invoke) { } protected void Remove(System.Delegate handler) { } } - [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Module | System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Enum | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Field | System.AttributeTargets.Event | System.AttributeTargets.Interface | System.AttributeTargets.Parameter | System.AttributeTargets.Delegate | System.AttributeTargets.ReturnValue | System.AttributeTargets.GenericParameter | System.AttributeTargets.All, AllowMultiple=false, Inherited=true)] + [System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Module | System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Enum | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Field | System.AttributeTargets.Event | System.AttributeTargets.Interface | System.AttributeTargets.Parameter | System.AttributeTargets.Delegate | System.AttributeTargets.ReturnValue | System.AttributeTargets.GenericParameter | System.AttributeTargets.All)] [System.Reactive.ExperimentalAttribute()] public sealed class ExperimentalAttribute : System.Attribute { @@ -825,7 +825,7 @@ namespace System.Reactive.Linq { System.Reactive.Linq.IQbservable CreateQuery(System.Linq.Expressions.Expression expression); } - [System.AttributeUsageAttribute(System.AttributeTargets.Class | System.AttributeTargets.All, AllowMultiple=false, Inherited=false)] + [System.AttributeUsageAttribute(System.AttributeTargets.Class | System.AttributeTargets.All, Inherited=false)] public sealed class LocalQueryMethodImplementationTypeAttribute : System.Attribute { public LocalQueryMethodImplementationTypeAttribute(System.Type targetType) { }