浏览代码

Adding some checked arithmetic.

Bart De Smet 10 年之前
父节点
当前提交
2d07433f6f

+ 4 - 4
Ix.NET/Source/System.Interactive.Async/AsyncEnumerable.Aggregates.cs

@@ -130,7 +130,7 @@ namespace System.Linq
             if (source == null)
                 throw new ArgumentNullException("source");
 
-            return source.Aggregate(0, (c, _) => c + 1, cancellationToken);
+            return source.Aggregate(0, (c, _) => checked(c + 1), cancellationToken);
         }
 
         public static Task<int> Count<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate, CancellationToken cancellationToken)
@@ -140,7 +140,7 @@ namespace System.Linq
             if (predicate == null)
                 throw new ArgumentNullException("predicate");
 
-            return source.Where(predicate).Aggregate(0, (c, _) => c + 1, cancellationToken);
+            return source.Where(predicate).Aggregate(0, (c, _) => checked(c + 1), cancellationToken);
         }
 
         public static Task<long> LongCount<TSource>(this IAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
@@ -148,7 +148,7 @@ namespace System.Linq
             if (source == null)
                 throw new ArgumentNullException("source");
 
-            return source.Aggregate(0L, (c, _) => c + 1, cancellationToken);
+            return source.Aggregate(0L, (c, _) => checked(c + 1), cancellationToken);
         }
 
         public static Task<long> LongCount<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate, CancellationToken cancellationToken)
@@ -158,7 +158,7 @@ namespace System.Linq
             if (predicate == null)
                 throw new ArgumentNullException("predicate");
 
-            return source.Where(predicate).Aggregate(0L, (c, _) => c + 1, cancellationToken);
+            return source.Where(predicate).Aggregate(0L, (c, _) => checked(c + 1), cancellationToken);
         }
 
         public static Task<bool> All<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate, CancellationToken cancellationToken)

+ 5 - 5
Ix.NET/Source/System.Interactive.Async/AsyncEnumerable.Single.cs

@@ -87,7 +87,7 @@ namespace System.Linq
                                 {
                                     try
                                     {
-                                        current = selector(e.Current, index++);
+                                        current = selector(e.Current, checked(index++));
                                     }
                                     catch (Exception ex)
                                     {
@@ -204,7 +204,7 @@ namespace System.Linq
                                 var b = false;
                                 try
                                 {
-                                    b = predicate(e.Current, index++);
+                                    b = predicate(e.Current, checked(index++));
                                 }
                                 catch (Exception ex)
                                 {
@@ -393,7 +393,7 @@ namespace System.Linq
                             {
                                 try
                                 {
-                                    ie = selector(e.Current, index++).GetEnumerator();
+                                    ie = selector(e.Current, checked(index++)).GetEnumerator();
                                     inner(tcs, ct);
                                 }
                                 catch (Exception ex)
@@ -586,7 +586,7 @@ namespace System.Linq
 
                                     try
                                     {
-                                        b = predicate(e.Current, index++);
+                                        b = predicate(e.Current, checked(index++));
                                     }
                                     catch (Exception ex)
                                     {
@@ -758,7 +758,7 @@ namespace System.Linq
                                     var result = false;
                                     try
                                     {
-                                        result = predicate(e.Current, index++);
+                                        result = predicate(e.Current, checked(index++));
                                     }
                                     catch (Exception ex)
                                     {