Exemple #1
0
        /// <summary>
        /// Extends ConvertTo so that methods that return a specific type object given a Type parameter can be
        /// used as generic method and casting is not required.
        /// <example>
        /// basenumberconverter.ConvertTo&lt;int&gt;(context, culture, value);
        /// </example>
        /// </summary>
        public static T ConvertTo <T>(this Int32Converter basenumberconverter, ITypeDescriptorContext context, System.Globalization.CultureInfo culture, Object value)
        {
            if (basenumberconverter == null)
            {
                throw new ArgumentNullException("basenumberconverter");
            }

            return((T)basenumberconverter.ConvertTo(context, culture, value, typeof(T)));
        }
Exemple #2
0
        /// <summary>
        /// Extends ConvertTo so that methods that return a specific type object given a Type parameter can be
        /// used as generic method and casting is not required.
        /// <example>
        /// typeconverter.ConvertTo&lt;int&gt;(value);
        /// </example>
        /// </summary>
        public static T ConvertTo <T>(this Int32Converter typeconverter, Object value)
        {
            if (typeconverter == null)
            {
                throw new ArgumentNullException("typeconverter");
            }

            return((T)typeconverter.ConvertTo(value, typeof(T)));
        }
        public override object ConvertTo(object sourceValue, Type destinationType, IFormatProvider formatProvider, bool ignoreCase)
        {
            if (sourceValue == null)
            {
                throw new NotSupportedException();
            }

            if (sourceValue is OptionSetValue optionsetValue)
            {
                if (destinationType == typeof(int))
                {
                    return(optionsetValue.Value);
                }
                else
                {
                    Int32Converter dc = new Int32Converter();
                    return(dc.ConvertTo(optionsetValue.Value, destinationType));
                }
            }

            return(new NotSupportedException());
        }