コード例 #1
0
ファイル: FontWeight.cs プロジェクト: dox0/DotNet471RS3
        /// <summary>
        /// Creates a string representation of this object based on the format string
        /// and IFormatProvider passed in.
        /// If the provider is null, the CurrentCulture is used.
        /// See the documentation for IFormattable for more information.
        /// </summary>
        /// <returns>
        /// A string representation of this object.
        /// </returns>
        private string ConvertToString(string format, IFormatProvider provider)
        {
            string convertedValue;

            if (!FontWeights.FontWeightToString(RealWeight, out convertedValue))
            {
                // This can happen if _weight value is not a multiple of 100.
                return(RealWeight.ToString(provider));
            }
            return(convertedValue);
        }
コード例 #2
0
ファイル: FontWeightConverter.cs プロジェクト: yk2012985/wpf
        /// <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);
        }