Created
May 5, 2015 21:00
-
-
Save cameronsjo/5963e1fe7a30bea1406f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static Dictionary<TKey, TValue> ToReverseDictionary<TModel, TKey, TValue>(this IEnumerable<TModel> collection, | |
| Func<TModel, IEnumerable<TKey>> keySelector, | |
| Func<TModel, TValue> valueSelector) | |
| { | |
| var dictionary = new Dictionary<TKey,TValue>(); | |
| foreach (var item in collection) | |
| { | |
| var value = valueSelector.Invoke(item); | |
| foreach (var key in keySelector.Invoke(item)) | |
| dictionary.Add(key, value); | |
| } | |
| return dictionary; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment