Пример #1
0
        public static object GetElement(RubyContext /*!*/ context, IDictionary <object, object> /*!*/ self, object key)
        {
            object result;

            if (!self.TryGetValue(CustomStringDictionary.NullToObj(key), out result))
            {
                return(null);
            }
            return(result);
        }
Пример #2
0
        public static object GetElement(BinaryOpStorage /*!*/ storage, IDictionary <object, object> /*!*/ self, object key)
        {
            object result;

            if (!self.TryGetValue(CustomStringDictionary.NullToObj(key), out result))
            {
                var site = storage.GetCallSite("default", 1);
                return(site.Target(site, self, key));
            }
            return(result);
        }
Пример #3
0
        public static Hash /*!*/ Invert(RubyContext /*!*/ context, IDictionary <object, object> /*!*/ self)
        {
            // invert returns a Hash, even from subclasses
            Hash hash = new Hash(context.EqualityComparer, self.Count);

            foreach (KeyValuePair <object, object> pair in self)
            {
                hash[CustomStringDictionary.NullToObj(pair.Value)] = CustomStringDictionary.ObjToNull(pair.Key);
            }
            return(hash);
        }
Пример #4
0
 public override void Add(ref DictionaryStorage storage, object key, object value)
 {
     lock (this) {
         string strKey = key as string;
         if (strKey != null)
         {
             _dict[strKey] = value;
         }
         else
         {
             EnsureObjectDictionary();
             _objDict[CustomStringDictionary.NullToObj(key)] = value;
         }
     }
 }
Пример #5
0
        public override bool Remove(ref DictionaryStorage storage, object key)
        {
            lock (this) {
                string strKey = key as string;
                if (strKey != null)
                {
                    return(_dict.Remove(strKey));
                }

                if (_objDict != null)
                {
                    return(_objDict.Remove(CustomStringDictionary.NullToObj(key)));
                }

                return(false);
            }
        }
Пример #6
0
        public override bool Contains(object key)
        {
            lock (this) {
                string strKey = key as string;
                if (strKey != null)
                {
                    return(_dict.ContainsKey(strKey));
                }

                if (_objDict != null)
                {
                    return(_objDict.ContainsKey(CustomStringDictionary.NullToObj(key)));
                }

                return(false);
            }
        }
Пример #7
0
        public override bool TryGetValue(object key, out object value)
        {
            lock (this) {
                string strKey = key as string;
                if (strKey != null)
                {
                    return(_dict.TryGetValue(strKey, out value));
                }

                if (_objDict != null)
                {
                    return(_objDict.TryGetValue(CustomStringDictionary.NullToObj(key), out value));
                }

                value = null;
                return(false);
            }
        }
Пример #8
0
        public static object Delete(BlockParam block, IDictionary <object, object> /*!*/ self, object key)
        {
            object value;

            if (!self.TryGetValue(CustomStringDictionary.NullToObj(key), out value))
            {
                // key not found, call the block if it was passed in
                if (block != null)
                {
                    object result;
                    block.Yield(key, out result);
                    return(result);
                }
                return(null);
            }
            self.Remove(CustomStringDictionary.NullToObj(key));
            return(value);
        }
Пример #9
0
 public static bool HasKey(IDictionary <object, object> /*!*/ self, object key)
 {
     return(self.ContainsKey(CustomStringDictionary.NullToObj(key)));
 }