From 393057d33ab144bbe92f64dd3061a892e23c25c9 Mon Sep 17 00:00:00 2001 From: adelikat Date: Thu, 3 Jul 2014 17:01:10 +0000 Subject: [PATCH] Convert a helper method into an extension method --- .../Extensions/ControlExtensions.cs | 2 +- .../config/N64/N64ControllerSettingControl.cs | 2 +- BizHawk.Common/EnumHelper.cs | 13 ++++++++----- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs b/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs index 6b71774ae3..f64c15ed22 100644 --- a/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs +++ b/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs @@ -22,7 +22,7 @@ namespace BizHawk.Client.EmuHawk.ControlExtensions box.Items.AddRange( EnumHelper.GetDescriptions() .ToArray()); - box.SelectedItem = EnumHelper.GetDescription(enumVal); + box.SelectedItem = enumVal.GetDescription(); } } } diff --git a/BizHawk.Client.EmuHawk/config/N64/N64ControllerSettingControl.cs b/BizHawk.Client.EmuHawk/config/N64/N64ControllerSettingControl.cs index be37f7fe1e..9d2d7435c7 100644 --- a/BizHawk.Client.EmuHawk/config/N64/N64ControllerSettingControl.cs +++ b/BizHawk.Client.EmuHawk/config/N64/N64ControllerSettingControl.cs @@ -78,7 +78,7 @@ namespace BizHawk.Client.EmuHawk { var toSelect = PakTypeDropdown.Items .OfType() - .FirstOrDefault(item => item.ToString() == EnumHelper.GetDescription(value)); + .FirstOrDefault(item => item.ToString() == value.GetDescription()); PakTypeDropdown.SelectedItem = toSelect; Refresh(); diff --git a/BizHawk.Common/EnumHelper.cs b/BizHawk.Common/EnumHelper.cs index 9c16ef0df8..5366894628 100644 --- a/BizHawk.Common/EnumHelper.cs +++ b/BizHawk.Common/EnumHelper.cs @@ -8,11 +8,14 @@ namespace BizHawk.Common { public static class EnumHelper { - public static string GetDescription(object en) + /// + /// Gets the description attribute from an object + /// + public static string GetDescription(this object obj) { - Type type = en.GetType(); + Type type = obj.GetType(); - var memInfo = type.GetMember(en.ToString()); + var memInfo = type.GetMember(obj.ToString()); if (memInfo != null && memInfo.Length > 0) { @@ -24,7 +27,7 @@ namespace BizHawk.Common } } - return en.ToString(); + return obj.ToString(); } /// @@ -63,7 +66,7 @@ namespace BizHawk.Common foreach (var v in vals) { - yield return GetDescription(v); + yield return v.GetDescription(); } } }