Exemplo n.º 1
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            ColumnWidthUnitType unitType;

            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            if (value is ColumnWidth)
            {
                return(value);
            }

            if (value is string)
            {
                return(ColumnWidthConverter.FromString(( string )value, culture));
            }

            double doubleValue = Convert.ToDouble(value, culture);

            unitType = ColumnWidthUnitType.Pixel;

            return(new ColumnWidth(doubleValue, unitType));
        }
Exemplo n.º 2
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == null)
            {
                throw new ArgumentNullException("destinationType");
            }

            if ((value != null) && (value is ColumnWidth))
            {
                ColumnWidth columnWidth = ( ColumnWidth )value;

                if (destinationType == typeof(string))
                {
                    return(ColumnWidthConverter.ToString(columnWidth, culture));
                }

                // If we ever want to add InstanceDescriptor in the list of supported destination
                // type, we will have to implement it in another method and surround the call
                // with a try/catch. Otherwise, the call to Type.GetConstructor() will fail if
                // the application does not have reflection permission (typically XBAP).
            }

            throw new ArgumentException("Cannot convert to type " + destinationType.FullName + ".", "value");
        }