From 00ac231a2ae8210b47756f08e12b136c7bbdd22f Mon Sep 17 00:00:00 2001 From: adelikat Date: Thu, 3 Jul 2014 17:29:01 +0000 Subject: [PATCH] More extension reorg --- .../Extensions/ControlExtensions.cs | 1 + .../config/N64/N64ControllerSettingControl.cs | 5 +++- BizHawk.Common/EnumHelper.cs | 24 ++-------------- BizHawk.Common/ReflectionUtil.cs | 28 ++++++++++++++++++- 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs b/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs index f64c15ed22..4bcb1b8337 100644 --- a/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs +++ b/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs @@ -5,6 +5,7 @@ using System.Text; using System.Windows.Forms; using BizHawk.Common; +using BizHawk.Common.ReflectionExtensions; namespace BizHawk.Client.EmuHawk.ControlExtensions { diff --git a/BizHawk.Client.EmuHawk/config/N64/N64ControllerSettingControl.cs b/BizHawk.Client.EmuHawk/config/N64/N64ControllerSettingControl.cs index 9d2d7435c7..10c17d7f3d 100644 --- a/BizHawk.Client.EmuHawk/config/N64/N64ControllerSettingControl.cs +++ b/BizHawk.Client.EmuHawk/config/N64/N64ControllerSettingControl.cs @@ -6,8 +6,11 @@ using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; -using BizHawk.Emulation.Cores.Nintendo.N64; + using BizHawk.Common; +using BizHawk.Common.ReflectionExtensions; + +using BizHawk.Emulation.Cores.Nintendo.N64; namespace BizHawk.Client.EmuHawk { diff --git a/BizHawk.Common/EnumHelper.cs b/BizHawk.Common/EnumHelper.cs index 5366894628..62726222b0 100644 --- a/BizHawk.Common/EnumHelper.cs +++ b/BizHawk.Common/EnumHelper.cs @@ -4,32 +4,12 @@ using System.Linq; using System.ComponentModel; using System.Reflection; +using BizHawk.Common.ReflectionExtensions; + namespace BizHawk.Common { public static class EnumHelper { - /// - /// Gets the description attribute from an object - /// - public static string GetDescription(this object obj) - { - Type type = obj.GetType(); - - var memInfo = type.GetMember(obj.ToString()); - - if (memInfo != null && memInfo.Length > 0) - { - object[] attrs = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false); - - if (attrs != null && attrs.Length > 0) - { - return ((DescriptionAttribute)attrs[0]).Description; - } - } - - return obj.ToString(); - } - /// /// Gets an enum from a description attribute /// diff --git a/BizHawk.Common/ReflectionUtil.cs b/BizHawk.Common/ReflectionUtil.cs index 947b87b950..6ce6e063e8 100644 --- a/BizHawk.Common/ReflectionUtil.cs +++ b/BizHawk.Common/ReflectionUtil.cs @@ -10,8 +10,34 @@ namespace BizHawk.Common.ReflectionExtensions /// /// Reflection based helper methods /// - public static class ReflectionUtil + public static class ReflectionExtensions { + /// + /// Gets the description attribute from an object + /// + public static string GetDescription(this object obj) + { + Type type = obj.GetType(); + + var memInfo = type.GetMember(obj.ToString()); + + if (memInfo != null && memInfo.Length > 0) + { + object[] attrs = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false); + + if (attrs != null && attrs.Length > 0) + { + return ((DescriptionAttribute)attrs[0]).Description; + } + } + + return obj.ToString(); + } + + /// + /// Gets the description attribute from a type + /// + /// public static string Description(this Type type) { var descriptions = (DescriptionAttribute[])