Last active
December 21, 2015 06:39
-
-
Save ritalin/6265558 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 IDictionary<TK, TV> EnumToMap<TEnum>() { | |
return EnumToMap(typeof(TEnum)); | |
} | |
public static IDictionary<TK, TV> EnumToMap(params Type[] enumTypes) { | |
return | |
enumTypes | |
.SelectMany(enumType => { | |
Enum.GetValues(enumType) | |
.Select(v => new { Key = Enum.GetName(enumType, Value = (TV)v }); | |
}) | |
.ToDictionary(entry => entry.Key, entry => entry.Value); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment