More extension reorg
This commit is contained in:
parent
6cba3568ef
commit
00ac231a2a
|
@ -5,6 +5,7 @@ using System.Text;
|
|||
using System.Windows.Forms;
|
||||
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Common.ReflectionExtensions;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk.ControlExtensions
|
||||
{
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -4,32 +4,12 @@ using System.Linq;
|
|||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
|
||||
using BizHawk.Common.ReflectionExtensions;
|
||||
|
||||
namespace BizHawk.Common
|
||||
{
|
||||
public static class EnumHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the description attribute from an object
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an enum from a description attribute
|
||||
/// </summary>
|
||||
|
|
|
@ -10,8 +10,34 @@ namespace BizHawk.Common.ReflectionExtensions
|
|||
/// <summary>
|
||||
/// Reflection based helper methods
|
||||
/// </summary>
|
||||
public static class ReflectionUtil
|
||||
public static class ReflectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the description attribute from an object
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the description attribute from a type
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string Description(this Type type)
|
||||
{
|
||||
var descriptions = (DescriptionAttribute[])
|
||||
|
|
Loading…
Reference in New Issue