private static void ApplyEnum <TEnum>([NotNull] ComboBox box, ConfigKey key, TEnum def) where TEnum : struct { if (box == null) { throw new ArgumentNullException("box"); } if (!typeof(TEnum).IsEnum) { throw new ArgumentException("Enum type required"); } try { if (key.IsBlank()) { box.SelectedIndex = (int)(object)def; } else { box.SelectedIndex = (int)Enum.Parse(typeof(TEnum), key.GetString(), true); } } catch (ArgumentException) { box.SelectedIndex = (int)(object)def; } }
static void ApplyEnum <TEnum>(ComboBox box, ConfigKey key, TEnum def) where TEnum : struct { #if DEBUG if (!typeof(TEnum).IsEnum) { throw new ArgumentException("Enum type required", "TEnum"); } #endif try { if (key.IsBlank()) { box.SelectedIndex = (int)(object)def; } else { box.SelectedIndex = (int)Enum.Parse(typeof(TEnum), Config.GetString(key), true); } } catch (ArgumentException) { box.SelectedIndex = (int)(object)def; } }