More extension reorg
This commit is contained in:
parent
90ab7d17b1
commit
ebee9b9ded
|
@ -68,8 +68,9 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
if (PakTypeDropdown.SelectedItem != null) // Null check for designer
|
if (PakTypeDropdown.SelectedItem != null) // Null check for designer
|
||||||
{
|
{
|
||||||
return EnumHelper.GetValueFromDescription<N64ControllerSettings.N64ControllerPakType>(
|
return PakTypeDropdown.SelectedItem
|
||||||
PakTypeDropdown.SelectedItem.ToString());
|
.ToString()
|
||||||
|
.GetEnumFromDescription<N64ControllerSettings.N64ControllerPakType>();
|
||||||
}
|
}
|
||||||
|
|
||||||
return N64ControllerSettings.N64ControllerPakType.NO_PAK;
|
return N64ControllerSettings.N64ControllerPakType.NO_PAK;
|
||||||
|
|
|
@ -4,9 +4,11 @@ using System.Linq;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
using BizHawk.Common.StringExtensions;
|
using BizHawk.Common.StringExtensions;
|
||||||
|
using BizHawk.Common.ReflectionExtensions;
|
||||||
using BizHawk.Emulation.Cores.Nintendo.N64;
|
using BizHawk.Emulation.Cores.Nintendo.N64;
|
||||||
using BizHawk.Client.EmuHawk.ControlExtensions;
|
|
||||||
using BizHawk.Client.Common;
|
using BizHawk.Client.Common;
|
||||||
|
using BizHawk.Client.EmuHawk.ControlExtensions;
|
||||||
|
|
||||||
|
|
||||||
using BizHawk.Common;
|
using BizHawk.Common;
|
||||||
|
|
||||||
|
@ -322,11 +324,11 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
ss.CoreType = CoreTypeDropdown.SelectedItem
|
ss.CoreType = CoreTypeDropdown.SelectedItem
|
||||||
.ToString()
|
.ToString()
|
||||||
.GetValueFromDescription<N64SyncSettings.CORETYPE>();
|
.GetEnumFromDescription<N64SyncSettings.CORETYPE>();
|
||||||
|
|
||||||
ss.RspType = RspTypeDropdown.SelectedItem
|
ss.RspType = RspTypeDropdown.SelectedItem
|
||||||
.ToString()
|
.ToString()
|
||||||
.GetValueFromDescription<N64SyncSettings.RSPTYPE>();
|
.GetEnumFromDescription<N64SyncSettings.RSPTYPE>();
|
||||||
|
|
||||||
PutSettings(s);
|
PutSettings(s);
|
||||||
PutSyncSettings(ss);
|
PutSyncSettings(ss);
|
||||||
|
|
|
@ -10,36 +10,6 @@ namespace BizHawk.Common
|
||||||
{
|
{
|
||||||
public static class EnumHelper
|
public static class EnumHelper
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Gets an enum from a description attribute
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The type of the enum</typeparam>
|
|
||||||
/// <param name="description">The description attribute value</param>
|
|
||||||
/// <returns>An enum value with the given description attribute, if no suitable description is found then a default value of the enum is returned</returns>
|
|
||||||
/// <remarks>http://stackoverflow.com/questions/4367723/get-enum-from-description-attribute</remarks>
|
|
||||||
public static T GetValueFromDescription<T>(this string description)
|
|
||||||
{
|
|
||||||
var type = typeof(T);
|
|
||||||
if (!type.IsEnum) throw new InvalidOperationException();
|
|
||||||
foreach (var field in type.GetFields())
|
|
||||||
{
|
|
||||||
var attribute = Attribute.GetCustomAttribute(field,
|
|
||||||
typeof(DescriptionAttribute)) as DescriptionAttribute;
|
|
||||||
if (attribute != null)
|
|
||||||
{
|
|
||||||
if (attribute.Description == description)
|
|
||||||
return (T)field.GetValue(null);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (field.Name == description)
|
|
||||||
return (T)field.GetValue(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return default(T);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<string> GetDescriptions<T>()
|
public static IEnumerable<string> GetDescriptions<T>()
|
||||||
{
|
{
|
||||||
var vals = Enum.GetValues(typeof(T));
|
var vals = Enum.GetValues(typeof(T));
|
||||||
|
|
|
@ -51,6 +51,36 @@ namespace BizHawk.Common.ReflectionExtensions
|
||||||
return descriptions[0].Description;
|
return descriptions[0].Description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets an enum from a description attribute
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type of the enum</typeparam>
|
||||||
|
/// <param name="description">The description attribute value</param>
|
||||||
|
/// <returns>An enum value with the given description attribute, if no suitable description is found then a default value of the enum is returned</returns>
|
||||||
|
/// <remarks>http://stackoverflow.com/questions/4367723/get-enum-from-description-attribute</remarks>
|
||||||
|
public static T GetEnumFromDescription<T>(this string description)
|
||||||
|
{
|
||||||
|
var type = typeof(T);
|
||||||
|
if (!type.IsEnum) throw new InvalidOperationException();
|
||||||
|
foreach (var field in type.GetFields())
|
||||||
|
{
|
||||||
|
var attribute = Attribute.GetCustomAttribute(field,
|
||||||
|
typeof(DescriptionAttribute)) as DescriptionAttribute;
|
||||||
|
if (attribute != null)
|
||||||
|
{
|
||||||
|
if (attribute.Description == description)
|
||||||
|
return (T)field.GetValue(null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (field.Name == description)
|
||||||
|
return (T)field.GetValue(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return default(T);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Takes an object and determines if it has methodName as a public method
|
/// Takes an object and determines if it has methodName as a public method
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in New Issue