Преглед изворни кода

4.x: simplify default(X) usages

Dávid Karnok пре 7 година
родитељ
комит
70741b9608

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

@@ -83,7 +83,7 @@ namespace System.Reactive
         private void RemoveAt(int index)
         private void RemoveAt(int index)
         {
         {
             _items[index] = _items[--_size];
             _items[index] = _items[--_size];
-            _items[_size] = default(IndexedItem);
+            _items[_size] = default;
 
 
             if (Percolate(index) == index)
             if (Percolate(index) == index)
                 Heapify(index);
                 Heapify(index);

+ 15 - 4
Rx.NET/Source/src/System.Reactive/Linq/Observable/Aggregate.cs

@@ -29,8 +29,6 @@ namespace System.Reactive.Linq.ObservableImpl
                 : base(observer)
                 : base(observer)
             {
             {
                 _accumulator = accumulator;
                 _accumulator = accumulator;
-                _accumulation = default(TSource);
-                _hasAccumulation = false;
             }
             }
 
 
             public override void OnNext(TSource value)
             public override void OnNext(TSource value)
@@ -48,11 +46,18 @@ namespace System.Reactive.Linq.ObservableImpl
                     }
                     }
                     catch (Exception exception)
                     catch (Exception exception)
                     {
                     {
+                        _accumulation = default;
                         ForwardOnError(exception);
                         ForwardOnError(exception);
                     }
                     }
                 }
                 }
             }
             }
 
 
+            public override void OnError(Exception error)
+            {
+                _accumulation = default;
+                ForwardOnError(error);
+            }
+
             public override void OnCompleted()
             public override void OnCompleted()
             {
             {
                 if (!_hasAccumulation)
                 if (!_hasAccumulation)
@@ -61,7 +66,9 @@ namespace System.Reactive.Linq.ObservableImpl
                 }
                 }
                 else
                 else
                 {
                 {
-                    ForwardOnNext(_accumulation);
+                    var accumulation = _accumulation;
+                    _accumulation = default;
+                    ForwardOnNext(accumulation);
                     ForwardOnCompleted();
                     ForwardOnCompleted();
                 }
                 }
             }
             }
@@ -105,18 +112,22 @@ namespace System.Reactive.Linq.ObservableImpl
                 }
                 }
                 catch (Exception exception)
                 catch (Exception exception)
                 {
                 {
+                    _accumulation = default;
                     ForwardOnError(exception);
                     ForwardOnError(exception);
                 }
                 }
             }
             }
 
 
             public override void OnError(Exception error)
             public override void OnError(Exception error)
             {
             {
+                _accumulation = default;
                 ForwardOnError(error);
                 ForwardOnError(error);
             }
             }
 
 
             public override void OnCompleted()
             public override void OnCompleted()
             {
             {
-                ForwardOnNext(_accumulation);
+                var accumulation = _accumulation;
+                _accumulation = default;
+                ForwardOnNext(accumulation);
                 ForwardOnCompleted();
                 ForwardOnCompleted();
             }
             }
         }
         }

+ 19 - 7
Rx.NET/Source/src/System.Reactive/Linq/Observable/LastAsync.cs

@@ -27,8 +27,6 @@ namespace System.Reactive.Linq.ObservableImpl
                 public _(IObserver<TSource> observer)
                 public _(IObserver<TSource> observer)
                     : base(observer)
                     : base(observer)
                 {
                 {
-                    _value = default(TSource);
-                    _seenValue = false;
                 }
                 }
 
 
                 public override void OnNext(TSource value)
                 public override void OnNext(TSource value)
@@ -37,6 +35,12 @@ namespace System.Reactive.Linq.ObservableImpl
                     _seenValue = true;
                     _seenValue = true;
                 }
                 }
 
 
+                public override void OnError(Exception error)
+                {
+                    _value = default;
+                    ForwardOnError(error);
+                }
+
                 public override void OnCompleted()
                 public override void OnCompleted()
                 {
                 {
                     if (!_seenValue)
                     if (!_seenValue)
@@ -45,7 +49,9 @@ namespace System.Reactive.Linq.ObservableImpl
                     }
                     }
                     else
                     else
                     {
                     {
-                        ForwardOnNext(_value);
+                        var value = _value;
+                        _value = default;
+                        ForwardOnNext(value);
                         ForwardOnCompleted();
                         ForwardOnCompleted();
                     }
                     }
                 }
                 }
@@ -77,9 +83,6 @@ namespace System.Reactive.Linq.ObservableImpl
                     : base(observer)
                     : base(observer)
                 {
                 {
                     _predicate = predicate;
                     _predicate = predicate;
-
-                    _value = default(TSource);
-                    _seenValue = false;
                 }
                 }
 
 
                 public override void OnNext(TSource value)
                 public override void OnNext(TSource value)
