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

GetInt32Value() public static method

A helper method to get an integer value from a configuration setting value.
public static GetInt32Value ( this config, string name, Int32 defaultValue ) : Int32
config this The available configuation values.
name string The name of the setting to retrieve.
defaultValue System.Int32 The default in case the named /// value does not exist.
return System.Int32
        public static Int32 GetInt32Value( this NameValueCollection config,
			string name, Int32 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 Int32.Parse(val);
            }
            catch (Exception)
            {
                throw new ArgumentOutOfRangeException(name, val,
                    string.Format("'{0}' must be an integer value.", name));
            }
        }