public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { if (destinationType == typeof(string)) { string str = String.Empty; ReasonCodeCollection rcc = value as ReasonCodeCollection; if (rcc != null) { foreach (ReasonCode rc in rcc) { ReasonCodeTypeConverter rctc = new ReasonCodeTypeConverter(); if (str == String.Empty) { str += string.Format("{0}", (string)rctc.ConvertTo(rc, typeof(string))); } else { str += string.Format(";{0}", (string)rctc.ConvertTo(rc, typeof(string))); } } } return(str); } else { return(base.ConvertTo(context, culture, value, destinationType)); } }
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { if (value.GetType() == typeof(string)) { ReasonCodeCollection rcc = new ReasonCodeCollection(); string str = value as string; if (str != null) { str = str.Trim(); string[] reasoncodes = str.Split(new char[] { ';' }, StringSplitOptions.None); foreach (string rcode in reasoncodes) { ReasonCodeTypeConverter rctc = new ReasonCodeTypeConverter(); ReasonCode rc = (ReasonCode)rctc.ConvertFrom(rcode); if (rc != null) { rcc.Add(rc); } } } return(rcc); } else { return(base.ConvertFrom(context, culture, value)); } }