Browse Source

Proper layering of some StartWith overload that was added by a clueless person.

Bart De Smet 10 years ago
parent
commit
f2ec644dcf

+ 2 - 0
Rx.NET/Source/System.Reactive.Linq/Reactive/Linq/IQueryLanguage.cs

@@ -669,6 +669,8 @@ namespace System.Reactive.Linq
         IObservable<TSource> SkipLast<TSource>(IObservable<TSource> source, int count);
         IObservable<TSource> StartWith<TSource>(IObservable<TSource> source, params TSource[] values);
         IObservable<TSource> StartWith<TSource>(IObservable<TSource> source, IScheduler scheduler, params TSource[] values);
+        IObservable<TSource> StartWith<TSource>(IObservable<TSource> source, IEnumerable<TSource> values);
+        IObservable<TSource> StartWith<TSource>(IObservable<TSource> source, IScheduler scheduler, IEnumerable<TSource> values);
         IObservable<TSource> TakeLast<TSource>(IObservable<TSource> source, int count);
         IObservable<TSource> TakeLast<TSource>(IObservable<TSource> source, int count, IScheduler scheduler);
         IObservable<IList<TSource>> TakeLastBuffer<TSource>(IObservable<TSource> source, int count);

+ 7 - 14
Rx.NET/Source/System.Reactive.Linq/Reactive/Linq/Observable.Single.cs

@@ -521,13 +521,7 @@ namespace System.Reactive.Linq
             if (values == null)
                 throw new ArgumentNullException("values");
 
-            TSource[] valueArray = values as TSource[];
-            if (valueArray == null)
-            {
-                List<TSource> valueList = new List<TSource>(values);
-                valueArray = valueList.ToArray();
-            }
-            return s_impl.StartWith<TSource>(source, valueArray);
+            return s_impl.StartWith<TSource>(source, values);
         }
 
         /// <summary>
@@ -562,6 +556,11 @@ namespace System.Reactive.Linq
         /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> or <paramref name="values"/> is null.</exception>
         public static IObservable<TSource> StartWith<TSource>(this IObservable<TSource> source, IScheduler scheduler, IEnumerable<TSource> values)
         {
+            //
+            // NOTE: For some reason, someone introduced this signature which is inconsistent with the Rx pattern of putting the IScheduler last.
+            //       We can't change it at this point because of compatibility.
+            //
+
             if (source == null)
                 throw new ArgumentNullException("source");
             if (scheduler == null)
@@ -569,13 +568,7 @@ namespace System.Reactive.Linq
             if (values == null)
                 throw new ArgumentNullException("values");
 
-            TSource[] valueArray = values as TSource[];
-            if (valueArray == null)
-            {
-                List<TSource> valueList = new List<TSource>(values);
-                valueArray = valueList.ToArray();
-            }
-            return s_impl.StartWith<TSource>(source, scheduler, valueArray);
+            return s_impl.StartWith<TSource>(source, scheduler, values);
         }
 
         #endregion

+ 7 - 3
Rx.NET/Source/System.Reactive.Linq/Reactive/Linq/QueryLanguage.Single.cs

@@ -503,15 +503,19 @@ namespace System.Reactive.Linq
 
         public virtual IObservable<TSource> StartWith<TSource>(IObservable<TSource> source, IScheduler scheduler, IEnumerable<TSource> values)
         {
-            if (values == null)
-                throw new ArgumentNullException("values");
+            //
+            // NOTE: For some reason, someone introduced this signature in the Observable class, which is inconsistent with the Rx pattern
+            //       of putting the IScheduler last. It also wasn't wired up through IQueryLanguage. When introducing this method in the
+            //       IQueryLanguage interface, we went for consistency with the public API, hence the odd position of the IScheduler.
+            //
 
             var valueArray = values as TSource[];
             if (valueArray == null)
             {
-                List<TSource> valueList = new List<TSource>(values);
+                var valueList = new List<TSource>(values);
                 valueArray = valueList.ToArray();
             }
+
             return StartWith_<TSource>(source, scheduler, valueArray);
         }