mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 17:56:51 +13:00
EnumDescriptionConverter localized description fix
This commit is contained in:
parent
3e0fbf5975
commit
ef6e784edc
1 changed files with 5 additions and 6 deletions
|
@ -26,6 +26,7 @@ You should have received a copy of the GNU General Public License
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ShareX.HelpersLib
|
||||
|
@ -47,7 +48,7 @@ public override bool CanConvertTo(ITypeDescriptorContext context, Type destType)
|
|||
|
||||
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destType)
|
||||
{
|
||||
return ((Enum)value).GetDescription();
|
||||
return ((Enum)value).GetLocalizedDescription();
|
||||
}
|
||||
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type srcType)
|
||||
|
@ -57,13 +58,11 @@ public override bool CanConvertFrom(ITypeDescriptorContext context, Type srcType
|
|||
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
{
|
||||
foreach (FieldInfo fi in enumType.GetFields())
|
||||
foreach (Enum e in Enum.GetValues(enumType).OfType<Enum>())
|
||||
{
|
||||
DescriptionAttribute da = (DescriptionAttribute)Attribute.GetCustomAttribute(fi, typeof(DescriptionAttribute));
|
||||
|
||||
if (da != null && da.Description == (string)value)
|
||||
if (e.GetLocalizedDescription() == (string)value)
|
||||
{
|
||||
return Enum.Parse(enumType, fi.Name);
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue