internal void SetParentNode(CommandSchemaNode node)
 {
     if (m_isReadOnly)
     {
         throw new InvalidOperationException("Node already marked as read only");
     }
     ParentNode = node;
 }
        /// <summary>
        /// Reads to the next node. If the next node is the end of the document. False is returned. Otherwise true.
        /// </summary>
        /// <returns></returns>
        public bool Read()
        {
TryAgain:

            if (m_completed)
            {
                return(false);
            }

            if (!m_initialized)
            {
                m_initialized          = true;
                m_currentNode          = m_schema[0];
                m_isElementOrArrayNull = false;
                return(true);
            }
            else
            {
                if (IsElementOrArrayNull)
                {
                    m_isElementOrArrayNull = false;
                    m_currentNode          = m_currentNode.PairedNode;
                }
                else
                {
                    m_currentNode = m_currentNode.NextNode;
                }
            }

            if (m_currentNode == null)
            {
                m_completed = true;
                return(false);
            }

            switch (m_currentNode.Symbol)
            {
            case CommandSchemaSymbol.StartArray:
                int count = (int)m_stream.Read();
                if (count < 0)
                {
                    m_isElementOrArrayNull = true;
                    m_arrayCountStack.Push(0);
                }
                else
                {
                    m_isElementOrArrayNull = false;
                    m_arrayCountStack.Push((int)count);
                }
                break;

            case CommandSchemaSymbol.StartElement:
                m_isElementOrArrayNull = !m_stream.Read().IsBoolean;
                break;

            case CommandSchemaSymbol.Value:
                m_value = m_stream.Read();
                break;

            case CommandSchemaSymbol.EndElement:
                return(true);

            case CommandSchemaSymbol.EndArray:
                var arrayCount = m_arrayCountStack.Pop() - 1;
                if (arrayCount <= 0)
                {
                    return(true);
                }
                else
                {
                    m_arrayCountStack.Push(arrayCount);
                    m_currentNode = m_currentNode.PairedNode;
                    goto TryAgain;
                }

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(true);
        }