فهرست منبع

2008-02-09 Miguel de Icaza <[email protected]>

	* Enumerable.cs (ToDictionary): Implement this overload. 

svn path=/trunk/mcs/; revision=95356
Miguel de Icaza 18 سال پیش
والد
کامیت
d99ebe3ed0
2فایلهای تغییر یافته به همراه14 افزوده شده و 3 حذف شده
  1. 4 0
      mcs/class/System.Core/System.Linq/ChangeLog
  2. 10 3
      mcs/class/System.Core/System.Linq/Enumerable.cs

+ 4 - 0
mcs/class/System.Core/System.Linq/ChangeLog

@@ -1,3 +1,7 @@
+2008-02-09  Miguel de Icaza  <[email protected]>
+
+	* Enumerable.cs (ToDictionary): Implement this overload. 
+
 2008-02-01  Jb Evain  <[email protected]>
 
 	* Queryable.cs, Check.cs: integrate GHOP work from

+ 10 - 3
mcs/class/System.Core/System.Linq/Enumerable.cs

@@ -2314,9 +2314,16 @@ namespace System.Linq
 		public static Dictionary<TKey, TSource> ToDictionary<TSource, TKey> (this IEnumerable<TSource> source,
 				Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
 		{
-			throw new NotImplementedException ();
-			// FIXME: compiler issue
-			//return ToDictionary (source, keySelector, (a) => a, comparer);
+			Check.SourceAndKeySelector (source, keySelector);
+
+			if (comparer == null)
+				comparer = EqualityComparer<TKey>.Default;
+			
+			var dict = new Dictionary<TKey, TSource> (comparer);
+			foreach (var e in source)
+				dict.Add (keySelector (e), e);
+
+			return dict;
 		}
 
 		#endregion