private object ConvertFromString(Type type, string value, CultureInfo culture)
        {
            TypeConverter converter = TypeConvertorHelpers.GetConverterForType(type);

            try
            {
                return(converter.ConvertFromString(null, culture, value));
            }
            catch (Exception ex)
            {
                // HACK: There is a bug in the .NET framework (3.5sp1) BaseNumberConverter class. The
                // class throws an Exception base class, and therefore we must catch the 'Exception' base class.
                throw new FormatException(
                          "The supplied value '" + value + "' could not be converted. " + ex.Message, ex);
            }
        }
Пример #2
0
        /// <summary>
        /// Converts value to string using the current thread culture.
        /// </summary>
        /// <param name="type"> The type as Type to convert. </param>
        /// <param name="value"> The value itself. </param>
        /// <param name="culture"> The culture as conversion context. </param>
        /// <returns></returns>
        //// [DebuggerStepThrough]
        public static string AsString(Type type, object value, CultureInfo culture)
        {
            TypeConverter converter = TypeConvertorHelpers.GetConverterForType(type);

            return(converter.ConvertToString(null, culture, value));
        }