瀏覽代碼

Check for existing type

Oren Novotny 9 年之前
父節點
當前提交
c94cff833e
共有 1 個文件被更改,包括 7 次插入0 次删除
  1. 7 0
      Ix.NET/Source/System.Interactive.Async/Cast.cs

+ 7 - 0
Ix.NET/Source/System.Interactive.Async/Cast.cs

@@ -16,6 +16,13 @@ namespace System.Linq
             if (source == null)
                 throw new ArgumentNullException(nameof(source));
 
+            // Check to see if it already is and short-circuit
+            var typedSource = source as IAsyncEnumerable<TResult>;
+            if (typedSource != null)
+            {
+                return typedSource;
+            }
+
             return source.Select(x => (TResult)x);
         }