From ef6e784edce5034e0266e3dadae988bebfd3dcaa Mon Sep 17 00:00:00 2001 From: Jaex Date: Mon, 10 Aug 2015 01:56:29 +0300 Subject: [PATCH] EnumDescriptionConverter localized description fix --- .../UITypeEditors/EnumDescriptionConverter.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ShareX.HelpersLib/UITypeEditors/EnumDescriptionConverter.cs b/ShareX.HelpersLib/UITypeEditors/EnumDescriptionConverter.cs index 1b02f6ddb..8f306d8ab 100644 --- a/ShareX.HelpersLib/UITypeEditors/EnumDescriptionConverter.cs +++ b/ShareX.HelpersLib/UITypeEditors/EnumDescriptionConverter.cs @@ -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()) { - 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; } }