public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { string[] ps = Enum.GetNames(typeof(PrecisionType)); string[] names = new string[ps.Length]; for (int i = 0; i < ps.Length; i++) { names[i] = EnumItemDescAttribute.GetDisplayValue(ps[i], typeof(PrecisionType), Thread.CurrentThread.CurrentUICulture); } System.ComponentModel.TypeConverter.StandardValuesCollection svc = new System.ComponentModel.TypeConverter.StandardValuesCollection(names); return(svc); }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == typeof(string)) { string[] ps = Enum.GetNames(typeof(PrecisionType)); foreach (string p in ps) { if (value.ToString() == p) { return(EnumItemDescAttribute.GetDisplayValue(value.ToString(), typeof(PrecisionType), Thread.CurrentThread.CurrentUICulture)); } } } return(base.ConvertTo(context, culture, value, destinationType)); }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { PrecisionType name = PrecisionType.None; if (value.GetType() == typeof(string)) { string[] ps = Enum.GetNames(typeof(PrecisionType)); foreach (string p in ps) { if (EnumItemDescAttribute.GetDisplayValue(p, typeof(PrecisionType), Thread.CurrentThread.CurrentUICulture) == value.ToString()) { name = (PrecisionType)Enum.Parse(typeof(PrecisionType), p); break; } } } return(name); }