/// <summary> /// Initializes a new instance of the <see cref="JsonDataStoreWriter"/> class. /// </summary> /// <param name="jsonWriter">The <see cref="JsonWriter"/> to use.</param> public JsonDataStoreWriter( JsonWriter jsonWriter ) { Ensure.That(jsonWriter).NotNull(); this.jsonWriter = jsonWriter; this.textWriter = new Mechanical.IO.StringWriter(); this.jsonWriter.WriteObjectStart(); }
private static string Write( bool indent, bool produceAscii, Action<JsonWriter> action ) { var sw = new StringWriter(); using( var writer = new JsonWriter(sw, indent, produceAscii) ) { action(writer); sw.Flush(); return sw.ToString(); } }
/// <summary> /// Called when the object is being disposed of. Inheritors must call base.OnDispose to be properly disposed. /// </summary> /// <param name="disposing">If set to <c>true</c>, release both managed and unmanaged resources; otherwise release only the unmanaged resources.</param> protected override void OnDispose( bool disposing ) { if( disposing ) { //// dispose-only (i.e. non-finalizable) logic //// (managed, disposable resources you own) if( this.jsonWriter.NotNullReference() ) { this.jsonWriter.WriteObjectEnd(); // closing root json object this.jsonWriter.Dispose(); this.jsonWriter = null; } } //// shared cleanup logic //// (unmanaged resources) this.textWriter = null; base.OnDispose(disposing); }