/// <summary> Add a key/value pair setting to this item </summary> /// <param name="Key"> Key for this setting </param> /// <param name="Value"> Value for this setting </param> /// <remarks> If a value already exists for the provided key, the value will be changed /// to the new value provided to this method. </remarks> public void Add_Setting(string Key, string Value) { // Look for existing key that matches // Ensure the list is defined if (Settings == null) Settings = new List<StringKeyValuePair>(); // Ensure the dictionary was built if (settingLookupDictionary == null) settingLookupDictionary = new Dictionary<string, StringKeyValuePair>(StringComparer.OrdinalIgnoreCase); if (settingLookupDictionary.Count != Settings.Count) { foreach (StringKeyValuePair setting in Settings) settingLookupDictionary[setting.Key] = setting; } // Does this key already exist? if (settingLookupDictionary.ContainsKey(Key)) settingLookupDictionary[Key].Value = Value; else { StringKeyValuePair newValue = new StringKeyValuePair(Key, Value); Settings.Add(newValue); settingLookupDictionary[Key] = newValue; } }
/// <summary> Add a new setting string key value pair </summary> /// <param name="Key"> Key for this setting value </param> /// <param name="Value"> Value for this setting value </param>\ /// <remarks> If a setting for that Key already exists, it will be replaced with the new Value</remarks> public void Add_Setting(string Key, string Value) { // Is the dictionary built? if (settingLookupTable == null) settingLookupTable = new Dictionary<string, StringKeyValuePair>( StringComparer.OrdinalIgnoreCase); // Is the dictionary apparently current? if (settingLookupTable.Count != Settings.Count) { foreach (StringKeyValuePair pair in Settings) { settingLookupTable[pair.Key] = pair; } } // Now, is the an existing pair for this key? if (settingLookupTable.ContainsKey(Key)) settingLookupTable[Key].Value = Value; else { StringKeyValuePair pair = new StringKeyValuePair(Key, Value); Settings.Add(pair); settingLookupTable[Key] = pair; } }