public override object ConvertTo ( System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType ) { if (typeof(string) == destinationType) { Source_GPIOList gpioList = value as Source_GPIOList; if (null == gpioList) { throw new ArgumentException("Expected a Source_GPIOList", "value"); } StringBuilder sb = new StringBuilder( ); foreach (Source_GPIO gpio in gpioList) { Object obj = TypeDescriptor.GetConverter(typeof(Source_GPIO)).ConvertToString(gpio); 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_GPIOList gpioList = new Source_GPIOList( ); if (String.IsNullOrEmpty(value as string)) { return(gpioList); } String[] gpioPinStrings = (value as String).Split(new Char[] { ';' }); if (null == gpioPinStrings) { return(gpioList); } foreach (String s in gpioPinStrings) { Object obj = TypeDescriptor.GetConverter(typeof(Source_GPIO)).ConvertFromString(s); if (null == obj) { // TODO : supply err msg || rely on Source_GPIO converter for msg } else { gpioList.Add(obj as Source_GPIO); } } return(gpioList); }