예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JsonWriter"/> class for writing to the <see cref="TextWriter"/>
        /// with specified settings and option to leave a stream open.
        /// </summary>
        /// <param name="textWriter">The <see cref="TextWriter"/> to write data to.</param>
        /// <param name="settings">The settings for writing data in JSON format.</param>
        /// <param name="leaveOpen">
        ///   <c>true</c> to leave the stream open after the value was written;
        ///   <c>false</c> to close the stream.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///   <paramref name="textWriter"/> is <c>null</c>
        ///   or
        ///   <paramref name="settings"/> is <c>null</c>.
        /// </exception>
        public JsonWriter(TextWriter textWriter, JsonWriterSettings settings, bool leaveOpen)
        {
            if (textWriter == null)
            {
                throw new ArgumentNullException("textWriter");
            }

            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            // Store the provided text reader
            this.textWriter = textWriter;
            this.Settings   = settings;
            this.leaveOpen  = leaveOpen;
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JsonWriter"/> class for writing to the
        /// <see cref="StringBuilder"/> with specified settings.
        /// </summary>
        /// <param name="jsonString">The <see cref="StringBuilder"/> to write data to.</param>
        /// <param name="settings">The settings for writing data in JSON format.</param>
        /// <exception cref="ArgumentNullException">
        ///   <paramref name="jsonString"/> is <c>null</c>
        ///   or
        ///   <paramref name="settings"/> is <c>null</c>.
        /// </exception>
        public JsonWriter(StringBuilder jsonString, JsonWriterSettings settings)
        {
            if (jsonString == null)
            {
                throw new ArgumentNullException("jsonString");
            }

            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            // Initialize a new string reader
            this.textWriter = new StringWriter(jsonString);
            this.Settings   = settings;
            this.leaveOpen  = false;
        }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JsonWriter"/> class for writing to the <see cref="Stream"/>
        /// with specified settings, encoding and option to leave a stream open.
        /// </summary>
        /// <param name="jsonStream">The <see cref="Stream"/> to write data to.</param>
        /// <param name="settings">The settings for writing data in JSON format.</param>
        /// <param name="encoding">The character encoding to use.</param>
        /// <param name="leaveOpen">
        ///   <c>true</c> to leave the stream open after the value was written;
        ///   <c>false</c> to close the stream.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///   <paramref name="jsonStream"/> is <c>null</c>
        ///   or
        ///   <paramref name="settings"/> is <c>null</c>
        ///   or
        ///   <paramref name="encoding"/> is <c>null</c>.
        /// </exception>
        public JsonWriter(Stream jsonStream, JsonWriterSettings settings, Encoding encoding, bool leaveOpen)
        {
            if (jsonStream == null)
            {
                throw new ArgumentNullException("jsonStream");
            }

            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            if (encoding == null)
            {
                throw new ArgumentNullException("encoding");
            }

            // Initialize a new stream reader
            this.textWriter = new StreamWriter(jsonStream, encoding);
            this.Settings   = settings;
            this.leaveOpen  = leaveOpen;
        }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JsonWriter"/> class for writing to the <see cref="TextWriter"/>
 /// with specified settings.
 /// </summary>
 /// <param name="textWriter">The <see cref="TextWriter"/> to write data to.</param>
 /// <param name="settings">The settings for writing data in JSON format.</param>
 /// <exception cref="ArgumentNullException">
 ///   <paramref name="textWriter"/> is <c>null</c>
 ///   or
 ///   <paramref name="settings"/> is <c>null</c>.
 /// </exception>
 public JsonWriter(TextWriter textWriter, JsonWriterSettings settings)
 // ReSharper disable IntroduceOptionalParameters.Global
     : this(textWriter, settings, false)
     // ReSharper restore IntroduceOptionalParameters.Global
 {
 }
예제 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JsonWriter"/> class for writing to the <see cref="Stream"/>
 /// with specified settings and encoding.
 /// </summary>
 /// <param name="jsonStream">The <see cref="Stream"/> to write data to.</param>
 /// <param name="settings">The settings for writing data in JSON format.</param>
 /// <param name="encoding">The character encoding to use.</param>
 /// <exception cref="ArgumentNullException">
 ///   <paramref name="jsonStream"/> is <c>null</c>
 ///   or
 ///   <paramref name="settings"/> is <c>null</c>
 ///   or
 ///   <paramref name="encoding"/> is <c>null</c>.
 /// </exception>
 public JsonWriter(Stream jsonStream, JsonWriterSettings settings, Encoding encoding)
 // ReSharper disable IntroduceOptionalParameters.Global
     : this(jsonStream, settings, encoding, false)
     // ReSharper restore IntroduceOptionalParameters.Global
 {
 }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JsonWriter"/> class for writing to the <see cref="Stream"/>
 /// with specified settings.
 /// </summary>
 /// <param name="jsonStream">The <see cref="Stream"/> to write data to.</param>
 /// <param name="settings">The settings for writing data in JSON format.</param>
 /// <exception cref="ArgumentNullException">
 ///   <paramref name="jsonStream"/> is <c>null</c>
 ///   or
 ///   <paramref name="settings"/> is <c>null</c>.
 /// </exception>
 public JsonWriter(Stream jsonStream, JsonWriterSettings settings)
     : this(jsonStream, settings, JsonWriter.DefaultEncoding, false)
 {
 }