/// <summary> /// Get a int value from the configuration /// </summary> /// <param name="Category">The category</param> /// <param name="Key">The key</param> /// <param name="Default">The default value</param> /// <returns>The value if found, default if not</returns> public int GetInt(ConfigurationSections Category, string Key, int Default) { object value = GetValue(Category.ToString(), Key, Default); if (value.GetType() == typeof(Int32)) { return((int)value); } else { return(Int32.Parse(value.ToString())); } }
/// <summary> /// Get a bool value from the configuration /// </summary> /// <param name="Category">The category</param> /// <param name="Key">The key</param> /// <param name="Default">The default value</param> /// <returns>The value if found, default if not</returns> public bool GetBool(ConfigurationSections Category, string Key, bool Default) { object value = GetValue(Category.ToString(), Key, Default); if (value.GetType() == typeof(Boolean)) { return((bool)value); } else { return(Boolean.Parse(value.ToString())); } }
/// <summary> /// Get a type value from the configuration /// </summary> /// <param name="Category">The category</param> /// <param name="Key">The key</param> /// <param name="Default">The default value</param> /// <returns>The value if found, default if not</returns> public Type GetType(ConfigurationSections Category, string Key, Type Default) { object value = GetValue(Category.ToString(), Key, Default); if (value == null) { return(null); } Type returnType = Type.GetType(value.ToString()); if (returnType != null) { return(returnType); } return(Default); }
/// <summary> /// Checks if the configuration has set a value for the given category and key /// </summary> /// <param name="Category">The category</param> /// <param name="Key">The key</param> /// <returns>True if the config has a value</returns> public bool HasValue(ConfigurationSections Category, string Key) { string CatKey = Category.ToString(); return(Configuration.ContainsKey(CatKey) && Configuration[CatKey].ContainsKey(Key)); }
/// <summary> /// Get a string value from the configuration /// </summary> /// <param name="Category">The category</param> /// <param name="Key">The key</param> /// <param name="Default">The default value</param> /// <returns>The value if found, default if not</returns> public string GetString(ConfigurationSections Category, string Key, string Default) { return(GetValue(Category.ToString(), Key, Default).ToString()); }