예제 #1
0
        public static CollectionDictionary <TKey, TElement> ToCollectionDictionary <TSource, TKey, TElement>(this IEnumerable <TSource> source,
                                                                                                             Func <TSource, TKey> keySelector, Func <TSource, TElement> elementSelector) where TElement : class
        {
            var result = new CollectionDictionary <TKey, TElement>();

            foreach (var element in source)
            {
                result.AddValue(keySelector(element), elementSelector(element), true);
            }

            return(result);
        }
예제 #2
0
        public static CollectionDictionary <TKey, TElement> MergeWith <TKey, TElement>(this CollectionDictionary <TKey, TElement> collectionDictionary, params IDictionary <TKey, TElement>[] dictionaries)
        {
            var result = new CollectionDictionary <TKey, TElement>(collectionDictionary);

            foreach (var dict in dictionaries)
            {
                foreach (var x in dict)
                {
                    result.AddValue(x.Key, x.Value);
                }
            }

            return(result);
        }