public override object ConvertTo ( System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType ) { if (typeof(string) == destinationType) { Source_FrequencyBandList channelList = value as Source_FrequencyBandList; if (null == channelList) { throw new ArgumentException("Expected a Source_FrequencyBandList", "value"); } StringBuilder sb = new StringBuilder( ); foreach (Source_FrequencyBand channel in channelList) { Object obj = TypeDescriptor.GetConverter(typeof(Source_FrequencyBand)).ConvertToString(channel); if (null == obj) { // Should NOT be possible ~ should get exception for bad arg // before seeing a null == obj return value } else { sb.Append(obj as String); sb.Append(';'); } } return(sb.ToString( )); } return(base.ConvertTo(context, culture, value, destinationType)); }
public override object ConvertFrom ( System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, Object value ) { Source_FrequencyBandList channelList = new Source_FrequencyBandList( ); if (String.IsNullOrEmpty(value as string)) { return(channelList); } String[] channelStrings = (value as String).Split(new Char[] { ';' }); if (null == channelStrings) { return(channelList); } foreach (String s in channelStrings) { Object obj = TypeDescriptor.GetConverter(typeof(Source_FrequencyBand)).ConvertFromString(s); if (null == obj) { // TODO : supply err msg || rely on Source_FrequencyBand converter for msg } else { channelList.Add(obj as Source_FrequencyBand); } } return(channelList); }