// Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; using System.ComponentModel; using System.Reflection; using System.Collections.Generic; namespace osu.Game.Graphics.UserInterface { public class OsuEnumDropdown : OsuDropdown { public OsuEnumDropdown() { if (!typeof(T).IsEnum) throw new InvalidOperationException("OsuEnumDropdown only supports enums as the generic type argument"); List> items = new List>(); foreach(var val in (T[])Enum.GetValues(typeof(T))) { var field = typeof(T).GetField(Enum.GetName(typeof(T), val)); items.Add( new KeyValuePair( field.GetCustomAttribute()?.Description ?? Enum.GetName(typeof(T), val), val ) ); } Items = items; } } }