# HG changeset patch # User IBBoard # Date 1239289851 0 # Node ID 41ddcd61dc92776be46640f5fd1ad30022caeddb # Parent 4ea1fc351533a5770c4ea8d376eab9101fb04c9d Add method to get array of keys from dictionary no-open-ticket diff -r 4ea1fc351533 -r 41ddcd61dc92 Collections/DictionaryUtils.cs --- a/Collections/DictionaryUtils.cs Sat Mar 28 20:54:01 2009 +0000 +++ b/Collections/DictionaryUtils.cs Thu Apr 09 15:10:51 2009 +0000 @@ -35,6 +35,33 @@ return col; } + + /// + /// Takes the set of keys in a dictionary and returns them as an array of typed objects. + /// + /// + /// A to extract an array of keys from + /// + /// + /// An array of objects taken from the Keys property of the dictionary, or NULL if the dictionary is NULL + /// + public static KEY_TYPE[] ToKeyArray(IDictionary dictionary) + { + if (dictionary == null) + { + return null; + } + + int entryCount = dictionary.Count; + KEY_TYPE[] col = new KEY_TYPE[entryCount]; + + if (entryCount > 0) + { + dictionary.Keys.CopyTo(col, 0); + } + + return col; + } /// /// Takes two dictionaries and merges them. If a key exists in both dictionaries then the value in firstDictionary takes priority.