コード例 #1
0
        // 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));
        }
コード例 #2
0
        // 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));
        }