Exemple #1
0
        /// <summary>
        /// Converts the <paramref name="value"/> to an instance of a <see cref="Color"/>
        /// </summary>
        /// <param name="context">Context of the conversion</param>
        /// <param name="culture">Culture to use for the conversion</param>
        /// <param name="value">Value to convert</param>
        /// <returns>A <see cref="Color"/> instance with the converted value</returns>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var str = value as string;

            if (str != null)
            {
                Color color;
                if (!Color.TryParse(str, out color))
                {
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "{0} is not a valid color value.", str));
                }
                return(color);
            }
            return(base.ConvertFrom(context, culture, value));
        }
Exemple #2
0
        /// <summary>
        /// Converts the <paramref name="value"/> to an instance of a <see cref="Color"/>
        /// </summary>
        /// <param name="context">Context of the conversion</param>
        /// <param name="culture">Culture to use for the conversion</param>
        /// <param name="value">Value to convert</param>
        /// <returns>A <see cref="Color"/> instance with the converted value</returns>
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            var str = value as string;

            if (str != null)
            {
                Color color;
                if (!Color.TryParse(str, out color, culture))
                {
                    throw new ArgumentException(str + " is not a valid color value.");
                }
                return(color);
            }
            return(base.ConvertFrom(context, culture, value));
        }