/// <summary>
		/// Ctor
		/// </summary>
		/// <param name="settings">JsonWriterSettings</param>
		public JsonDataWriter(JsonWriterSettings settings)
		{
			if (settings == null)
			{
				throw new ArgumentNullException("settings");
			}
			this.Settings = settings;
		}
        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="output">StringBuilder for appending</param>
        /// <param name="settings">JsonWriterSettings</param>
        public JsonWriter(StringBuilder output, JsonWriterSettings settings)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            this.Writer         = new StringWriter(output, System.Globalization.CultureInfo.InvariantCulture);
            this.settings       = settings;
            this.Writer.NewLine = this.settings.NewLine;
        }
        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="output">Stream for writing</param>
        /// <param name="settings">JsonWriterSettings</param>
        public JsonWriter(Stream output, JsonWriterSettings settings)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            this.Writer         = new StreamWriter(output, Encoding.UTF8);
            this.settings       = settings;
            this.Writer.NewLine = this.settings.NewLine;
        }
        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="output">file name for writing</param>
        /// <param name="settings">JsonWriterSettings</param>
        public JsonWriter(string outputFileName, JsonWriterSettings settings)
        {
            if (outputFileName == null)
            {
                throw new ArgumentNullException("outputFileName");
            }
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            Stream stream = new FileStream(outputFileName, FileMode.Create, FileAccess.Write, FileShare.Read);

            this.Writer         = new StreamWriter(stream, Encoding.UTF8);
            this.settings       = settings;
            this.Writer.NewLine = this.settings.NewLine;
        }
        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="output">TextWriter for writing</param>
        /// <param name="settings">JsonWriterSettings</param>
        public JsonWriter(TextWriter output, JsonWriterSettings settings)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            this.Writer         = output;
            this.settings       = settings;
            this.Writer.NewLine = this.settings.NewLine;

            if (settings.HandleCyclicReferences)
            {
                this.previouslySerializedObjects = new Dictionary <object, int> ();
            }
        }
		/// <summary>
		/// Ctor
		/// </summary>
		/// <param name="output">TextWriter for writing</param>
		/// <param name="settings">JsonWriterSettings</param>
		public JsonWriter (TextWriter output, JsonWriterSettings settings)
		{
			if (output == null) {
				throw new ArgumentNullException ("output");
			}
			if (settings == null) {
				throw new ArgumentNullException ("settings");
			}

			this.Writer = output;
			this.settings = settings;
			this.Writer.NewLine = this.settings.NewLine;
			
			if (settings.HandleCyclicReferences)
			{
				this.previouslySerializedObjects = new Dictionary<object, int> ();
			}
		}
		// <summary>
		/// A helper method for serializing an object to JSON
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		public static string Serialize(object value, JsonWriterSettings settings)
		{
			StringBuilder output = new StringBuilder();
			
			using (JsonWriter writer = new JsonWriter(output, settings))
			{
				writer.Write(value);
			}
			
			return output.ToString();
		}
		/// <summary>
		/// Ctor
		/// </summary>
		/// <param name="output">StringBuilder for appending</param>
		/// <param name="settings">JsonWriterSettings</param>
		public JsonWriter(StringBuilder output, JsonWriterSettings settings)
		{
			if (output == null)
			{
				throw new ArgumentNullException("output");
			}
			if (settings == null)
			{
				throw new ArgumentNullException("settings");
			}

			this.Writer = new StringWriter(output, System.Globalization.CultureInfo.InvariantCulture);
			this.settings = settings;
			this.Writer.NewLine = this.settings.NewLine;
		}
		/// <summary>
		/// Ctor
		/// </summary>
		/// <param name="output">file name for writing</param>
		/// <param name="settings">JsonWriterSettings</param>
		public JsonWriter(string outputFileName, JsonWriterSettings settings)
		{
			if (outputFileName == null)
			{
				throw new ArgumentNullException("outputFileName");
			}
			if (settings == null)
			{
				throw new ArgumentNullException("settings");
			}

			Stream stream = new FileStream(outputFileName, FileMode.Create, FileAccess.Write, FileShare.Read);
			this.Writer = new StreamWriter(stream, Encoding.UTF8);
			this.settings = settings;
			this.Writer.NewLine = this.settings.NewLine;
		}
		/// <summary>
		/// Ctor
		/// </summary>
		/// <param name="output">Stream for writing</param>
		/// <param name="settings">JsonWriterSettings</param>
		public JsonWriter(Stream output, JsonWriterSettings settings)
		{
			if (output == null)
			{
				throw new ArgumentNullException("output");
			}
			if (settings == null)
			{
				throw new ArgumentNullException("settings");
			}

			this.Writer = new StreamWriter(output, Encoding.UTF8);
			this.settings = settings;
			this.Writer.NewLine = this.settings.NewLine;
		}
		/// <summary>
		/// Builds a common settings objects
		/// </summary>
		/// <param name="prettyPrint"></param>
		/// <returns></returns>
		public static JsonWriterSettings CreateSettings(bool prettyPrint)
		{
			JsonWriterSettings settings = new JsonWriterSettings();

			settings.PrettyPrint = prettyPrint;

			return settings;
		}