Candor.Configuration.Provider.ProviderHelperExtensions.GetBooleanValue C# (CSharp) Method

GetBooleanValue() public static method

A helper method to get a boolean value from a configuration setting value.
public static GetBooleanValue ( this config, string name, System.Boolean defaultValue ) : System.Boolean
config this The available configuation values.
name string The name of the setting to retrieve.
defaultValue System.Boolean The default in case the named /// value does not exist.
return System.Boolean
        public static Boolean GetBooleanValue( this NameValueCollection config,
			string name, Boolean defaultValue )
        {
            if (config == null)
                return defaultValue;
            string val = config[name];
            if (val == null)
                return defaultValue;
            val = val.Trim();
            if (val.Length == 0)
                return defaultValue;

            try
            {
                return Boolean.Parse(val);
            }
            catch (Exception)
            {
                throw new ArgumentOutOfRangeException(name, val,
                    string.Format("'{0}' must be a boolean value.", name));
            }
        }