예제 #1
0
파일: Domain.cs 프로젝트: JabX/kinetix
        /// <summary>
        /// Converti un string en valeur.
        /// </summary>
        /// <param name="text">Valeur à convertir.</param>
        /// <param name="propertyDescriptor">Propriété.</param>
        /// <returns>Valeur dans le type cible.</returns>
        /// <exception cref="System.FormatException">En cas d'erreur de convertion.</exception>
        object IDomainChecker.ConvertFromString(string text, BeanPropertyDescriptor propertyDescriptor)
        {
            if (propertyDescriptor == null)
            {
                throw new ArgumentNullException("propertyDescriptor");
            }

            object v = null;

            try {
                if (_formatter != null)
                {
                    v = _formatter.ConvertFromString(text);
                }
                else if (_extendedFormatter != null)
                {
                    v = _extendedFormatter.ConvertFromString(text);
                }
                else
                {
                    if (!string.IsNullOrEmpty(text))
                    {
                        v = TypeDescriptor.GetConverter(typeof(T)).ConvertFromString(text);
                    }
                }
            } catch (Exception e) {
                string message = e.Message;
                if (_propertyMessage != null)
                {
                    message = string.Format(CultureInfo.CurrentCulture, (string)_propertyMessage.GetValue(null, null), text);
                }

                throw new ConstraintException(propertyDescriptor, message, e);
            }

            CheckValueType(v, propertyDescriptor);
            CheckValueValidation(v, propertyDescriptor);
            return(v);
        }