Bladeren bron

Resolve the source of confusion that is DefaultDisposable: Its name is poorly chosen, Disposable.Empty points to DefaultDisposable.Instance and should be the only no-op-disposable used throughout the code. Thus, DefaultDisposable is nested and renamed. (#555)

Daniel C. Weber 7 jaren geleden
bovenliggende
commit
96e7ce33ad

+ 0 - 29
Rx.NET/Source/src/System.Reactive/Disposables/DefaultDisposable.cs

@@ -1,29 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// 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. 
-
-namespace System.Reactive.Disposables
-{
-    /// <summary>
-    /// Represents a disposable that does nothing on disposal.
-    /// </summary>
-    internal sealed class DefaultDisposable : IDisposable
-    {
-        /// <summary>
-        /// Singleton default disposable.
-        /// </summary>
-        public static readonly DefaultDisposable Instance = new DefaultDisposable();
-
-        private DefaultDisposable()
-        {
-        }
-
-        /// <summary>
-        /// Does nothing.
-        /// </summary>
-        public void Dispose()
-        {
-            // no op
-        }
-    }
-}

+ 25 - 2
Rx.NET/Source/src/System.Reactive/Disposables/Disposable.cs

@@ -11,10 +11,33 @@ namespace System.Reactive.Disposables
     /// </summary>
     public static class Disposable
     {
+        /// <summary>
+        /// Represents a disposable that does nothing on disposal.
+        /// </summary>
+        private sealed class EmptyDisposable : IDisposable
+        {
+            /// <summary>
+            /// Singleton default disposable.
+            /// </summary>
+            public static readonly EmptyDisposable Instance = new EmptyDisposable();
+
+            private EmptyDisposable()
+            {
+            }
+
+            /// <summary>
+            /// Does nothing.
+            /// </summary>
+            public void Dispose()
+            {
+                // no op
+            }
+        }
+
         /// <summary>
         /// Gets the disposable that does nothing when disposed.
         /// </summary>
-        public static IDisposable Empty => DefaultDisposable.Instance;
+        public static IDisposable Empty => EmptyDisposable.Instance;
 
         /// <summary>
         /// Creates a disposable object that invokes the specified action when disposed.
@@ -50,7 +73,7 @@ namespace System.Reactive.Disposables
             var current = Volatile.Read(ref fieldRef);
 
             return current == BooleanDisposable.True
-                ? DefaultDisposable.Instance
+                ? EmptyDisposable.Instance
                 : current;
         }
 

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

@@ -47,7 +47,7 @@ namespace System.Reactive.Disposables
 
                 if (current == BooleanDisposable.True)
                 {
-                    return DefaultDisposable.Instance; // Don't leak the sentinel value.
+                    return Disposables.Disposable.Empty; // Don't leak the sentinel value.
                 }
 
                 return current;