@@ -92,6 +95,7 @@ namespace System.Reactive.Linq.ObservableImpl
                     }
                     }
                     catch (Exception ex)
                     catch (Exception ex)
                     {
                     {
+                        _value = default;
                         ForwardOnError(ex);
                         ForwardOnError(ex);
                         return;
                         return;
                     }
                     }
@@ -103,6 +107,12 @@ namespace System.Reactive.Linq.ObservableImpl
                     }
                     }
                 }
                 }
 
 
+                public override void OnError(Exception error)
+                {
+                    _value = default;
+                    ForwardOnError(error);
+                }
+
                 public override void OnCompleted()
                 public override void OnCompleted()
                 {
                 {
                     if (!_seenValue)
                     if (!_seenValue)
@@ -111,7 +121,9 @@ namespace System.Reactive.Linq.ObservableImpl
                     }
                     }
                     else
                     else
                     {
                     {
-                        ForwardOnNext(_value);
+                        var value = _value;
+                        _value = default;
+                        ForwardOnNext(value);
                         ForwardOnCompleted();
                         ForwardOnCompleted();
                     }
                     }
                 }
                 }

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

@@ -26,7 +26,6 @@ namespace System.Reactive.Linq.ObservableImpl
                 public _(IObserver<TSource> observer)
                 public _(IObserver<TSource> observer)
                     : base(observer)
                     : base(observer)
                 {
                 {
-                    _value = default(TSource);
                 }
                 }
 
 
                 public override void OnNext(TSource value)
                 public override void OnNext(TSource value)
@@ -34,9 +33,17 @@ namespace System.Reactive.Linq.ObservableImpl
                     _value = value;
                     _value = value;
                 }
                 }
 
 
+                public override void OnError(Exception error)
+                {
+                    _value = default;
+                    ForwardOnError(error);
+                }
+
                 public override void OnCompleted()
                 public override void OnCompleted()
                 {
                 {
-                    ForwardOnNext(_value);
+                    var value = _value;
+                    _value = default;
+                    ForwardOnNext(value);
                     ForwardOnCompleted();
                     ForwardOnCompleted();
                 }
                 }
             }
             }
@@ -66,8 +73,6 @@ namespace System.Reactive.Linq.ObservableImpl
                     : base(observer)
                     : base(observer)
                 {
                 {
                     _predicate = predicate;
                     _predicate = predicate;
-
-                    _value = default(TSource);
                 }
                 }
 
 
                 public override void OnNext(TSource value)
                 public override void OnNext(TSource value)
@@ -80,6 +85,7 @@ namespace System.Reactive.Linq.ObservableImpl
                     }
                     }
                     catch (Exception ex)
                     catch (Exception ex)
                     {
                     {
+                        _value = default;
                         ForwardOnError(ex);
                         ForwardOnError(ex);
                         return;
                         return;
                     }
                     }
@@ -90,9 +96,17 @@ namespace System.Reactive.Linq.ObservableImpl
                     }
                     }
                 }
                 }
 
 
+                public override void OnError(Exception error)
+                {
+                    _value = default;
+                    ForwardOnError(error);
+                }
+
                 public override void OnCompleted()
                 public override void OnCompleted()
                 {
                 {
-                    ForwardOnNext(_value);
+                    var value = _value;
+                    _value = default;
+                    ForwardOnNext(value);
                     ForwardOnCompleted();
                     ForwardOnCompleted();
                 }
                 }
             }
             }

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

@@ -119,7 +119,7 @@ namespace System.Reactive.Linq.ObservableImpl
                         break;
                         break;
                 }
                 }
 
 
-                current = default(TSource);
+                current = default;
                 return false;
                 return false;
             }
             }
         }
         }

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

@@ -72,7 +72,7 @@ namespace System.Reactive.Linq.ObservableImpl
                         break;
                         break;
                 }
                 }
 
 
-                current = default(TSource);
+                current = default;
                 return false;
                 return false;
             }
             }
         }
         }

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

@@ -130,7 +130,7 @@ namespace System.Reactive.Linq.ObservableImpl
                         break;
                         break;
                 }
                 }
 
 
-                current = default(TSource);
+                current = default;
                 return false;
                 return false;
             }
             }
         }
         }

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

@@ -220,7 +220,7 @@ namespace System.Reactive
             /// <summary>
             /// <summary>
             /// Throws the exception.
             /// Throws the exception.
             /// </summary>
             /// </summary>
-            public override T Value { get { Exception.Throw(); return default(T); } }
+            public override T Value { get { Exception.Throw(); return default; } }
 
 
             /// <summary>
             /// <summary>
             /// Returns the exception.
             /// Returns the exception.

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

@@ -134,7 +134,7 @@ namespace System.Reactive.Subjects
                 if (observers == DISPOSED)
                 if (observers == DISPOSED)
                 {
                 {
                     _exception = null;
                     _exception = null;
-                    _value = default(T);
+                    _value = default;
                     ThrowDisposed();
                     ThrowDisposed();
                     break;
                     break;
                 }
                 }
