Convert a helper method into an extension method

This commit is contained in:
adelikat 2014-07-03 17:01:10 +00:00
parent 540a235514
commit 393057d33a
3 changed files with 10 additions and 7 deletions

View File

@ -22,7 +22,7 @@ namespace BizHawk.Client.EmuHawk.ControlExtensions
box.Items.AddRange(
EnumHelper.GetDescriptions<T>()
.ToArray());
box.SelectedItem = EnumHelper.GetDescription(enumVal);
box.SelectedItem = enumVal.GetDescription();
}
}
}

View File

@ -78,7 +78,7 @@ namespace BizHawk.Client.EmuHawk
{
var toSelect = PakTypeDropdown.Items
.OfType<object>()
.FirstOrDefault(item => item.ToString() == EnumHelper.GetDescription(value));
.FirstOrDefault(item => item.ToString() == value.GetDescription());
PakTypeDropdown.SelectedItem = toSelect;
Refresh();

View File

@ -8,11 +8,14 @@ namespace BizHawk.Common
{
public static class EnumHelper
{
public static string GetDescription(object en)
/// <summary>
/// Gets the description attribute from an object
/// </summary>
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();
}
/// <summary>
@ -63,7 +66,7 @@ namespace BizHawk.Common
foreach (var v in vals)
{
yield return GetDescription(v);
yield return v.GetDescription();
}
}
}