Skip to content

Instantly share code, notes, and snippets.

@ritalin
Last active December 21, 2015 06:39
Show Gist options
  • Save ritalin/6265558 to your computer and use it in GitHub Desktop.
Save ritalin/6265558 to your computer and use it in GitHub Desktop.
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