Beispiel #1
0
        /// <summary>
        /// ConvertFrom - attempt to convert to a FontWeight from the given object
        /// </summary>
        /// <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 FontWeight.
        /// </exception>
        public override object ConvertFrom(ITypeDescriptorContext td, CultureInfo ci, object value)
        {
            if (null == value)
            {
                throw GetConvertFromException(value);
            }

            String s = value as string;

            if (null == s)
            {
                throw new ArgumentException(SR.Get(SRID.General_BadType, "ConvertFrom"), "value");
            }

            FontWeight fontWeight = new FontWeight();

            if (!FontWeights.FontWeightStringToKnownWeight(s, ci, ref fontWeight))
            {
                throw new FormatException(SR.Get(SRID.Parsers_IllegalToken));
            }

            return(fontWeight);
        }