示例#1
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (!(value is string))
            {
                throw new NotSupportedException("Int32RectConvert only supports converting from strings");
            }

            return(Int32Rect.Parse((string)value));
        }
        /// <summary>
        /// Attempts to convert to a Int32Rect from the given object.
        /// </summary>
        /// <returns>
        /// The Int32Rect which was constructed.
        /// </returns>
        /// <exception cref="NotSupportedException">
        /// A NotSupportedException is thrown if the example object is null or is not a valid type
        /// which can be converted to a Int32Rect.
        /// </exception>
        /// <param name="context"> The ITypeDescriptorContext for this call. </param>
        /// <param name="culture"> The requested CultureInfo.  Note that conversion uses "en-US" rather than this parameter. </param>
        /// <param name="value"> The object to convert to an instance of Int32Rect. </param>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value == null)
            {
                throw GetConvertFromException(value);
            }

            String source = value as string;

            if (source != null)
            {
                return(Int32Rect.Parse(source));
            }

            return(base.ConvertFrom(context, culture, value));
        }