fuck componentmodel
This commit is contained in:
parent
ea32862199
commit
ed02493297
|
@ -52,6 +52,7 @@
|
|||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
|
@ -81,6 +82,7 @@
|
|||
<Compile Include="Colors.cs" />
|
||||
<Compile Include="CustomCollections.cs" />
|
||||
<Compile Include="DeepEquality.cs" />
|
||||
<Compile Include="DescribableEnumConverter.cs" />
|
||||
<Compile Include="Extensions\BufferExtensions.cs" />
|
||||
<Compile Include="Extensions\CollectionExtensions.cs" />
|
||||
<Compile Include="Extensions\IOExtensions.cs" />
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BizHawk.Common
|
||||
{
|
||||
public class DescribableEnumConverter : EnumConverter
|
||||
{
|
||||
private Type enumType;
|
||||
|
||||
public DescribableEnumConverter(Type type) : base(type)
|
||||
{
|
||||
enumType = type;
|
||||
}
|
||||
|
||||
public override bool CanConvertTo(ITypeDescriptorContext context, Type destType)
|
||||
{
|
||||
return destType == typeof(string);
|
||||
}
|
||||
|
||||
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture,
|
||||
object value, Type destType)
|
||||
{
|
||||
var fi = enumType.GetField(Enum.GetName(enumType, value));
|
||||
var attr = (DisplayAttribute)fi.GetCustomAttribute(typeof(DisplayAttribute));
|
||||
if (attr != null)
|
||||
return attr.Name;
|
||||
else
|
||||
return value.ToString();
|
||||
}
|
||||
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type srcType)
|
||||
{
|
||||
return srcType == typeof(string);
|
||||
}
|
||||
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture,
|
||||
object value)
|
||||
{
|
||||
foreach (var fi in enumType.GetFields(BindingFlags.Public | BindingFlags.Static))
|
||||
{
|
||||
var attr = (DisplayAttribute)fi.GetCustomAttribute(typeof(DisplayAttribute));
|
||||
if (attr != null && attr.Name.Equals(value))
|
||||
return Enum.Parse(enumType, fi.Name);
|
||||
}
|
||||
return Enum.Parse(enumType, (string)value);
|
||||
}
|
||||
|
||||
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
|
||||
{
|
||||
var ret = new List<object>();
|
||||
foreach (var fi in enumType.GetFields(BindingFlags.Public | BindingFlags.Static))
|
||||
{
|
||||
ret.Add(fi.GetValue(null));
|
||||
}
|
||||
return new StandardValuesCollection(ret);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -345,6 +345,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.Saturn
|
|||
[DisplayName("Default Region")]
|
||||
[Description("Used when Region Autodetect is disabled or fails")]
|
||||
[DefaultValue(RegionType.Japan)]
|
||||
[TypeConverter(typeof(DescribableEnumConverter))]
|
||||
public RegionType Region { get; set; }
|
||||
|
||||
public enum LanguageType
|
||||
|
|
Loading…
Reference in New Issue