コード例 #1
0
        // Auto-load/save functions
        public void loadFromFile() // List itself should contain the default values
        {
            // Check for nonexistent files (to speed things up)
            if (!File.Exists(SettingsFilePath))
            {
                return;
            }

            // Load values
            for (int i = 0; i < settings.Count; i++)
            {
                KeyValuePair <string, object> kvp = settings.ElementAt <KeyValuePair <string, object> >(i);

                string key   = kvp.Key;
                object value = kvp.Value;

                string type = Convert.ToString(kvp.GetType()).ToLowerInvariant();

                if (SettingsFileLowLevelIO.keyExistsInFile(key, SettingsFilePath))
                {
                    // Any errors triggered by the read... functions should NOT be handled here (so the programmer is notified of them)!
                    if (value is int)
                    {
                        value = SettingsFileLowLevelIO.readInteger(key, SettingsFilePath);
                    }
                    if (value is double)
                    {
                        value = SettingsFileLowLevelIO.readDouble(key, SettingsFilePath);
                    }
                    if (value is string)
                    {
                        value = SettingsFileLowLevelIO.readString(key, SettingsFilePath);
                    }
                    if (value is bool)
                    {
                        value = SettingsFileLowLevelIO.readBoolean(key, SettingsFilePath);
                    }
                }

                // Update value
                settings[key] = value;
            }
        }