示例#1
0
        // `comparer` may be null
        public static IDictionary <TKey, TElement> ToKeyDictionary <TSource, TKey, TElement>(this IEnumerable <TSource> source, Func <TSource, TKey> keySelector, Func <TSource, TElement> elementSelector, IEqualityComparer <TKey> comparer)
        {
            Check.NotNull(source, keySelector, elementSelector);

            var elements   = source.Select(x => (keySelector(x), elementSelector(x)));
            var dictionary = new KeyDictionary <TKey, TElement>(comparer);

            dictionary.AddRange(elements, HinaLinq.GetCollectionLength(elements) ?? -1);
            return(dictionary);
        }