/// <summary> /// Sets the value at a given key. /// </summary> /// <param name="dictionary">a dictionary</param> /// <param name="key">A key in the dictionary.</param> /// <param name="value">The value to set</param> /// <returns name="dictionary">The modified dictionary. Returns null if no key is found.</returns> public static Dictionary SetValueAtKey(Dictionary dictionary, string key, System.Object value) { c.Dictionary<string, System.Object> unwrapped = Dictionary.UnwrapDictionary(dictionary); if (dictionary.internalDictionary.ContainsKey(key)) { dictionary.internalDictionary.Remove(key); dictionary.internalDictionary.Add(key, value); return dictionary; } else { return null; } }
/// <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> /// Prints the Dictionary as a string. /// </summary> /// <returns name="string">Converts to a string.</returns> public override string ToString() { c.Dictionary<string, System.Object> dict = this.internalDictionary; Type t = typeof(Dictionary); string s = ""; s = string.Concat(s, t.Namespace, ".", GetType().Name); int i = 0; foreach (c.KeyValuePair<string, System.Object> keyValue in dict) { s = string.Concat(s, string.Format("\n {0} Key-> \"{1}\", Value-> {2}", i, keyValue.Key, keyValue.Value)); i++; } return s; }
/// <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> /// Wraps a .Net Dictionary object into a Synthetic.Core.Dictionary object. /// </summary> /// <param name="dotNetDictionary">.Net Dictionary object.</param> /// <returns name="dictionary">Returns a A Synthetic.Core.Dictionary object.</returns> public static Dictionary Wrap(c.Dictionary<string, System.Object> dotNetDictionary) { return new Dictionary(dotNetDictionary); }
internal Dictionary() { internalDictionary = new c.Dictionary<string,System.Object>(); }
internal Dictionary (c.Dictionary<string,System.Object> d) { internalDictionary = d; }