Exemple #1
0
        public override object this[object key] {
            set {
                data[DictOps.NullToObj(key)] = value;

                string s1 = key as string;
                string s2 = value as string;
                if (s1 != null && s2 != null)
                {
                    Environment.SetEnvironmentVariable(s1, s2);
                }
            }
        }
Exemple #2
0
 public virtual object this[object key] {
     get {
         object realKey = DictOps.NullToObj(key);
         object ret;
         lock (this) if (TryGetValue(realKey, out ret))
             {
                 return(ret);
             }
         throw Ops.KeyError("'{0}'", key);
     }
     set {
         lock (this) data[DictOps.NullToObj(key)] = value;
     }
 }
Exemple #3
0
        public static void Update(IDictionary <object, object> self, object b)
        {
            object      keysFunc;
            IDictionary dict = b as IDictionary;

            if (dict != null)
            {
                IDictionaryEnumerator e = dict.GetEnumerator();
                while (e.MoveNext())
                {
                    self[DictOps.NullToObj(e.Key)] = e.Value;
                }
            }
            else if (Ops.TryGetAttr(b, SymbolTable.Keys, out keysFunc))
            {
                // user defined dictionary
                IEnumerator i = Ops.GetEnumerator(Ops.Call(keysFunc));
                while (i.MoveNext())
                {
                    self[DictOps.NullToObj(i.Current)] = Ops.GetIndex(b, i.Current);
                }
            }
            else
            {
                // list of lists (key/value pairs), list of tuples,
                // tuple of tuples, etc...
                IEnumerator i     = Ops.GetEnumerator(b);
                int         index = 0;
                while (i.MoveNext())
                {
                    if (!AddKeyValue(self, i.Current))
                    {
                        throw Ops.ValueError("dictionary update sequence element #{0} has bad length; 2 is required", index);
                    }
                    index++;
                }
            }
        }
Exemple #4
0
 public bool TryGetValue(object key, out object value)
 {
     lock (this) return(data.TryGetValue(DictOps.NullToObj(key), out value));
 }
Exemple #5
0
 public bool Remove(object key)
 {
     lock (this) return(data.Remove(DictOps.NullToObj(key)));
 }
Exemple #6
0
 public bool ContainsKey(object key)
 {
     lock (this) return(data.ContainsKey(DictOps.NullToObj(key)));
 }
Exemple #7
0
 void Replace(object key, object value)
 {
     lock (this) data[DictOps.NullToObj(key)] = value;
 }
Exemple #8
0
 public void Add(object key, object value)
 {
     lock (this) data.Add(DictOps.NullToObj(key), value);
 }
Exemple #9
0
 public bool Remove(KeyValuePair <object, object> item)
 {
     lock (this) return(data.Remove(DictOps.NullToObj(item.Key)));
 }
Exemple #10
0
 public bool Contains(KeyValuePair <object, object> item)
 {
     lock (this) return(data.ContainsKey(DictOps.NullToObj(item.Key)));
 }
Exemple #11
0
 public void Add(KeyValuePair <object, object> item)
 {
     lock (this) data[DictOps.NullToObj(item.Key)] = item.Value;
 }