// Override ConvertFrom to convert from a string to an instance of Complex. public override object ConvertFrom( ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { string text = value as string; if (text != null) { try { return(ComplexProxy.Parse(text)); } catch (Exception e) { throw new Exception( String.Format("Cannot convert '{0}' ({1}) because {2}", value, value.GetType(), e.Message), e); } } return(base.ConvertFrom(context, culture, value)); }
// Override ConvertTo to convert from an instance of Complex to string. public override object ConvertTo( ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { if (destinationType == null) { throw new ArgumentNullException("destinationType"); } //Convert Complex to a string in a standard format. ComplexProxy c = value as ComplexProxy; if (c != null && this.CanConvertTo(context, destinationType)) { return(c.ToString()); } return(base.ConvertTo(context, culture, value, destinationType)); }