public string ParseAndValidateScopeValue(string scopeName, object value)
        {
            this.ValidateScopeName(scopeName);
            ConfigurationProperty property = this.ScopeSchema.GetConfigurationProperty(scopeName, null);

            ExchangeConfigurationSection.RunConfigOperation(delegate
            {
                if (property.Type != value.GetType())
                {
                    property.Converter.ConvertFrom(value);
                }
                property.Validator.Validate(value);
            }, (Exception ex) => new ConfigurationSettingsScopePropertyFailedValidationException(scopeName, (value != null) ? value.ToString() : null, ex));
            if (value == null)
            {
                return(null);
            }
            if (value is string)
            {
                return((string)value);
            }
            string result;

            try
            {
                result = property.Converter.ConvertToInvariantString(value);
            }
            catch (NotSupportedException innerException)
            {
                throw new ConfigurationSettingsScopePropertyBadValueException(scopeName, (value != null) ? value.ToString() : null, innerException);
            }
            return(result);
        }
        public object ParseAndValidateConfigValue(string settingName, string serializedValue, Type settingType = null)
        {
            ConfigurationProperty property = base.GetConfigurationProperty(settingName, settingType);
            object convertedValue          = null;

            ExchangeConfigurationSection.RunConfigOperation(delegate
            {
                TypeConverter converter = property.Converter;
                convertedValue          = converter.ConvertFromInvariantString(serializedValue);
            }, (Exception ex) => new ConfigurationSettingsPropertyBadValueException(settingName, serializedValue, ex));
            this.ValidateConfigValue(property, convertedValue);
            return(convertedValue);
        }
 private void ValidateConfigValue(ConfigurationProperty property, object value)
 {
     if (property == null)
     {
         throw new ArgumentNullException("property");
     }
     ExchangeConfigurationSection.RunConfigOperation(delegate
     {
         ConfigurationValidatorBase validator = property.Validator;
         if (validator != null)
         {
             validator.Validate(value);
         }
     }, (Exception ex) => new ConfigurationSettingsPropertyFailedValidationException(property.Name, (value != null) ? value.ToString() : null, ex));
 }
        public static T ConvertValue <T>(IConfigSchema schema, string settingName, object rawValue)
        {
            if (!(rawValue is T))
            {
                ConfigurationProperty property = schema.GetConfigurationProperty(settingName, typeof(T));
                ExchangeConfigurationSection.RunConfigOperation(delegate
                {
                    TypeConverter converter = property.Converter;
                    rawValue = converter.ConvertTo(rawValue, typeof(T));
                }, (Exception ex) => new ConfigurationSettingsPropertyBadTypeException(string.Format("{0}:{1}", settingName, (rawValue != null) ? rawValue.GetType().ToString() : "(null)"), typeof(T).ToString(), ex));
            }
            T result;

            try
            {
                result = (T)((object)rawValue);
            }
            catch (InvalidCastException innerException)
            {
                throw new ConfigurationSettingsPropertyBadTypeException(string.Format("{0}:{1}", settingName, (rawValue != null) ? rawValue.GetType().ToString() : "(null)"), typeof(T).ToString(), innerException);
            }
            return(result);
        }