More extension reorg

This commit is contained in:
adelikat 2014-07-03 17:29:01 +00:00
parent 6cba3568ef
commit 00ac231a2a
4 changed files with 34 additions and 24 deletions

View File

@ -5,6 +5,7 @@ using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Common.ReflectionExtensions;
namespace BizHawk.Client.EmuHawk.ControlExtensions namespace BizHawk.Client.EmuHawk.ControlExtensions
{ {

View File

@ -6,8 +6,11 @@ using System.Data;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Emulation.Cores.Nintendo.N64;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Common.ReflectionExtensions;
using BizHawk.Emulation.Cores.Nintendo.N64;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {

View File

@ -4,32 +4,12 @@ using System.Linq;
using System.ComponentModel; using System.ComponentModel;
using System.Reflection; using System.Reflection;
using BizHawk.Common.ReflectionExtensions;
namespace BizHawk.Common namespace BizHawk.Common
{ {
public static class EnumHelper 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> /// <summary>
/// Gets an enum from a description attribute /// Gets an enum from a description attribute
/// </summary> /// </summary>

View File

@ -10,8 +10,34 @@ namespace BizHawk.Common.ReflectionExtensions
/// <summary> /// <summary>
/// Reflection based helper methods /// Reflection based helper methods
/// </summary> /// </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) public static string Description(this Type type)
{ {
var descriptions = (DescriptionAttribute[]) var descriptions = (DescriptionAttribute[])