Example #1
0
        public static Dict <TKey, TValue> Clone <TKey, TValue>(this Dict <TKey, TValue> rDict)
        {
            var newDict = new Dict <TKey, TValue>();

            foreach (var item in rDict)
            {
                newDict.Add((TKey)item.Key, (TValue)item.Value);
            }
            return(newDict);
        }
Example #2
0
 public override JsonNode this[string rKey]
 {
     get
     {
         JsonNode rNode = null;
         dict.TryGetValue(rKey, out rNode);
         return(rNode);
     }
     set
     {
         if (dict.ContainsKey(rKey))
         {
             dict[rKey] = value;
         }
         else
         {
             dict.Add(rKey, value);
         }
     }
 }
Example #3
0
 public override void AddHead(string rKey, JsonNode rItem)
 {
     if (!string.IsNullOrEmpty(rKey))
     {
         if (dict.ContainsKey(rKey))
         {
             dict[rKey] = rItem;
         }
         else
         {
             var rTempdict = new Dict <string, JsonNode>();
             rTempdict.Add(rKey, rItem);
             foreach (var rPair in dict)
             {
                 rTempdict.Add(rPair.Key, rPair.Value);
             }
             dict = rTempdict;
         }
     }
     else
     {
         Debug.LogError("JsonClass dict cannot Add empty string key.");
     }
 }
Example #4
0
        public static Dict <TKey, TValue> Sort <TKey, TValue>(this Dict <TKey, TValue> rDict, Comparison <KeyValuePair <TKey, TValue> > cmpAlgo)
        {
            var list = new List <KeyValuePair <TKey, TValue> >();

            foreach (var item in rDict)
            {
                list.Add(item);
            }

            list.Sort(cmpAlgo);

            rDict.Clear();
            for (int i = 0; i < list.Count; i++)
            {
                rDict.Add(list[i].Key, list[i].Value);
            }

            return(rDict);
        }