예제 #1
0
        private void WriteMemberInternal(string name, string value, bool quoteValue)
        {
            JSonWriterTokenInfo currentToken = VerifyTopTokenEqualTo(JSonWriterTokenType.Object);

            if (currentToken != null)
            {
                currentToken.AddItem(_output, Indent, CompactEnumerables);
            }

            _output.Write('"');
            StringHelper.WriteSecureString(_output, name);
            _output.Write('"');

            if (CompactEnumerables)
            {
                _output.Write(':');
            }
            else
            {
                _output.Write(": ");
            }

            if (quoteValue)
            {
                _output.Write('"');
            }

            _output.Write(value);

            if (quoteValue)
            {
                _output.Write('"');
            }
        }
예제 #2
0
        /// <summary>
        /// Writes an array start.
        /// </summary>
        public void WriteArrayBegin()
        {
            JSonWriterTokenInfo currentToken = _tokens.Count > 0 ? _tokens.Peek() : null;

            _tokens.Push(new JSonWriterTokenInfo(JSonWriterTokenType.Array, _level++));

            if (currentToken != null)
            {
                currentToken.AddItem(_output, currentToken.TokenType != JSonWriterTokenType.MemberValue && Indent, CompactEnumerables);
            }

            _output.Write('[');
        }
예제 #3
0
        /// <summary>
        /// Writes an object start.
        /// </summary>
        public void WriteObjectBegin()
        {
            // object can't be directly embedded inside another object:
            JSonWriterTokenInfo currentToken = VerifyTopTokenDifferentThan(JSonWriterTokenType.Object);

            _tokens.Push(new JSonWriterTokenInfo(JSonWriterTokenType.Object, _level++));

            if (currentToken != null)
            {
                currentToken.AddItem(_output, currentToken.TokenType != JSonWriterTokenType.MemberValue && Indent, CompactEnumerables);
            }

            _output.Write('{');
        }
예제 #4
0
        /// <summary>
        /// Writes a member only to an object.
        /// It requires to be called before writing an object (or array) inside current object.
        /// Writing values after call to this function is also allowed, however it is not recommented
        /// due to number of checks performed. The better performance can be achieved
        /// if other overloaded functions are used.
        /// </summary>
        public void WriteMember(string name)
        {
            JSonWriterTokenInfo currentToken = VerifyTopTokenEqualTo(JSonWriterTokenType.Object);

            currentToken.AddItem(_output, Indent, CompactEnumerables);

            _tokens.Push(new JSonWriterTokenInfo(JSonWriterTokenType.MemberValue, _level));
            _output.Write('"');
            StringHelper.WriteSecureString(_output, name);
            _output.Write('"');
            if (CompactEnumerables)
            {
                _output.Write(':');
            }
            else
            {
                _output.Write(": ");
            }
        }
예제 #5
0
        private void WriteValueInternal(string value, bool quoteValue)
        {
            // allow adding value item, when it's just a simple writing without wrapping
            // in array or object:
            if (_tokens.Count == 0)
            {
                // push dummy item on tokens stack, so that on the next try, verification will fail,
                // only one value item can be added!
                _tokens.Push(new JSonWriterTokenInfo(JSonWriterTokenType.Nothing, -1));
                if (quoteValue)
                {
                    _output.Write('"');
                }
                _output.Write(value);
                if (quoteValue)
                {
                    _output.Write('"');
                }
                return;
            }

            JSonWriterTokenInfo currentToken = VerifyTopTokenEqualTo(JSonWriterTokenType.Array, JSonWriterTokenType.MemberValue);

            currentToken.AddItem(_output, currentToken.TokenType != JSonWriterTokenType.MemberValue && Indent, CompactEnumerables);

            if (currentToken.TokenType == JSonWriterTokenType.MemberValue)
            {
                _tokens.Pop();
            }

            if (quoteValue)
            {
                _output.Write('"');
            }
            _output.Write(value);
            if (quoteValue)
            {
                _output.Write('"');
            }
        }