Remove duplicate code in SettingsEnumDropdown

This commit is contained in:
DrabWeb
2017-05-19 17:04:59 -03:00
parent 5b2c74be50
commit 1d61fc84c7
2 changed files with 10 additions and 25 deletions

View File

@ -13,12 +13,12 @@ namespace osu.Game.Graphics.UserInterface
public OsuEnumDropdown()
{
if (!typeof(T).IsEnum)
throw new InvalidOperationException("SettingsDropdown only supports enums as the generic type argument");
throw new InvalidOperationException("OsuEnumDropdown only supports enums as the generic type argument");
List<KeyValuePair<string, T>> items = new List<KeyValuePair<string, T>>();
foreach(var val in (T[])Enum.GetValues(typeof(T)))
{
var field = typeof(T).GetField(Enum.GetName(typeof(T), val));
var field = typeof(T).GetField(Enum.GetName(typeof(T), val));
items.Add(
new KeyValuePair<string, T>(
field.GetCustomAttribute<DescriptionAttribute>()?.Description ?? Enum.GetName(typeof(T), val),