Fix null sessions in HttpContextWrapper.Session
[mono.git] / mcs / class / System.Core / System.Linq.Parallel.QueryNodes / QueryZipNode.cs
index ae693172f4a60c2beb16e67886f3dffd39bc3017..9b9b475ac6807aa71047e8b93ff111d998d485d8 100644 (file)
@@ -31,7 +31,7 @@ using System.Linq;
 using System.Collections.Generic;
 using System.Collections.Concurrent;
 
-namespace System.Linq
+namespace System.Linq.Parallel.QueryNodes
 {
        internal class QueryZipNode<TFirst, TSecond, TResult> : QueryMuxNode<TFirst, TSecond, TResult>
        {
@@ -43,6 +43,12 @@ namespace System.Linq
                        this.resultSelector = resultSelector;
                }
 
+               // If strict is set to `true', the zip'ing process will throw if sequences length mistmatches
+               public bool Strict {
+                       get;
+                       set;
+               }
+
                internal override IEnumerable<TResult> GetSequential ()
                {
                        IEnumerable<TFirst> first = Parent.GetSequential ();
@@ -61,7 +67,7 @@ namespace System.Linq
 
                        return first
                                .Select ((f, i) => GetEnumerable (f, second[i]))
-                               .ToArray ();
+                               .ToList ();
                }
 
                IEnumerable<TResult> GetEnumerable (IEnumerable<TFirst> first, IEnumerable<TSecond> second)
@@ -71,11 +77,17 @@ namespace System.Linq
 
                        try {
                                while (eFirst.MoveNext ()) {
-                                       if (!eSecond.MoveNext ())
-                                               yield break;
+                                       if (!eSecond.MoveNext ()) {
+                                               if (Strict)
+                                                       throw new QueryZipException ();
+                                               else
+                                                       yield break;
+                                       }
 
                                        yield return resultSelector (eFirst.Current, eSecond.Current);
                                }
+                               if (Strict && eSecond.MoveNext ())
+                                       throw new QueryZipException ();
                        } finally {
                                eFirst.Dispose ();
                                eSecond.Dispose ();
@@ -100,7 +112,7 @@ namespace System.Linq
 
                        return first
                                .Select ((f, i) => GetEnumerable (f, second[i], i , store1, store2, barrier))
-                               .ToArray ();
+                               .ToList ();
                }
 
                IEnumerable<KeyValuePair<long, TResult>> GetEnumerable (IEnumerable<KeyValuePair<long, TFirst>> first,
@@ -115,8 +127,12 @@ namespace System.Linq
 
                        try {
                                while (eFirst.MoveNext ()) {
-                                       if (!eSecond.MoveNext ())
-                                               break;
+                                       if (!eSecond.MoveNext ()) {
+                                               if (Strict)
+                                                       throw new QueryZipException ();
+                                               else
+                                                       break;
+                                       }
 
                                        store1[index] = eFirst.Current;
                                        store2[index] = eSecond.Current;
@@ -126,6 +142,8 @@ namespace System.Linq
                                        yield return new KeyValuePair<long, TResult> (store1[index].Key,
                                                                                      resultSelector (store1[index].Value, store2[index].Value));
                                }
+                               if (Strict && eSecond.MoveNext ())
+                                       throw new QueryZipException ();
                        } finally {
                                barrier.RemoveParticipant ();
                                eFirst.Dispose ();
@@ -133,6 +151,10 @@ namespace System.Linq
                        }
                }
        }
+
+       internal class QueryZipException : Exception
+       {
+       }
 }
 
 #endif