private XmlDataStoreWriter( XmlWriter xmlWriter )
        {
            Ensure.That(xmlWriter).NotNull();

            this.xmlWriter = xmlWriter;
            this.textWriter = new Mechanical.IO.StringWriter();
            this.xmlWriter.WriteStartElement(RootName);
        }
        /// <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();
            }
        }
        private static string Write( CsvFormat csvFormat, Action<CsvWriter> action )
        {
            var sw = new StringWriter();
            using( var writer = new CsvWriter(sw, csvFormat) )
            {
                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.memoryStream.NotNullReference() )
                {
                    this.memoryStream.Dispose();
                    this.memoryStream = null;
                }
            }

            //// shared cleanup logic
            //// (unmanaged resources)
            this.root = null;
            this.binaryWriter = null;
            this.textWriter = null;

            base.OnDispose(disposing);
        }
        /// <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.xmlWriter.NotNullReference() )
                {
                    this.xmlWriter.WriteFullEndElement(); // closing root xml element
                    this.xmlWriter.Close();
                    this.xmlWriter = null;
                }
            }

            //// shared cleanup logic
            //// (unmanaged resources)
            this.textWriter = null;

            base.OnDispose(disposing);
        }
        /// <summary>
        /// Returns the writer of the value.
        /// If possible, a new reader should not be created.
        /// </summary>
        /// <returns>The writer of the value.</returns>
        protected override ITextWriter OpenTextWriter()
        {
            if( this.textWriter.NullReference() )
                this.textWriter = new StringWriter();

            return this.textWriter;
        }