I have filed Bug 601101 https://bugzilla.novell.com/show_bug.cgi?id=601101 for 
this issue. In addition; I have attached a patch which resolves the issue. That 
said, I'm not really sure this patch is the most desirable way to fix the bug. 
If you would like to use the patch I release it under the MIT/X11 License.

Also worth noting is that a Dictionary is used to create the groups, but 
Dictionary as defined by MSDN does not preserve element ordering. It appears 
that the mono implementation of Dictionary does and that is why it is used, is 
this correct?

Thanks,

Richard Kiene
Index: System.Linq/Enumerable.cs
===================================================================
--- System.Linq/Enumerable.cs   (revision 147679)
+++ System.Linq/Enumerable.cs   (working copy)
@@ -52,11 +52,11 @@
                static class Function<T> {
                        public static readonly Func<T, T> Identity = (t) => t;
                }
-               
+
                static class EmptyOf<T> {
                        public static readonly T[] Instance = new T [0];
                }
-               
+
                static class ReadOnlyCollectionOf<T> {
                        public static readonly ReadOnlyCollection<T> Empty = 
new ReadOnlyCollection<T> (EmptyOf<T>.Instance);
                }
@@ -707,6 +707,12 @@
                                yield return grouping;
                                counter++;
                        }
+
+                       if (counter == nullCounter) {
+                               Grouping<TKey, TSource> nullGroup = new 
Grouping<TKey, TSource> (default (TKey), nullList);
+                               yield return nullGroup;
+                               counter++;
+                       }
                }
 
                public static IEnumerable<IGrouping<TKey, TElement>> 
GroupBy<TSource, TKey, TElement> (this IEnumerable<TSource> source,
@@ -2167,17 +2173,17 @@
                        Check.SourceAndKeyElementSelectors (source, 
keySelector, elementSelector);
 
                        List<TElement> nullKeyElements = null;
-                       
+
                        var dictionary = new Dictionary<TKey, List<TElement>> 
(comparer ?? EqualityComparer<TKey>.Default);
                        foreach (var element in source) {
                                var key = keySelector (element);
 
                                List<TElement> list;
-                               
+
                                if (key == null) {
                                        if (nullKeyElements == null)
                                                nullKeyElements = new 
List<TElement> ();
-                                       
+
                                        list = nullKeyElements;
                                } else if (!dictionary.TryGetValue (key, out 
list)) {
                                        list = new List<TElement> ();
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to