@@ -167,7 +167,7 @@ namespace System.Reactive.Subjects
             var observers = Volatile.Read(ref _observers);
             var observers = Volatile.Read(ref _observers);
             if (observers == DISPOSED)
             if (observers == DISPOSED)
             {
             {
-                _value = default(T);
+                _value = default;
                 _exception = null;
                 _exception = null;
                 ThrowDisposed();
                 ThrowDisposed();
                 return;
                 return;
@@ -226,7 +226,7 @@ namespace System.Reactive.Subjects
                 var a = Volatile.Read(ref _observers);
                 var a = Volatile.Read(ref _observers);
                 if (a == DISPOSED)
                 if (a == DISPOSED)
                 {
                 {
-                    _value = default(T);
+                    _value = default;
                     _exception = null;
                     _exception = null;
                     ThrowDisposed();
                     ThrowDisposed();
                     return true;
                     return true;
@@ -339,7 +339,7 @@ namespace System.Reactive.Subjects
             if (Interlocked.Exchange(ref _observers, DISPOSED) != DISPOSED)
             if (Interlocked.Exchange(ref _observers, DISPOSED) != DISPOSED)
             {
             {
                 _exception = null;
                 _exception = null;
-                _value = default(T);
+                _value = default;
                 _hasValue = false;
                 _hasValue = false;
             }
             }
         }
         }

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

@@ -115,7 +115,7 @@ namespace System.Reactive.Subjects
             {
             {
                 if (_isDisposed)
                 if (_isDisposed)
                 {
                 {
-                    value = default(T);
+                    value = default;
                     return false;
                     return false;
                 }
                 }
                 else if (_exception != null)
                 else if (_exception != null)
@@ -275,7 +275,7 @@ namespace System.Reactive.Subjects
             {
             {
                 _isDisposed = true;
                 _isDisposed = true;
                 _observers = null;
                 _observers = null;
-                _value = default(T);
+                _value = default;
                 _exception = null;
                 _exception = null;
             }
             }
         }
         }

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

@@ -592,7 +592,7 @@ namespace System.Reactive.Subjects
 
 
             protected override void DisposeCore()
             protected override void DisposeCore()
             {
             {
-                _value = default(T);
+                _value = default;
             }
             }
         }
         }
 
 

+ 1 - 1
Rx.NET/Source/src/System.Reactive/Threading/Tasks/TaskObservableExtensions.cs

@@ -290,7 +290,7 @@ namespace System.Reactive.Threading.Tasks
         {
         {
             private readonly CancellationToken _ct;
             private readonly CancellationToken _ct;
             private readonly TaskCompletionSource<TResult> _tcs;
             private readonly TaskCompletionSource<TResult> _tcs;
-            private readonly CancellationTokenRegistration _ctr = default(CancellationTokenRegistration);
+            private readonly CancellationTokenRegistration _ctr = default;
 
 
             private bool _hasValue;
             private bool _hasValue;
             private TResult _lastValue;
             private TResult _lastValue;

+ 1 - 0
Rx.NET/Source/tests/Tests.System.Reactive/Tests.System.Reactive.csproj

@@ -2,6 +2,7 @@
   <PropertyGroup>
   <PropertyGroup>
     <TargetFrameworks>net46;netcoreapp2.0</TargetFrameworks>
     <TargetFrameworks>net46;netcoreapp2.0</TargetFrameworks>
     <NoWarn>$(NoWarn);CS0618</NoWarn>
     <NoWarn>$(NoWarn);CS0618</NoWarn>
+    <LangVersion>7.1</LangVersion>
   </PropertyGroup>
   </PropertyGroup>
   
   
   <ItemGroup>
   <ItemGroup>

+ 2 - 2
Rx.NET/Source/tests/Tests.System.Reactive/Tests/Linq/Observable/UsingTest.cs

@@ -48,7 +48,7 @@ namespace ReactiveTests.Tests
                     () =>
                     () =>
                     {
                     {
                         disposeInvoked++;
                         disposeInvoked++;
-                        disposable = default(MockDisposable);
+                        disposable = default;
                         return disposable;
                         return disposable;
                     },
                     },
                     d =>
                     d =>
@@ -56,7 +56,7 @@ namespace ReactiveTests.Tests
                         _d = d;
                         _d = d;
                         createInvoked++;
                         createInvoked++;
                         xs = scheduler.CreateColdObservable(
                         xs = scheduler.CreateColdObservable(
-                            OnNext<long>(100, scheduler.Clock),
+                            OnNext(100, scheduler.Clock),
                             OnCompleted<long>(200));
                             OnCompleted<long>(200));
                         return xs;
                         return xs;
                     }
                     }