Пример #1
0
 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();
 }
Пример #2
0
        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));
            }
        }
Пример #3
0
 public string GetAppSettingValue(AppSettingsKeys key)
 {
     return(GetAppSetting(key.ToString()).Value);
 }
Пример #4
0
 private static void AssertAppSettingFound(AppSettingsKeys key)
 {
     Contract.Assert(ConfigurationManager.AppSettings[key.ToString()] != null,
         "AppSettings key " + key.ToString() + " not found.");
 }
Пример #5
0
 public AppSetting GetAppSetting(AppSettingsKeys key)
 {
     return(GetAppSetting(key.ToString()));
 }