RestImageResize/Utils/ConfigUtils.cs
/// <summary>
/// Reads the setting entry of application settings section.
/// </summary>
/// <typeparam name="TValue">The setting's value type.</typeparam>
/// <param name="settingKey">The setting's key.</param>
/// <param name="valueConverter">The value from string conversion method.</param>
/// <param name="defaultValue">The default value.</param>
/// <param name="isRequired">Indicating whether value is required.</param>
/// <returns>
/// The setting value.
/// </returns>
Reads the setting entry of application settings section.
Reads the setting entry of application settings section .
private static TValue ReadAppSetting<TValue>(string settingKey, Func<string, TValue> valueConverter, Tuple<TValue> defaultValue = null, bool isRequired = false)
        {
            string stringValue = ConfigurationManager.AppSettings[settingKey];
            if (stringValue == null)
            {
                if (isRequired)
                {
                    throw new ConfigurationErrorsException(string.Format(RequiredSettingHasNotBeenFound, settingKey));
                }
                return defaultValue != null ? defaultValue.Item1 : default(TValue);
            }
            try
            {
                return valueConverter(stringValue);
            }
            catch (Exception ex)
            {
                throw new ConfigurationErrorsException(string.Format(ParameterValueDoesNotMatchExpectedFormat, settingKey, stringValue), ex);
            }
        }
private static TValue ReadAppSetting < TValue > ( string settingKey , Func < string , TValue > valueConverter , Tuple < TValue > defaultValue = null , bool isRequired = false ) { string stringValue = ConfigurationManager . AppSettings [ settingKey ] ; if ( stringValue == null ) { if ( isRequired ) { throw new ConfigurationErrorsException ( string . Format ( RequiredSettingHasNotBeenFound , settingKey ) ) ; } return defaultValue != null ? defaultValue . Item1 : default ( TValue ) ; } try { return valueConverter ( stringValue ) ; } catch ( Exception ex ) { throw new ConfigurationErrorsException ( string . Format ( ParameterValueDoesNotMatchExpectedFormat , settingKey , stringValue ) , ex ) ; } }
Reads the setting entry of application settings section.
Reads the setting entry of application settings section .
The setting value.
The setting value .
settingKey
string
The setting's key.
The setting ' s key .
valueConverter
Func<string, TValue>
The value from string conversion method.
The value from string conversion method .
defaultValue
Tuple<TValue>
The default value.
The default value .
isRequired
bool
Indicating whether value is required.
Indicating whether value is required .
typeparam
The setting's value type.
The setting ' s value type .