using System; using System.Collections.Generic; namespace WixIncludeMake { public static class LinqHelpers { public static Dictionary ToSafeDictionary(this IEnumerable source, Func keySelector, Func valueSelector, string locationName) { if (source == null) throw new ArgumentNullException("source"); if (keySelector == null) throw new ArgumentNullException("keySelector"); if (valueSelector == null) throw new ArgumentNullException("valueSelector"); Dictionary res = new Dictionary(); foreach (TSource el in source) { TKey k = keySelector(el); TValue v = valueSelector(el); if (res.ContainsKey(k)) Console.WriteLine("*** Warning, duplicate key: " + k.ToString() + " in " + locationName); else res.Add(k, v); } return res; } } }