public void AddNullValue()
 {
     JArray a = new JArray();
     a.Add(null);
     Assert.AreEqual(1, a.Count);
     Assert.IsNull(a[0]);
 }
        /// <summary>
        /// Accumulate values under a key. It is similar to the Put method except
        /// that if there is already an object stored under the key then a
        /// JArray is stored under the key to hold all of the accumulated values.
        /// If there is already a JArray, then the new value is appended to it.
        /// In contrast, the Put method replaces the previous value.
        /// </summary>

        public virtual JObject Accumulate(string name, object value)
        {
            if (name == null)
                throw new ArgumentNullException("name");

            object current = InnerHashtable[name];

            if (current == null)
            {
                Put(name, value);
            }
            else 
            {
                IList values = current as IList;
                
                if (values != null)
                {
                    values.Add(value);
                }
                else
                {
                    values = new JArray();
                    values.Add(current);
                    values.Add(value);
                    Put(name, values);
                }
            }

            return this;
        }
        /// <summary>
        /// Produce a JArray containing the names of the elements of this
        /// JObject.
        /// </summary>

        public virtual JArray GetNamesArray()
        {
            JArray names = new JArray();
            ListNames(names);
            return names;
        }
        /// <summary>
        /// Returns a new array consisting of a combination of two or more
        /// arrays.
        /// </summary>

        public JArray Concat(params object[] values)
        {
            JArray newArray = new JArray(this);

            if (values != null)
            {
                foreach (object value in values)
                {
                    JArray arrayValue = value as JArray;
                    
                    if (arrayValue != null)
                    {
                        foreach (object arrayValueValue in arrayValue)
                            newArray.Push(arrayValueValue);
                    }
                    else
                    {
                        newArray.Push(value);
                    }
                }
            }

            return newArray;
        }
        private object OnEnd(object current)
        {
            Debug.Assert(current != null);

            _currentArray = null;
            _currentObject = null;

            if (Stack.Count != 0)
            {
                object o = Stack.Pop();

                //
                // Pop last object as the current object or array and
                // assert that we've poppoed one of the two as a sanity check.
                //

                _currentObject = o as JObject;

                if (_currentObject == null)
                    _currentArray = o as JArray;

                Debug.Assert(_currentObject != null || _currentArray != null);
            }

            return current;
        }
        private void OnStart()
        {
            //
            // Remember the current array or object, whichever happens to be
            // the one this instance is building right now, by pushing it on to
            // the stack.
            //

            if (_currentObject != null)            
            {
                Stack.Push(_currentObject);
                _currentObject = null;
            }
            else if (_currentArray != null)
            {
                Stack.Push(_currentArray);
                _currentArray = null;
            }

            //
            // Sanity check.
            //
 
            Debug.Assert(_currentArray == null);
            Debug.Assert(_currentObject == null);
        }
 public void StartArray()
 {
     OnStart();
     _currentArray = new JArray();
 }