Esempio n. 1
0
        /// <summary>
        /// Writes a text representation of the specified <paramref name="arrayValue"/> into a text writer.
        /// </summary>
        /// <param name="arrayValue">The JSON value to write.</param>
        private void WriteArray(JsonArray arrayValue)
        {
            var startArrayTextAnnotation = arrayValue.GetAnnotation <JsonStartArrayTextAnnotation>()
                                           ?? JsonStartArrayTextAnnotation.GetDefault(this.writer);
            var endArrayTextAnnotation = arrayValue.GetAnnotation <JsonEndArrayTextAnnotation>()
                                         ?? JsonEndArrayTextAnnotation.GetDefault(this.writer);

            this.writer.Write(startArrayTextAnnotation.Text);

            bool first = true;

            foreach (JsonValue element in arrayValue.Elements)
            {
                var arrayElementSeparatorTextAnnotation = element.GetAnnotation <JsonArrayElementSeparatorTextAnnotation>()
                                                          ?? JsonArrayElementSeparatorTextAnnotation.GetDefault(first);
                first = false;

                this.writer.Write(arrayElementSeparatorTextAnnotation.Text);
                this.WriteValue(element);
            }

            this.writer.Write(endArrayTextAnnotation.Text);
        }
        /// <summary>
        /// Writes a text representation of the specified <paramref name="arrayValue"/> into a text writer.
        /// </summary>
        /// <param name="arrayValue">The JSON value to write.</param>
        private void WriteArray(JsonArray arrayValue)
        {
            var startArrayTextAnnotation = arrayValue.GetAnnotation<JsonStartArrayTextAnnotation>()
                ?? JsonStartArrayTextAnnotation.GetDefault(this.writer);
            var endArrayTextAnnotation = arrayValue.GetAnnotation<JsonEndArrayTextAnnotation>()
                ?? JsonEndArrayTextAnnotation.GetDefault(this.writer);

            this.writer.Write(startArrayTextAnnotation.Text);

            bool first = true;
            foreach (JsonValue element in arrayValue.Elements)
            {
                var arrayElementSeparatorTextAnnotation = element.GetAnnotation<JsonArrayElementSeparatorTextAnnotation>()
                    ?? JsonArrayElementSeparatorTextAnnotation.GetDefault(first);
                first = false;

                this.writer.Write(arrayElementSeparatorTextAnnotation.Text);
                this.WriteValue(element);
            }

            this.writer.Write(endArrayTextAnnotation.Text);
        }