소스 검색

More code cosmetics.

Bart De Smet 8 년 전
부모
커밋
c695d246f2

+ 7 - 13
Ix.NET/Source/System.Interactive.Async/First.cs

@@ -53,8 +53,7 @@ namespace System.Linq
             if (predicate == null)
                 throw new ArgumentNullException(nameof(predicate));
 
-            return source.Where(predicate)
-                         .First(cancellationToken);
+            return source.Where(predicate).First(cancellationToken);
         }
 
         public static Task<TSource> First<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<bool>> predicate, CancellationToken cancellationToken)
@@ -64,8 +63,7 @@ namespace System.Linq
             if (predicate == null)
                 throw new ArgumentNullException(nameof(predicate));
 
-            return source.Where(predicate)
-                         .First(cancellationToken);
+            return source.Where(predicate).First(cancellationToken);
         }
 
         public static Task<TSource> FirstOrDefault<TSource>(this IAsyncEnumerable<TSource> source)
@@ -111,8 +109,7 @@ namespace System.Linq
             if (predicate == null)
                 throw new ArgumentNullException(nameof(predicate));
 
-            return source.Where(predicate)
-                         .FirstOrDefault(cancellationToken);
+            return source.Where(predicate).FirstOrDefault(cancellationToken);
         }
 
         public static Task<TSource> FirstOrDefault<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<bool>> predicate, CancellationToken cancellationToken)
@@ -122,8 +119,7 @@ namespace System.Linq
             if (predicate == null)
                 throw new ArgumentNullException(nameof(predicate));
 
-            return source.Where(predicate)
-                         .FirstOrDefault(cancellationToken);
+            return source.Where(predicate).FirstOrDefault(cancellationToken);
         }
 
         private static async Task<TSource> First_<TSource>(IAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
@@ -138,8 +134,7 @@ namespace System.Linq
 
             try
             {
-                if (await e.MoveNextAsync(cancellationToken)
-                           .ConfigureAwait(false))
+                if (await e.MoveNextAsync(cancellationToken).ConfigureAwait(false))
                 {
                     return e.Current;
                 }
@@ -164,8 +159,7 @@ namespace System.Linq
 
             try
             {
-                if (await e.MoveNextAsync(cancellationToken)
-                           .ConfigureAwait(false))
+                if (await e.MoveNextAsync(cancellationToken).ConfigureAwait(false))
                 {
                     return e.Current;
                 }
@@ -178,4 +172,4 @@ namespace System.Linq
             return default(TSource);
         }
     }
-}
+}

+ 1 - 1
Ix.NET/Source/System.Interactive.Async/IOrderedAsyncEnumerable.cs

@@ -1,7 +1,7 @@
 // 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. 
-using System;
+
 using System.Collections.Generic;
 
 namespace System.Linq

+ 2 - 4
Ix.NET/Source/System.Interactive.Async/IgnoreElements.cs

@@ -4,7 +4,6 @@
 
 using System.Collections.Generic;
 using System.Diagnostics;
-using System.Threading;
 using System.Threading.Tasks;
 
 namespace System.Linq
@@ -57,8 +56,7 @@ namespace System.Linq
                         goto case AsyncIteratorState.Iterating;
 
                     case AsyncIteratorState.Iterating:
-                        while (await enumerator.MoveNextAsync()
-                                               .ConfigureAwait(false))
+                        while (await enumerator.MoveNextAsync().ConfigureAwait(false))
                         {
                             // Do nothing, we're ignoring these elements
                         }
@@ -71,4 +69,4 @@ namespace System.Linq
             }
         }
     }
-}
+}

+ 4 - 8
Ix.NET/Source/System.Interactive.Async/Intersect.cs

@@ -4,7 +4,6 @@
 
 using System.Collections.Generic;
 using System.Diagnostics;
-using System.Threading;
 using System.Threading.Tasks;
 
 namespace System.Linq
@@ -98,15 +97,13 @@ namespace System.Linq
                             {
                                 // This is here so we don't need to call Task.WhenAll each time after the set is filled
                                 var moveNextTask = firstEnumerator.MoveNextAsync();
-                                await Task.WhenAll(moveNextTask, fillSetTask)
-                                          .ConfigureAwait(false);
+                                await Task.WhenAll(moveNextTask, fillSetTask).ConfigureAwait(false);
                                 setFilled = true;
                                 moveNext = moveNextTask.Result;
                             }
                             else
                             {
-                                moveNext = await firstEnumerator.MoveNextAsync()
-                                                                .ConfigureAwait(false);
+                                moveNext = await firstEnumerator.MoveNextAsync().ConfigureAwait(false);
                             }
 
                             if (moveNext)
@@ -129,8 +126,7 @@ namespace System.Linq
 
             private async Task FillSet()
             {
-                var array = await second.ToArray()
-                                        .ConfigureAwait(false);
+                var array = await second.ToArray().ConfigureAwait(false);
                 for (var i = 0; i < array.Length; i++)
                 {
                     set.Add(array[i]);
@@ -138,4 +134,4 @@ namespace System.Linq
             }
         }
     }
-}
+}

+ 15 - 16
Ix.NET/Source/System.Interactive.Async/Join.cs

@@ -42,7 +42,7 @@ namespace System.Linq
             if (resultSelector == null)
                 throw new ArgumentNullException(nameof(resultSelector));
 
-            return new JoinAsyncIterator<TOuter,TInner,TKey,TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, EqualityComparer<TKey>.Default);
+            return new JoinAsyncIterator<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, EqualityComparer<TKey>.Default);
         }
 
         internal sealed class JoinAsyncIterator<TOuter, TInner, TKey, TResult> : AsyncIterator<TResult>
@@ -90,17 +90,17 @@ namespace System.Linq
             }
 
             // State machine vars
-            Internal.Lookup<TKey, TInner> lookup;
-            int count;
-            TInner[] elements;
-            int index;
-            TOuter item;
+            private Internal.Lookup<TKey, TInner> lookup;
+            private int count;
+            private TInner[] elements;
+            private int index;
+            private TOuter item;
             private int mode;
 
-            const int State_If = 1;
-            const int State_DoLoop = 2;
-            const int State_For = 3;
-            const int State_While = 4;
+            private const int State_If = 1;
+            private const int State_DoLoop = 2;
+            private const int State_For = 3;
+            private const int State_While = 4;
 
             protected override async Task<bool> MoveNextCore()
             {
@@ -116,19 +116,19 @@ namespace System.Linq
                         switch (mode)
                         {
                             case State_If:
-                                if (await outerEnumerator.MoveNextAsync()
-                                                         .ConfigureAwait(false))
+                                if (await outerEnumerator.MoveNextAsync().ConfigureAwait(false))
                                 {
                                     lookup = await Internal.Lookup<TKey, TInner>.CreateForJoinAsync(inner, innerKeySelector, comparer).ConfigureAwait(false);
 
                                     if (lookup.Count != 0)
                                     {
                                         mode = State_DoLoop;
-                                        goto case State_DoLoop;   
+                                        goto case State_DoLoop;
                                     }
                                 }
 
                                 break;
+
                             case State_DoLoop:
                                 item = outerEnumerator.Current;
                                 var g = lookup.GetGrouping(outerKeySelector(item), create: false);
@@ -152,6 +152,7 @@ namespace System.Linq
                                 {
                                     mode = State_While;
                                 }
+
                                 return true;
 
                             case State_While:
@@ -161,12 +162,10 @@ namespace System.Linq
                                     goto case State_DoLoop;
                                 }
 
-                             
                                 break;
                         }
 
                         await DisposeAsync().ConfigureAwait(false);
-
                         break;
                 }
 
@@ -174,4 +173,4 @@ namespace System.Linq
             }
         }
     }
-}
+}

+ 7 - 11
Ix.NET/Source/System.Interactive.Async/Last.cs

@@ -53,8 +53,7 @@ namespace System.Linq
             if (predicate == null)
                 throw new ArgumentNullException(nameof(predicate));
 
-            return source.Where(predicate)
-                         .Last(cancellationToken);
+            return source.Where(predicate).Last(cancellationToken);
         }
 
         public static Task<TSource> Last<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<bool>> predicate, CancellationToken cancellationToken)
@@ -64,8 +63,7 @@ namespace System.Linq
             if (predicate == null)
                 throw new ArgumentNullException(nameof(predicate));
 
-            return source.Where(predicate)
-                         .Last(cancellationToken);
+            return source.Where(predicate).Last(cancellationToken);
         }
 
         public static Task<TSource> LastOrDefault<TSource>(this IAsyncEnumerable<TSource> source)
@@ -122,8 +120,7 @@ namespace System.Linq
             if (predicate == null)
                 throw new ArgumentNullException(nameof(predicate));
 
-            return source.Where(predicate)
-                         .LastOrDefault(cancellationToken);
+            return source.Where(predicate).LastOrDefault(cancellationToken);
         }
 
         private static async Task<TSource> Last_<TSource>(IAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
@@ -144,8 +141,7 @@ namespace System.Linq
 
             try
             {
-                while (await e.MoveNextAsync(cancellationToken)
-                              .ConfigureAwait(false))
+                while (await e.MoveNextAsync(cancellationToken).ConfigureAwait(false))
                 {
                     hasLast = true;
                     last = e.Current;
@@ -158,6 +154,7 @@ namespace System.Linq
 
             if (!hasLast)
                 throw new InvalidOperationException(Strings.NO_ELEMENTS);
+
             return last;
         }
 
@@ -179,8 +176,7 @@ namespace System.Linq
 
             try
             {
-                while (await e.MoveNextAsync(cancellationToken)
-                              .ConfigureAwait(false))
+                while (await e.MoveNextAsync(cancellationToken).ConfigureAwait(false))
                 {
                     hasLast = true;
                     last = e.Current;
@@ -194,4 +190,4 @@ namespace System.Linq
             return !hasLast ? default(TSource) : last;
         }
     }
-}
+}

+ 13 - 24
Ix.NET/Source/System.Interactive.Async/Lookup.cs

@@ -2,15 +2,12 @@
 // 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. 
 
-using System;
 using System.Collections;
 using System.Collections.Generic;
 using System.Diagnostics;
-using System.Linq;
 using System.Threading;
 using System.Threading.Tasks;
 
-
 namespace System.Linq
 {
     public static partial class AsyncEnumerable
@@ -74,8 +71,7 @@ namespace System.Linq
             if (comparer == null)
                 throw new ArgumentNullException(nameof(comparer));
 
-            var lookup = await Internal.Lookup<TKey, TElement>.CreateAsync(source, keySelector, elementSelector, comparer)
-                                       .ConfigureAwait(false);
+            var lookup = await Internal.Lookup<TKey, TElement>.CreateAsync(source, keySelector, elementSelector, comparer).ConfigureAwait(false);
 
             return lookup;
         }
@@ -188,7 +184,7 @@ namespace System.Linq.Internal
                 } while (g != _lastGrouping);
             }
         }
-        
+
         internal static async Task<Lookup<TKey, TElement>> CreateAsync<TSource>(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default(CancellationToken))
         {
             Debug.Assert(source != null);
@@ -201,11 +197,9 @@ namespace System.Linq.Internal
 
             try
             {
-                while (await enu.MoveNextAsync(cancellationToken)
-                                .ConfigureAwait(false))
+                while (await enu.MoveNextAsync(cancellationToken).ConfigureAwait(false))
                 {
-                    lookup.GetGrouping(keySelector(enu.Current), create: true)
-                          .Add(elementSelector(enu.Current));
+                    lookup.GetGrouping(keySelector(enu.Current), create: true).Add(elementSelector(enu.Current));
                 }
             }
             finally
@@ -216,7 +210,7 @@ namespace System.Linq.Internal
             return lookup;
         }
 
-        internal static async Task<Lookup<TKey, TElement>> CreateAsync(IAsyncEnumerable<TElement> source, Func<TElement, TKey> keySelector,  IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default(CancellationToken))
+        internal static async Task<Lookup<TKey, TElement>> CreateAsync(IAsyncEnumerable<TElement> source, Func<TElement, TKey> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default(CancellationToken))
         {
             Debug.Assert(source != null);
             Debug.Assert(keySelector != null);
@@ -227,8 +221,7 @@ namespace System.Linq.Internal
 
             try
             {
-                while (await enu.MoveNextAsync(cancellationToken)
-                                .ConfigureAwait(false))
+                while (await enu.MoveNextAsync(cancellationToken).ConfigureAwait(false))
                 {
                     lookup.GetGrouping(keySelector(enu.Current), create: true)
                           .Add(enu.Current);
@@ -250,14 +243,12 @@ namespace System.Linq.Internal
 
             try
             {
-                while (await enu.MoveNextAsync()
-                                .ConfigureAwait(false))
+                while (await enu.MoveNextAsync().ConfigureAwait(false))
                 {
                     var key = keySelector(enu.Current);
                     if (key != null)
                     {
-                        lookup.GetGrouping(key, create: true)
-                              .Add(enu.Current);
+                        lookup.GetGrouping(key, create: true).Add(enu.Current);
                     }
                 }
             }
@@ -272,7 +263,7 @@ namespace System.Linq.Internal
         internal Grouping<TKey, TElement> GetGrouping(TKey key, bool create)
         {
             var hashCode = InternalGetHashCode(key);
-            for (var g = _groupings[hashCode%_groupings.Length]; g != null; g = g._hashNext)
+            for (var g = _groupings[hashCode % _groupings.Length]; g != null; g = g._hashNext)
             {
                 if (g._hashCode == hashCode && _comparer.Equals(g._key, key))
                 {
@@ -287,7 +278,7 @@ namespace System.Linq.Internal
                     Resize();
                 }
 
-                var index = hashCode%_groupings.Length;
+                var index = hashCode % _groupings.Length;
                 var g = new Grouping<TKey, TElement>
                 {
                     _key = key,
@@ -358,20 +349,19 @@ namespace System.Linq.Internal
 
         private void Resize()
         {
-            var newSize = checked((Count*2) + 1);
+            var newSize = checked((Count * 2) + 1);
             var newGroupings = new Grouping<TKey, TElement>[newSize];
             var g = _lastGrouping;
             do
             {
                 g = g._next;
-                var index = g._hashCode%newSize;
+                var index = g._hashCode % newSize;
                 g._hashNext = newGroupings[index];
                 newGroupings[index] = g;
             } while (g != _lastGrouping);
 
             _groupings = newGroupings;
         }
-        
 
         public Task<int> GetCountAsync(bool onlyIfCheap, CancellationToken cancellationToken)
         {
@@ -418,6 +408,5 @@ namespace System.Linq.Internal
 
             return Task.FromResult(array);
         }
-
     }
-}
+}