Browse Source

Use C# 8.0 in ElementAt.

Bart De Smet 7 years ago
parent
commit
3e63666486

+ 12 - 0
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ElementAt.cs

@@ -37,6 +37,17 @@ namespace System.Linq
 
                     if (_index >= 0)
                     {
+#if CSHARP8 && AETOR_HAS_CT // CS0656 Missing compiler required member 'System.Collections.Generic.IAsyncEnumerable`1.GetAsyncEnumerator'
+                        await foreach (TSource item in _source.WithCancellation(_cancellationToken).ConfigureAwait(false))
+                        {
+                            if (_index == 0)
+                            {
+                                return item;
+                            }
+
+                            _index--;
+                        }
+#else
                         var e = _source.GetAsyncEnumerator(_cancellationToken);
 
                         try
@@ -55,6 +66,7 @@ namespace System.Linq
                         {
                             await e.DisposeAsync().ConfigureAwait(false);
                         }
+#endif
                     }
                 }
 

+ 12 - 0
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ElementAtOrDefault.cs

@@ -40,6 +40,17 @@ namespace System.Linq
                     }
                     else
                     {
+#if CSHARP8 && AETOR_HAS_CT // CS0656 Missing compiler required member 'System.Collections.Generic.IAsyncEnumerable`1.GetAsyncEnumerator'
+                        await foreach (TSource item in _source.WithCancellation(_cancellationToken).ConfigureAwait(false))
+                        {
+                            if (_index == 0)
+                            {
+                                return item;
+                            }
+
+                            _index--;
+                        }
+#else
                         var e = _source.GetAsyncEnumerator(_cancellationToken);
 
                         try
@@ -58,6 +69,7 @@ namespace System.Linq
                         {
                             await e.DisposeAsync().ConfigureAwait(false);
                         }
+#endif
                     }
                 }