/// <summary> /// Retrieves the keys in the dictionary as a list. /// </summary> /// <param name="dictionary">A dictionary object.</param> /// <returns name="keys">A list of keys.</returns> public static c.List<string> GetKeys (Dictionary dictionary) { c.ICollection<string> keys = dictionary.internalDictionary.Keys; c.List<string> k = new c.List<string>(); foreach (string key in keys) { k.Add(key); } return k; }
/// <summary> /// Converts the dictionary into a list of key-value pair lists. /// </summary> /// <param name="dict">A dictionary object</param> /// <returns name="Keys+Values">Returns a list of key-value pair lists.</returns> public static c.List<c.List<System.Object>> GetKeyValuePairs (Dictionary dict) { c.List< c.List <System.Object> > l = new c.List< c.List <System.Object> >(); c.List<string> k = new c.List<string>(); c.List<System.Object> v = new c.List<System.Object>(); foreach (c.KeyValuePair<string, System.Object> kvp in dict.internalDictionary) { l.Add(new c.List<System.Object>{kvp.Key, kvp.Value} ); } return l; }
/// <summary> /// Creates a Dictionary made of key value pairs. /// </summary> /// <param name="keys">Keys to be used in the dictionary.</param> /// <param name="values">Values in the dictionary.</param> /// <returns name="Dictionary">A new dictionary object.</returns> public static Dictionary ByKeysValues (c.List<string> keys, c.List<System.Object> values) { c.Dictionary<string, System.Object> dict = new c.Dictionary<string, System.Object>(); int i = 0; int vLength = values.Count; foreach (string key in keys) { if (i < vLength) { dict.Add(key, values[i]); } i++; } return new Dictionary(dict); }
/// <summary> /// /// </summary> /// <param name="dictionary"></param> /// <param name="keyContains"></param> /// <returns></returns> public static c.List<System.Object> KeyContains (Dictionary dictionary, string keyContains) { c.List<string> keys = dictionary.internalDictionary.Keys.Where(key => key.Contains(keyContains)).ToList(); return keys.Where(k => dictionary.internalDictionary.ContainsKey(k)).Select(k => dictionary.internalDictionary[k]).ToList(); }