Przeglądaj źródła

Remove usage of Disposable.Utils.SetSingle.

Daniel Weber 5 lat temu
rodzic
commit
7853d67679

+ 0 - 20
Rx.NET/Source/src/System.Reactive/Disposables/Disposable.Utils.cs

@@ -43,26 +43,6 @@ namespace System.Reactive.Disposables
                 : current;
                 : current;
         }
         }
 
 
-        /// <summary>
-        /// Assigns <paramref name="value" /> to <paramref name="fieldRef" />.
-        /// </summary>
-        /// <returns>true if <paramref name="fieldRef" /> was assigned to <paramref name="value" /> and has not
-        /// been assigned before.</returns>
-        /// <returns>false if <paramref name="fieldRef" /> has been already disposed.</returns>
-        /// <exception cref="InvalidOperationException"><paramref name="fieldRef" /> has already been assigned a value.</exception>
-        internal static bool SetSingle([NotNullIfNotNull("value")] ref IDisposable? fieldRef, IDisposable? value)
-        {
-            var result = TrySetSingle(ref fieldRef, value);
-
-            if (result == TrySetSingleResult.AlreadyAssigned)
-            {
-                throw new InvalidOperationException(Strings_Core.DISPOSABLE_ALREADY_ASSIGNED);
-            }
-
-            return result == TrySetSingleResult.Success;
-        }
-
-        /// <summary>
         /// Tries to assign <paramref name="value" /> to <paramref name="fieldRef" />.
         /// Tries to assign <paramref name="value" /> to <paramref name="fieldRef" />.
         /// </summary>
         /// </summary>
         /// <returns>A <see cref="TrySetSingleResult"/> value indicating the outcome of the operation.</returns>
         /// <returns>A <see cref="TrySetSingleResult"/> value indicating the outcome of the operation.</returns>

+ 9 - 1
Rx.NET/Source/src/System.Reactive/Disposables/SingleAssignmentDisposableValue.cs

@@ -24,7 +24,15 @@ namespace System.Reactive.Disposables
         public IDisposable? Disposable
         public IDisposable? Disposable
         {
         {
             get => Disposables.Disposable.GetValueOrDefault(ref _current);
             get => Disposables.Disposable.GetValueOrDefault(ref _current);
-            set => Disposables.Disposable.SetSingle(ref _current, value);
+            set
+            {
+                var result = Disposables.Disposable.TrySetSingle(ref _current, value);
+
+                if (result == TrySetSingleResult.AlreadyAssigned)
+                {
+                    throw new InvalidOperationException(Strings_Core.DISPOSABLE_ALREADY_ASSIGNED);
+                }
+            }
         }
         }
 
 
         /// <summary>
         /// <summary>

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

@@ -70,7 +70,7 @@ namespace System.Reactive.Linq.ObservableImpl
                     var longRunning = _loopScheduler.AsLongRunning();
                     var longRunning = _loopScheduler.AsLongRunning();
                     if (longRunning != null)
                     if (longRunning != null)
                     {
                     {
-                        Disposable.SetSingle(ref _loopDisposable, longRunning.ScheduleLongRunning(this, static (@this, c) => @this.Loop(c)));
+                        Disposable.TrySetSingle(ref _loopDisposable, longRunning.ScheduleLongRunning(this, static (@this, c) => @this.Loop(c)));
                     }
                     }
                     else
                     else
                     {
                     {
@@ -186,7 +186,7 @@ namespace System.Reactive.Linq.ObservableImpl
                     var longRunning = _loopScheduler.AsLongRunning();
                     var longRunning = _loopScheduler.AsLongRunning();
                     if (longRunning != null)
                     if (longRunning != null)
                     {
                     {
-                        Disposable.SetSingle(ref _loopDisposable, longRunning.ScheduleLongRunning(this, static (@this, c) => @this.Loop(c)));
+                        Disposable.TrySetSingle(ref _loopDisposable, longRunning.ScheduleLongRunning(this, static (@this, c) => @this.Loop(c)));
                     }
                     }
                     else
                     else
                     {
                     {