Пример #1
0
        private static object CreateObjectFromString(string value, Type dstType)
        {
            var underlyingType = Nullable.GetUnderlyingType(dstType);

            if (underlyingType != null)
            {
                if (string.IsNullOrEmpty(value))
                {
                    return(null);
                }
                dstType = underlyingType;
            }

            var converter = Configuration.FindTypeStringConverter(dstType);

            if (converter == Configuration.FallbackConverter)
            {
                throw ConfigurationException.CreateOnConverterMissing(value, dstType);
            }

            try
            {
                return(converter.ConvertFromString(value, dstType));
            }
            catch (Exception ex)
            {
                throw ConfigurationException.Create(value, dstType, ex);
            }
        }