Exemple #1
0
        public static T GetSetting <T>(
            this IINIFile iniFile,
            string section,
            string setting,
            T defaultValue = default(T))
        {
            if (!iniFile.HasSetting(section, setting))
            {
                return(defaultValue);
            }
            var stringValue = iniFile[section][setting];

            return(AttemptToConvert <T>(stringValue, defaultValue));
        }
Exemple #2
0
        private void LoadConfig(string name)
        {
            // config files will live in the user profile folder (eg C:\users\myprofile)
            var fullPath = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
                name);

            // if the file exists, it will be loaded; if not, then the INIFile instance
            //    will still know that when it's time to save, it should save back to that file
            _loadedConfig = new INIFile(fullPath);
            // load up the label, if we can
            ColorDisplay.Text = _loadedConfig.HasSetting("colors", "FavoriteColor")
                ? _loadedConfig["colors"]["FavoriteColor"]
                : "(no favorite color chosen yet for #1)";
            ColorDisplay.ForeColor = TryDetermineColorFor(ColorDisplay.Text);
            // reset the selected color in the drop-down
            ColorList.SelectedIndex = -1;
            // signal to the user that a color may be selected by enabling the controls
            ColorList.Enabled   = true;
            ChangeLabel.Enabled = true;
        }
Exemple #3
0
 public bool ContainsKey(string key)
 {
     return(_iniFile.HasSetting(_section, key));
 }