public AppSettingsManager() { foreach (var prop in typeof(T).GetProperties()) { var attr = prop.GetCustomAttribute <AppSettingsAttribute>(); if (attr != null) { AppSettingsKeys.Add(attr.Key, prop); AppSettingsOptions.Add(attr.Key, attr); } } Load(); }
private static string ReadSetting(string key) { if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } string keyWithEnvironment = string.Format("{0}_{1}", key, CurrentEnvironment); if (AppSettingsKeys.Contains(keyWithEnvironment)) { // Variable de configuration associée à l'environnement : return(ConfigurationManager.AppSettings[keyWithEnvironment]); } else { // Variable de configuration introuvable avec ou sans le suffixe d'environnement : throw new Exception(string.Format("Clé de configuration introuvable : \"{0}\".", key)); } }
public string GetAppSettingValue(AppSettingsKeys key) { return(GetAppSetting(key.ToString()).Value); }
private static void AssertAppSettingFound(AppSettingsKeys key) { Contract.Assert(ConfigurationManager.AppSettings[key.ToString()] != null, "AppSettings key " + key.ToString() + " not found."); }
public AppSetting GetAppSetting(AppSettingsKeys key) { return(GetAppSetting(key.ToString())); }