/// <summary> /// Set Dictionary Iterator to first Key-Value pair and return its Key. /// </summary> /// <param name="DictID">Supplies the id of the Dictionary to access. /// </param> /// <param name="Key">Output is the first Key in the SortedDictionary. /// </param> /// <returns>True if Dictionary DictID exists and contains elements, /// otherwise false.</returns> private bool DictionaryIterateFirst(string DictID, out string Key) { SortedDictionary <string, string> Dict; IDictionaryEnumerator ide; Key = ""; if (StorageList.TryGetValue(DictID, out Dict) == false) { return(false); } ide = Dict.GetEnumerator(); // Confirm there exists an element within this dictionary, // if not simply return false if (ide.MoveNext() == false) { return(false); } Key = (string)ide.Key; // Store iterator for future use StorageIteratorList[DictID] = ide; return(true); }
/// <summary> /// Delete value from dictionary by key. /// </summary> /// <param name="DictID">Supplies the id of the Dictionary to access. /// </param> /// <param name="Key">Key to search for and delete from the dictionary. /// </param> private void DictionaryDeleteKey(string DictID, string Key) { SortedDictionary <string, string> Dict; if (StorageList.TryGetValue(DictID, out Dict) == false) { return; } Dict.Remove(Key); StorageIteratorList.Remove(Key); }
/// <summary> /// Set Dictionary DictID's Key to a String Value. /// </summary> /// <param name="DictID">Supplies the id of the Dictionary to access. /// If this Dictionary does not exist, create it. </param> /// <param name="Key">Supplies the Key for lookup of the target dictionary. /// If no such Key exists, create a new Key/Value pair. </param> /// <param name="Value">Supplies the Value to associate to the Key in the /// target dictionary. </param> private void DictionarySetString(string DictID, string Key, string Value) { SortedDictionary <string, string> Dict; // Create if does not exist if (StorageList.TryGetValue(DictID, out Dict) == false) { Dict = new SortedDictionary <string, string>(); StorageList[DictID] = Dict; } Dict[Key] = Value; StorageIteratorList.Remove(DictID); }
/// <summary> /// Get Value corresponding to Dictionary DictID's Key. On error return /// null string. /// </summary> /// <param name="DictID">Supplies the id of the Dictionary to access. /// </param> /// <param name="Key">Supplies the Key for lookup of the target dictionary. /// </param> /// <param name="Value">Output is the Value corresponding to Key. /// </param> /// <returns>True if Dictionary DictID exists and Key exists within it, /// otherwise false.</returns> private bool DictionaryGetString(string DictID, string Key, out string Value) { SortedDictionary <string, string> Dict; Value = ""; if (StorageList.TryGetValue(DictID, out Dict) == false) { return(false); } if (Dict.TryGetValue(Key, out Value) == false) { return(false); } return(true); }