Premature commonality gives premature optimization of the run for money as the root of evil. Conventionality is expensive , and expensive code has to be justified thanks to its clear advantages.
Therefore, I would use increased generality in your method based on specific scenarios. I can think of many ways to make your method more general:
Do not take a string dictionary into a string; take a dictionary of, say, strings for an arbitrary type.
Do not take Dictionary<...>; take it IDictionary<...>.
Do not use a dictionary. Take Action<K, V>, the action of which may be to introduce an element into the dictionary.
Do not accept the file name. In any case, you simply turn the file name into a stream, so start the stream first. Ask the caller to open the stream for you.
. , IEnumerable<...> .
? , T, K V. ? , , :
static void MakeMap<T, K, V>(this IEnumerable<T> sequence, Action<K, V> mapWriter, Func<T, K> keyExtractor, Func<T, V> valueExtractor)
{
foreach(var item in sequence)
mapWriter(keyExtractor(item), valueExtractor(item));
}
, , . , - . , ? ? . , , ? , .
? , ? . , , , . ? ? , ? , ? , :
public static ILookup<TKey, TElement> ToLookup<TSource, TKey, TElement>(
this IEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
Func<TSource, TElement> elementSelector,
IEqualityComparer<TKey> comparer) { ... }
, ToLookup(). , , , .