Convert a helper method into an extension method
This commit is contained in:
parent
540a235514
commit
393057d33a
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue