Browse Source

Mark fields as readonly as suggested by ReSharper.

Daniel Weber 7 years ago
parent
commit
9d1d361fbe

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

@@ -13,7 +13,7 @@ namespace System.Reactive.Concurrency
     public sealed class DefaultScheduler : LocalScheduler, ISchedulerPeriodic
     {
         private static readonly Lazy<DefaultScheduler> _instance = new Lazy<DefaultScheduler>(() => new DefaultScheduler());
-        private static IConcurrencyAbstractionLayer _cal = ConcurrencyAbstractionLayer.Current;
+        private static readonly IConcurrencyAbstractionLayer _cal = ConcurrencyAbstractionLayer.Current;
 
         /// <summary>
         /// Gets the singleton instance of the default scheduler.
@@ -192,7 +192,7 @@ namespace System.Reactive.Concurrency
                 public bool IsDisposed => Disposable.GetIsDisposed(ref _cancel);
             }
 
-            public static ISchedulerLongRunning Instance = new LongRunning();
+            public static readonly ISchedulerLongRunning Instance = new LongRunning();
 
             public IDisposable ScheduleLongRunning<TState>(TState state, Action<TState, ICancelable> action)
             {

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

@@ -28,7 +28,7 @@ namespace System.Reactive.Concurrency
         /// <summary>
         /// Stopwatch for timing free of absolute time dependencies.
         /// </summary>
-        private IStopwatch _stopwatch;
+        private readonly IStopwatch _stopwatch;
 
         /// <summary>
         /// Thread used by the event loop to run work items on. No work should be run on any other thread.

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

@@ -60,7 +60,7 @@ namespace System.Reactive.Concurrency
         //
 
 
-        private static Lazy<IScheduler> _threadPool = new Lazy<IScheduler>(() => Initialize("ThreadPool"));
+        private static readonly Lazy<IScheduler> _threadPool = new Lazy<IScheduler>(() => Initialize("ThreadPool"));
 
         /// <summary>
         /// Gets a scheduler that schedules work on the thread pool.
@@ -68,7 +68,7 @@ namespace System.Reactive.Concurrency
         [Obsolete(Constants_Core.OBSOLETE_SCHEDULER_THREADPOOL)]
         public static IScheduler ThreadPool => _threadPool.Value;
 
-        private static Lazy<IScheduler> _newThread = new Lazy<IScheduler>(() => Initialize("NewThread"));
+        private static readonly Lazy<IScheduler> _newThread = new Lazy<IScheduler>(() => Initialize("NewThread"));
 
         /// <summary>
         /// Gets a scheduler that schedules work on a new thread using default thread creation options.
@@ -76,7 +76,7 @@ namespace System.Reactive.Concurrency
         [Obsolete(Constants_Core.OBSOLETE_SCHEDULER_NEWTHREAD)]
         public static IScheduler NewThread => _newThread.Value;
 
-        private static Lazy<IScheduler> _taskPool = new Lazy<IScheduler>(() => Initialize("TaskPool"));
+        private static readonly Lazy<IScheduler> _taskPool = new Lazy<IScheduler>(() => Initialize("TaskPool"));
 
         /// <summary>
         /// Gets a scheduler that schedules work on Task Parallel Library (TPL) task pool using the default TaskScheduler.

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

@@ -9,7 +9,7 @@ namespace System.Reactive
 {
     internal static class ExceptionHelpers
     {
-        private static Lazy<IExceptionServices> _services = new Lazy<IExceptionServices>(Initialize);
+        private static readonly Lazy<IExceptionServices> _services = new Lazy<IExceptionServices>(Initialize);
 
         public static void Throw(this Exception exception) => _services.Value.Rethrow(exception);
 

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

@@ -13,7 +13,7 @@ namespace System.Reactive.PlatformServices
     [EditorBrowsable(EditorBrowsableState.Never)]
     public static class HostLifecycleService
     {
-        private static Lazy<IHostLifecycleNotifications> _notifications = new Lazy<IHostLifecycleNotifications>(InitializeNotifications);
+        private static readonly Lazy<IHostLifecycleNotifications> _notifications = new Lazy<IHostLifecycleNotifications>(InitializeNotifications);
 
         private static int _refCount;
 

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

@@ -19,8 +19,8 @@ namespace System.Reactive.PlatformServices
     [EditorBrowsable(EditorBrowsableState.Never)]
     public static class SystemClock
     {
-        private static Lazy<ISystemClock> _serviceSystemClock = new Lazy<ISystemClock>(InitializeSystemClock);
-        private static Lazy<INotifySystemClockChanged> _serviceSystemClockChanged = new Lazy<INotifySystemClockChanged>(InitializeSystemClockChanged);
+        private static readonly Lazy<ISystemClock> _serviceSystemClock = new Lazy<ISystemClock>(InitializeSystemClock);
+        private static readonly Lazy<INotifySystemClockChanged> _serviceSystemClockChanged = new Lazy<INotifySystemClockChanged>(InitializeSystemClockChanged);
         private static readonly HashSet<WeakReference<LocalScheduler>> _systemClockChanged = new HashSet<WeakReference<LocalScheduler>>();
         private static IDisposable _systemClockChangedHandlerCollector;
 

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

@@ -18,7 +18,7 @@ namespace System.Reactive
         private bool _isDisposed;
         private int _trampoline;
         private IDisposable _currentSubscription;
-        private Stack<IEnumerator<IObservable<TSource>>> _stack = new Stack<IEnumerator<IObservable<TSource>>>();
+        private readonly Stack<IEnumerator<IObservable<TSource>>> _stack = new Stack<IEnumerator<IObservable<TSource>>>();
 
         public void Run(IEnumerable<IObservable<TSource>> sources)
         {

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Joins/ActivePlan.cs

@@ -8,7 +8,7 @@ namespace System.Reactive.Joins
 {
     internal abstract class ActivePlan
     {
-        private Dictionary<IJoinObserver, IJoinObserver> _joinObservers = new Dictionary<IJoinObserver, IJoinObserver>();
+        private readonly Dictionary<IJoinObserver, IJoinObserver> _joinObservers = new Dictionary<IJoinObserver, IJoinObserver>();
 
         protected readonly Action _onCompleted;
 

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Linq/Observable/Delay.cs

@@ -590,7 +590,7 @@ namespace System.Reactive.Linq.ObservableImpl
             internal abstract class _ : IdentitySink<TSource>
             {
                 private readonly CompositeDisposable _delays = new CompositeDisposable();
-                private object _gate = new object();
+                private readonly object _gate = new object();
 
                 private readonly Func<TSource, IObservable<TDelay>> _delaySelector;
 

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Linq/Observable/Distinct.cs

@@ -26,7 +26,7 @@ namespace System.Reactive.Linq.ObservableImpl
         internal sealed class _ : IdentitySink<TSource>
         {
             private readonly Func<TSource, TKey> _keySelector;
-            private HashSet<TKey> _hashSet;
+            private readonly HashSet<TKey> _hashSet;
 
             public _(Distinct<TSource, TKey> parent, IObserver<TSource> observer)
                 : base(observer)

+ 5 - 5
Rx.NET/Source/src/System.Reactive/Linq/Observable/Merge.cs

@@ -36,10 +36,10 @@ namespace System.Reactive.Linq.ObservableImpl
                     _maxConcurrent = maxConcurrent;
                 }
 
-                private object _gate = new object();
-                private Queue<IObservable<TSource>> _q = new Queue<IObservable<TSource>>();
+                private readonly object _gate = new object();
+                private readonly Queue<IObservable<TSource>> _q = new Queue<IObservable<TSource>>();
                 private volatile bool _isStopped;
-                private CompositeDisposable _group = new CompositeDisposable();
+                private readonly CompositeDisposable _group = new CompositeDisposable();
                 private int _activeCount;
 
                 public override void OnNext(IObservable<TSource> value)
@@ -168,9 +168,9 @@ namespace System.Reactive.Linq.ObservableImpl
                 {
                 }
 
-                private object _gate = new object();
+                private readonly object _gate = new object();
                 private volatile bool _isStopped;
-                private CompositeDisposable _group = new CompositeDisposable();
+                private readonly CompositeDisposable _group = new CompositeDisposable();
 
                 public override void OnNext(IObservable<TSource> value)
                 {

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

@@ -27,7 +27,7 @@ namespace System.Reactive.Linq.ObservableImpl
             internal sealed class _ : IdentitySink<TSource>
             {
                 private readonly int _count;
-                private Queue<TSource> _queue;
+                private readonly Queue<TSource> _queue;
 
                 public _(int count, IObserver<TSource> observer)
                     : base(observer)
@@ -67,7 +67,7 @@ namespace System.Reactive.Linq.ObservableImpl
             internal sealed class _ : IdentitySink<TSource>
             {
                 private readonly TimeSpan _duration;
-                private Queue<Reactive.TimeInterval<TSource>> _queue;
+                private readonly Queue<Reactive.TimeInterval<TSource>> _queue;
 
                 public _(TimeSpan duration, IObserver<TSource> observer)
                     : base(observer)

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Linq/Observable/TakeLast.cs

@@ -142,7 +142,7 @@ namespace System.Reactive.Linq.ObservableImpl
             {
                 private readonly TimeSpan _duration;
                 private readonly IScheduler _loopScheduler;
-                private Queue<Reactive.TimeInterval<TSource>> _queue;
+                private readonly Queue<Reactive.TimeInterval<TSource>> _queue;
 
                 public _(Time parent, IObserver<TSource> observer)
                     : base(observer)

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

@@ -27,7 +27,7 @@ namespace System.Reactive.Linq.ObservableImpl
             internal sealed class _ : Sink<TSource, IList<TSource>>
             {
                 private readonly int _count;
-                private Queue<TSource> _queue;
+                private readonly Queue<TSource> _queue;
 
                 public _(int count, IObserver<IList<TSource>> observer)
                     : base(observer)
@@ -79,7 +79,7 @@ namespace System.Reactive.Linq.ObservableImpl
             internal sealed class _ : Sink<TSource, IList<TSource>>
             {
                 private readonly TimeSpan _duration;
-                private Queue<Reactive.TimeInterval<TSource>> _queue;
+                private readonly Queue<Reactive.TimeInterval<TSource>> _queue;
 
                 public _(TimeSpan duration, IObserver<IList<TSource>> observer)
                     : base(observer)

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

@@ -85,7 +85,7 @@ namespace System.Reactive.Linq.ObservableImpl
                 {
                     private readonly _ _parent;
                     private SecondObserver _other;
-                    private Queue<TFirst> _queue;
+                    private readonly Queue<TFirst> _queue;
 
                     public FirstObserver(_ parent)
                     {
@@ -168,7 +168,7 @@ namespace System.Reactive.Linq.ObservableImpl
                 {
                     private readonly _ _parent;
                     private FirstObserver _other;
-                    private Queue<TSecond> _queue;
+                    private readonly Queue<TSecond> _queue;
 
                     public SecondObserver(_ parent)
                     {

+ 2 - 2
Rx.NET/Source/src/System.Reactive/Linq/QueryLanguageEx.cs

@@ -490,8 +490,8 @@ namespace System.Reactive.Linq
 
         private class ChainObservable<T> : ISubject<IObservable<T>, T>
         {
-            private T _head;
-            private AsyncSubject<IObservable<T>> _tail = new AsyncSubject<IObservable<T>>();
+            private readonly T _head;
+            private readonly AsyncSubject<IObservable<T>> _tail = new AsyncSubject<IObservable<T>>();
 
             public ChainObservable(T head)
             {

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

@@ -365,7 +365,7 @@ namespace System.Reactive
                 }
             }
 
-            private static Lazy<ILookup<string, MethodInfo>> _observableMethods = new Lazy<ILookup<string, MethodInfo>>(() => GetMethods(typeof(Observable)));
+            private static readonly Lazy<ILookup<string, MethodInfo>> _observableMethods = new Lazy<ILookup<string, MethodInfo>>(() => GetMethods(typeof(Observable)));
 
             private static MethodCallExpression FindObservableMethod(MethodInfo method, IList<Expression> arguments)
             {