You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.1 KiB
34 lines
1.1 KiB
using System;
|
|
using System.ComponentModel;
|
|
using System.Reflection;
|
|
|
|
namespace eCompanies
|
|
{
|
|
public class EnumDescriptionTypeConverter : EnumConverter
|
|
{
|
|
public EnumDescriptionTypeConverter(Type type)
|
|
: base(type)
|
|
{
|
|
}
|
|
|
|
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
|
|
{
|
|
if (destinationType == typeof(string))
|
|
{
|
|
if (value != null)
|
|
{
|
|
FieldInfo fi = value.GetType().GetField(value.ToString());
|
|
if (fi != null)
|
|
{
|
|
var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
|
|
return ((attributes.Length > 0) && (!String.IsNullOrEmpty(attributes[0].Description))) ? attributes[0].Description : value.ToString();
|
|
}
|
|
}
|
|
|
|
return string.Empty;
|
|
}
|
|
|
|
return base.ConvertTo(context, culture, value, destinationType);
|
|
}
|
|
}
|
|
}
|
|
|