/// <summary>Creates a <see cref="ConcurrentDictionary{TKey,TValue}" /> from an <see cref="IEnumerable{T}" /> according to a specified key selector function.</summary>
        /// <param name="source">An <see cref="IEnumerable{T}" /> to create a <see cref="ConcurrentDictionary{TKey,TValue}" /> from.</param>
        /// <param name="keySelector">A function to extract a key from each element.</param>
        /// <param name="valueSelector">A function to extract a value from each element.</param>
        /// <param name="comparer">An <see cref="IEqualityComparer{T}" /> to compare keys.</param>
        public static ConcurrentDictionary <TKey, TElement> ToConcurrentDictionary <TSource, TKey, TElement>(this IEnumerable <TSource> source, Func <TSource, TKey> keySelector, Func <TSource, TElement> valueSelector, IEqualityComparer <TKey> comparer)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (keySelector == null)
            {
                throw new ArgumentNullException(nameof(keySelector));
            }
            if (valueSelector == null)
            {
                throw new ArgumentNullException(nameof(valueSelector));
            }

            var dictionary = new ConcurrentDictionary <TKey, TElement>(comparer);

            dictionary.AddOrUpdateRange(source, keySelector, valueSelector);

            return(dictionary);
        }