/// <summary> /// Creates a new <see cref="JsonWriter"/> instance and write content to the /// provided <see cref="Stream"/> with custom formatting. /// </summary> /// <param name="stream">Stream that data will be written to.</param> /// <param name="settings">Custom settings.</param> /// <returns> /// New <see cref="JsonWriter"/> instance. /// </returns> /// <exception cref="System.ArgumentNullException"> /// <list type="bullet"> /// <item>If <paramref name="stream"/> is <c>null</c>.</item> /// <item>If <paramref name="settings"/> is <c>null</c>.</item> /// </list> /// </exception> /// <exception cref="System.ArgumentException"> /// If <paramref name="stream"/> is not writable. /// </exception> public static JsonWriter Create(Stream stream, JsonWriterSettings settings) { if (stream == null) { throw new ArgumentNullException("stream"); } if (!stream.CanWrite) { throw new ArgumentException("Cannot write to stream.", "stream"); } if (settings == null) { throw new ArgumentNullException("settings"); } return(new JsonWriter(new StreamWriter(stream), settings)); }
/// <summary> /// Initializes a new instance of the <see cref="JsonWriter"/> class. /// </summary> /// <param name="textWriter">Text writer.</param> /// <param name="settings">Custom settings.</param> /// <exception cref="System.ArgumentNullException"> /// <list type="bullet"> /// <item>If <paramref name="textWriter"/> is <c>null</c>.</item> /// <item>If <paramref name="settings"/> is <c>null</c>.</item> /// </list> /// </exception> private JsonWriter(TextWriter textWriter, JsonWriterSettings settings) { if (textWriter == null) { throw new ArgumentNullException("textWriter"); } if (settings == null) { throw new ArgumentNullException("settings"); } this.writer = textWriter; this.Settings = settings; settings.MarkReadOnly(); this.writeContextStack.Push(WriteContext.Root); }
static JsonWriterSettings() { DefaultSettings = new JsonWriterSettings(); DefaultSettings.MarkReadOnly(); }
/// <summary> /// Creates a new <see cref="JsonWriter"/> instance with custom formatting. /// </summary> /// <param name="settings">Custom settings.</param> /// <returns> /// New <see cref="JsonWriter"/> instance. /// </returns> public static JsonWriter Create(JsonWriterSettings settings) { return(Create(new StringWriter(), settings)); }