/// <summary> /// Creates a Dictionary from a list of key value pair lists. /// </summary> /// <param name="keyValuePairs">A list of paired lists representing Keys and Values.</param> /// <returns name="Dictionary">A new dictionary object.</returns> public static Dictionary ByKeyValuePairs(c.List<c.List<System.Object>> keyValuePairs) { c.Dictionary<string, System.Object> dict = new c.Dictionary<string, System.Object>(); foreach (c.List<System.Object> pair in keyValuePairs) { dict.Add((string)pair[0], pair[1]); } return new Dictionary(dict); }
/// <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> /// Retrieves the values in the dictionary as a list. /// </summary> /// <param name="dict">A dictionary object.</param> /// <returns name="values">A list of values.</returns> public static c.List<System.Object> GetValues(Dictionary dict) { c.ICollection<System.Object> values = dict.internalDictionary.Values; c.List<System.Object> v = new c.List<System.Object>(); foreach (System.Object value in values) { v.Add(value); } return v; }
/// <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); }