Пример #1
0
 public static void RemoveVariable(string name)
 {
     if (_variableDictionary.ContainsKey(name))
     {
         _variableDictionary.Remove(name);
     }
 }
Пример #2
0
        /// <summary>
        /// Newtonsoft JSon parser fails to parse json containing a "$ref" and an adjacent
        /// object property. Google service discovery currently generates this in the "annotations"
        /// property.
        /// </summary>
        /// <param name="js"></param>
        /// <param name="depth"></param>
        internal static void RemoveAnnotations(JsonDictionary js, int depth)
        {
            if (js.ContainsKey("$ref") && js.ContainsKey("annotations") && depth >= 3)
            {
                js.Remove("annotations");
            }

            foreach (var jd in js.Values
                     .Where(o => o is JsonDictionary)
                     .Select(o => o as JsonDictionary))
            {
                RemoveAnnotations(jd, depth + 1);
            }
        }
Пример #3
0
        public bool RenameKey(string oldName, string newName)
        {
            if (!IsDictionary())
            {
                return(false);
            }

            JsonDictionary dictionary = m_value as JsonDictionary;

            object value = null;

            if (!dictionary.TryGetValue(oldName, out value))
            {
                return(false);
            }

            if (!dictionary.Remove(oldName))
            {
                return(false);                  // TODO: should we raise an exception here?
            }
            dictionary.Add(newName, value);
            return(true);
        }
Пример #4
0
        public void Remove(int count)
        {
            var keys    = RandomKeys().Take(count).ToArray();
            var removes = keys.Where((key, i) => i % 3 == 0).ToArray();

            foreach (var key in keys)
            {
                _dict.Add(key, _value);
            }
            foreach (var key in removes)
            {
                _dict.Remove(key);
            }
            var n = 0;

            foreach (var key in keys)
            {
                Assert.AreEqual(!removes.Contains(key), _dict.ContainsKey(key), n++.ToString());
            }
        }