示例#1
0
 /// <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; }
 }
示例#2
0
        /// <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);
        }
示例#3
0
        /// <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;
        }
示例#4
0
        /// <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);
        }
示例#5
0
 /// <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);
 }
示例#6
0
 internal Dictionary()
 {
     internalDictionary = new c.Dictionary<string,System.Object>();
 }
示例#7
0
 internal Dictionary (c.Dictionary<string,System.Object> d) 
 {
     internalDictionary = d;
 }