I'm running Mono 2.0-1 on Linux. The implementation of Lookup extension method 
on IEnumerable does not seem to handle a case insensitive comparer correctly. 
The code does the following:

public static Lookup<TKey, TElement> ToLookup<TSource, TKey, TElement> (this 
IEnumerable<TSource> source,
                       Func<TSource, TKey> keySelector, Func<TSource, TElement> 
elementSelector, IEqualityComparer<TKey> comparer)
               {
                       if (source == null || keySelector == null || 
elementSelector == null)
                               throw new ArgumentNullException ();

                       Dictionary<TKey, List<TElement>> dictionary = new 
Dictionary<TKey, List<TElement>> (comparer ?? EqualityComparer<TKey>.Default);
                       foreach (TSource element in source) {
                               TKey key = keySelector (element);
                               if (key == null)
                                      throw new ArgumentNullException ();
                               if (!dictionary.ContainsKey (key))
                                      dictionary.Add (key, new List<TElement> 
());
                               dictionary [key].Add (elementSelector (element));
                       }
                       return new Lookup<TKey, TElement> (dictionary);
               }

The last line of the this method does not pass the comparer to the 
Lookup<TKey,TElement> class and hence all comparisons are done with the wrong 
comparer.

Please let me know if you'd like me to test a patch.

Thanks!
Bassam
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to