Class JsonWriter
Represents a writer that provides a fast, non-cached, forward-only way of generating JSON data.
Implements
Inherited Members
Namespace: Bayat.Json
Assembly: Bayat.Json.Runtime.dll
Syntax
public abstract class JsonWriter : IDisposable
Constructors
| Improve this Doc View SourceJsonWriter()
Creates an instance of the JsonWriter
class.
Declaration
protected JsonWriter()
Fields
| Improve this Doc View SourceStateArrayTempate
Declaration
public static readonly JsonWriter.State[][] StateArrayTempate
Field Value
Type | Description |
---|---|
JsonWriter.State[][] |
Properties
| Improve this Doc View SourceCloseOutput
Gets or sets a value indicating whether the underlying stream or System.IO.TextReader should be closed when the writer is closed.
Declaration
public bool CloseOutput { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | true to close the underlying stream or System.IO.TextReader when the writer is closed; otherwise false. The default is true. |
ContainerPath
Declaration
public string ContainerPath { get; }
Property Value
Type | Description |
---|---|
System.String |
Culture
Gets or sets the culture used when writing JSON. Defaults to System.Globalization.CultureInfo.InvariantCulture.
Declaration
public CultureInfo Culture { get; set; }
Property Value
Type | Description |
---|---|
System.Globalization.CultureInfo |
DateFormatHandling
Get or set how dates are written to JSON text.
Declaration
public DateFormatHandling DateFormatHandling { get; set; }
Property Value
Type | Description |
---|---|
DateFormatHandling |
DateFormatString
Get or set how System.DateTime and System.DateTimeOffset values are formatting when writing JSON text.
Declaration
public string DateFormatString { get; set; }
Property Value
Type | Description |
---|---|
System.String |
DateTimeZoneHandling
Get or set how System.DateTime time zones are handling when writing JSON text.
Declaration
public DateTimeZoneHandling DateTimeZoneHandling { get; set; }
Property Value
Type | Description |
---|---|
DateTimeZoneHandling |
FloatFormatHandling
Get or set how special floating point numbers, e.g. System.Double.NaN, System.Double.PositiveInfinity and System.Double.NegativeInfinity, are written to JSON text.
Declaration
public FloatFormatHandling FloatFormatHandling { get; set; }
Property Value
Type | Description |
---|---|
FloatFormatHandling |
Formatting
Indicates how JSON text output is formatted.
Declaration
public Formatting Formatting { get; set; }
Property Value
Type | Description |
---|---|
Formatting |
Path
Gets the path of the writer.
Declaration
public string Path { get; }
Property Value
Type | Description |
---|---|
System.String |
StringEscapeHandling
Get or set how strings are escaped when writing JSON text.
Declaration
public StringEscapeHandling StringEscapeHandling { get; set; }
Property Value
Type | Description |
---|---|
StringEscapeHandling |
Top
Gets the top.
Declaration
public int Top { get; }
Property Value
Type | Description |
---|---|
System.Int32 | The top. |
WriteState
Gets the state of the writer.
Declaration
public WriteState WriteState { get; }
Property Value
Type | Description |
---|---|
WriteState |
Methods
| Improve this Doc View SourceAutoComplete(JsonToken)
Declaration
public void AutoComplete(JsonToken tokenBeingWritten)
Parameters
Type | Name | Description |
---|---|---|
JsonToken | tokenBeingWritten |
BuildStateArray()
Declaration
public static JsonWriter.State[][] BuildStateArray()
Returns
Type | Description |
---|---|
JsonWriter.State[][] |
Close()
Closes this stream and the underlying stream.
Declaration
public virtual void Close()
Dispose(Boolean)
Releases unmanaged and - optionally - managed resources
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing |
|
Flush()
Flushes whatever is in the buffer to the underlying streams and also flushes the underlying stream.
Declaration
public abstract void Flush()
InternalWriteComment()
Declaration
protected void InternalWriteComment()
InternalWriteEnd(JsonContainerType)
Declaration
protected void InternalWriteEnd(JsonContainerType container)
Parameters
Type | Name | Description |
---|---|---|
JsonContainerType | container |
InternalWritePropertyName(String)
Declaration
protected void InternalWritePropertyName(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name |
InternalWriteRaw()
Declaration
protected void InternalWriteRaw()
InternalWriteStart(JsonToken, JsonContainerType)
Declaration
protected void InternalWriteStart(JsonToken token, JsonContainerType container)
Parameters
Type | Name | Description |
---|---|---|
JsonToken | token | |
JsonContainerType | container |
InternalWriteValue(JsonToken)
Declaration
protected void InternalWriteValue(JsonToken token)
Parameters
Type | Name | Description |
---|---|---|
JsonToken | token |
InternalWriteWhitespace(String)
Declaration
protected void InternalWriteWhitespace(string ws)
Parameters
Type | Name | Description |
---|---|---|
System.String | ws |
OnStringEscapeHandlingChanged()
Declaration
protected virtual void OnStringEscapeHandlingChanged()
SetWriteState(JsonToken, Object)
Sets the state of the JsonWriter,
Declaration
protected void SetWriteState(JsonToken token, object value)
Parameters
Type | Name | Description |
---|---|---|
JsonToken | token | The JsonToken being written. |
System.Object | value | The value being written. |
UpdateScopeWithFinishedValue()
Declaration
public void UpdateScopeWithFinishedValue()
WriteComment(String)
Writes out a comment
/.../
containing the specified text.
Declaration
public virtual void WriteComment(string text)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | Text to place inside the comment. |
WriteEnd()
Writes the end of the current JSON object or array.
Declaration
public virtual void WriteEnd()
WriteEnd(JsonToken)
Writes the specified end token.
Declaration
protected virtual void WriteEnd(JsonToken token)
Parameters
Type | Name | Description |
---|---|---|
JsonToken | token | The end token to write. |
WriteEndArray()
Writes the end of an array.
Declaration
public virtual void WriteEndArray()
WriteEndConstructor()
Writes the end constructor.
Declaration
public virtual void WriteEndConstructor()
WriteEndObject()
Writes the end of a JSON object.
Declaration
public virtual void WriteEndObject()
WriteIndent()
Writes indent characters.
Declaration
protected virtual void WriteIndent()
WriteIndentSpace()
Writes an indent space.
Declaration
protected virtual void WriteIndentSpace()
WriteNull()
Writes a null value.
Declaration
public virtual void WriteNull()
WriteProperty(String, Object)
Writes the property name and value of a name/value pair on a JSON object.
Declaration
public virtual void WriteProperty(string name, object value)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the property. |
System.Object | value | The value of the property. |
WritePropertyName(String)
Writes the property name of a name/value pair on a JSON object.
Declaration
public virtual void WritePropertyName(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the property. |
WritePropertyName(String, Boolean)
Writes the property name of a name/value pair on a JSON object.
Declaration
public virtual void WritePropertyName(string name, bool escape)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the property. |
System.Boolean | escape | A flag to indicate whether the text should be escaped when it is written as a JSON property name. |
WriteRaw(String)
Writes raw JSON without changing the writer's state.
Declaration
public virtual void WriteRaw(string json)
Parameters
Type | Name | Description |
---|---|---|
System.String | json | The raw JSON to write. |
WriteRawValue(String)
Writes raw JSON where a value is expected and updates the writer's state.
Declaration
public virtual void WriteRawValue(string json)
Parameters
Type | Name | Description |
---|---|---|
System.String | json | The raw JSON to write. |
WriteStartArray()
Writes the beginning of a JSON array.
Declaration
public virtual void WriteStartArray()
WriteStartConstructor(String)
Writes the start of a constructor with the given name.
Declaration
public virtual void WriteStartConstructor(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the constructor. |
WriteStartObject()
Writes the beginning of a JSON object.
Declaration
public virtual void WriteStartObject()
WriteToken(JsonReader)
Writes the current JsonReader token and its children.
Declaration
public void WriteToken(JsonReader reader)
Parameters
Type | Name | Description |
---|---|---|
JsonReader | reader | The JsonReader to read the token from. |
WriteToken(JsonReader, Boolean)
Writes the current JsonReader token.
Declaration
public void WriteToken(JsonReader reader, bool writeChildren)
Parameters
Type | Name | Description |
---|---|---|
JsonReader | reader | The JsonReader to read the token from. |
System.Boolean | writeChildren | A flag indicating whether the current token's children should be written. |
WriteToken(JsonReader, Boolean, Boolean, Boolean)
Declaration
public virtual void WriteToken(JsonReader reader, bool writeChildren, bool writeDateConstructorAsDate, bool writeComments)
Parameters
Type | Name | Description |
---|---|---|
JsonReader | reader | |
System.Boolean | writeChildren | |
System.Boolean | writeDateConstructorAsDate | |
System.Boolean | writeComments |
WriteToken(JsonToken)
Writes the JsonToken token.
Declaration
public void WriteToken(JsonToken token)
Parameters
Type | Name | Description |
---|---|---|
JsonToken | token | The JsonToken to write. |
WriteToken(JsonToken, Object)
Writes the JsonToken token and its value.
Declaration
public void WriteToken(JsonToken token, object value)
Parameters
Type | Name | Description |
---|---|---|
JsonToken | token | The JsonToken to write. |
System.Object | value | The value to write. A value is only required for tokens that have an associated value, e.g. the System.String property name for PropertyName. A null value can be passed to the method for token's that don't have a value, e.g. StartObject. |
WriteUndefined()
Writes an undefined value.
Declaration
public virtual void WriteUndefined()
WriteValue(JsonWriter, PrimitiveTypeCode, Object)
Declaration
public static void WriteValue(JsonWriter writer, PrimitiveTypeCode typeCode, object value)
Parameters
Type | Name | Description |
---|---|---|
JsonWriter | writer | |
PrimitiveTypeCode | typeCode | |
System.Object | value |
WriteValue(Boolean)
Writes a System.Boolean value.
Declaration
public virtual void WriteValue(bool value)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | value | The System.Boolean value to write. |
WriteValue(Byte)
Writes a System.Byte value.
Declaration
public virtual void WriteValue(byte value)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | value | The System.Byte value to write. |
WriteValue(Byte[])
Writes a System.Byte[] value.
Declaration
public virtual void WriteValue(byte[] value)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | value | The System.Byte[] value to write. |
WriteValue(Char)
Writes a System.Char value.
Declaration
public virtual void WriteValue(char value)
Parameters
Type | Name | Description |
---|---|---|
System.Char | value | The System.Char value to write. |
WriteValue(DateTime)
Writes a System.DateTime value.
Declaration
public virtual void WriteValue(DateTime value)
Parameters
Type | Name | Description |
---|---|---|
System.DateTime | value | The System.DateTime value to write. |
WriteValue(DateTimeOffset)
Writes a System.DateTimeOffset value.
Declaration
public virtual void WriteValue(DateTimeOffset value)
Parameters
Type | Name | Description |
---|---|---|
System.DateTimeOffset | value | The System.DateTimeOffset value to write. |
WriteValue(Decimal)
Writes a System.Decimal value.
Declaration
public virtual void WriteValue(decimal value)
Parameters
Type | Name | Description |
---|---|---|
System.Decimal | value | The System.Decimal value to write. |
WriteValue(Double)
Writes a System.Double value.
Declaration
public virtual void WriteValue(double value)
Parameters
Type | Name | Description |
---|---|---|
System.Double | value | The System.Double value to write. |
WriteValue(Guid)
Writes a System.Guid value.
Declaration
public virtual void WriteValue(Guid value)
Parameters
Type | Name | Description |
---|---|---|
System.Guid | value | The System.Guid value to write. |
WriteValue(Int16)
Writes a System.Int16 value.
Declaration
public virtual void WriteValue(short value)
Parameters
Type | Name | Description |
---|---|---|
System.Int16 | value | The System.Int16 value to write. |
WriteValue(Int32)
Writes a System.Int32 value.
Declaration
public virtual void WriteValue(int value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | value | The System.Int32 value to write. |
WriteValue(Int64)
Writes a System.Int64 value.
Declaration
public virtual void WriteValue(long value)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | value | The System.Int64 value to write. |
WriteValue(Nullable<Boolean>)
Writes a System.Nullable<T> value.
Declaration
public virtual void WriteValue(bool? value)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Boolean> | value | The System.Nullable<T> value to write. |
WriteValue(Nullable<Byte>)
Writes a System.Nullable<T> value.
Declaration
public virtual void WriteValue(byte? value)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Byte> | value | The System.Nullable<T> value to write. |
WriteValue(Nullable<Char>)
Writes a System.Nullable<T> value.
Declaration
public virtual void WriteValue(char? value)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Char> | value | The System.Nullable<T> value to write. |
WriteValue(Nullable<DateTime>)
Writes a System.Nullable<T> value.
Declaration
public virtual void WriteValue(DateTime? value)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.DateTime> | value | The System.Nullable<T> value to write. |
WriteValue(Nullable<DateTimeOffset>)
Writes a System.Nullable<T> value.
Declaration
public virtual void WriteValue(DateTimeOffset? value)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.DateTimeOffset> | value | The System.Nullable<T> value to write. |
WriteValue(Nullable<Decimal>)
Writes a System.Nullable<T> value.
Declaration
public virtual void WriteValue(decimal? value)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Decimal> | value | The System.Nullable<T> value to write. |
WriteValue(Nullable<Double>)
Writes a System.Nullable<T> value.
Declaration
public virtual void WriteValue(double? value)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Double> | value | The System.Nullable<T> value to write. |
WriteValue(Nullable<Guid>)
Writes a System.Nullable<T> value.
Declaration
public virtual void WriteValue(Guid? value)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Guid> | value | The System.Nullable<T> value to write. |
WriteValue(Nullable<Int16>)
Writes a System.Nullable<T> value.
Declaration
public virtual void WriteValue(short? value)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Int16> | value | The System.Nullable<T> value to write. |
WriteValue(Nullable<Int32>)
Writes a System.Nullable<T> value.
Declaration
public virtual void WriteValue(int? value)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Int32> | value | The System.Nullable<T> value to write. |
WriteValue(Nullable<Int64>)
Writes a System.Nullable<T> value.
Declaration
public virtual void WriteValue(long? value)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Int64> | value | The System.Nullable<T> value to write. |
WriteValue(Nullable<SByte>)
Writes a System.Nullable<T> value.
Declaration
public virtual void WriteValue(sbyte? value)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.SByte> | value | The System.Nullable<T> value to write. |
WriteValue(Nullable<Single>)
Writes a System.Nullable<T> value.
Declaration
public virtual void WriteValue(float? value)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Single> | value | The System.Nullable<T> value to write. |
WriteValue(Nullable<TimeSpan>)
Writes a System.Nullable<T> value.
Declaration
public virtual void WriteValue(TimeSpan? value)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.TimeSpan> | value | The System.Nullable<T> value to write. |
WriteValue(Nullable<UInt16>)
Writes a System.Nullable<T> value.
Declaration
public virtual void WriteValue(ushort? value)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.UInt16> | value | The System.Nullable<T> value to write. |
WriteValue(Nullable<UInt32>)
Writes a System.Nullable<T> value.
Declaration
public virtual void WriteValue(uint? value)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.UInt32> | value | The System.Nullable<T> value to write. |
WriteValue(Nullable<UInt64>)
Writes a System.Nullable<T> value.
Declaration
public virtual void WriteValue(ulong? value)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.UInt64> | value | The System.Nullable<T> value to write. |
WriteValue(Object)
Writes a System.Object value. An error will raised if the value cannot be written as a single JSON token.
Declaration
public virtual void WriteValue(object value)
Parameters
Type | Name | Description |
---|---|---|
System.Object | value | The System.Object value to write. |
WriteValue(SByte)
Writes a System.SByte value.
Declaration
public virtual void WriteValue(sbyte value)
Parameters
Type | Name | Description |
---|---|---|
System.SByte | value | The System.SByte value to write. |
WriteValue(Single)
Writes a System.Single value.
Declaration
public virtual void WriteValue(float value)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | The System.Single value to write. |
WriteValue(String)
Writes a System.String value.
Declaration
public virtual void WriteValue(string value)
Parameters
Type | Name | Description |
---|---|---|
System.String | value | The System.String value to write. |
WriteValue(TimeSpan)
Writes a System.TimeSpan value.
Declaration
public virtual void WriteValue(TimeSpan value)
Parameters
Type | Name | Description |
---|---|---|
System.TimeSpan | value | The System.TimeSpan value to write. |
WriteValue(UInt16)
Writes a System.UInt16 value.
Declaration
public virtual void WriteValue(ushort value)
Parameters
Type | Name | Description |
---|---|---|
System.UInt16 | value | The System.UInt16 value to write. |
WriteValue(UInt32)
Writes a System.UInt32 value.
Declaration
public virtual void WriteValue(uint value)
Parameters
Type | Name | Description |
---|---|---|
System.UInt32 | value | The System.UInt32 value to write. |
WriteValue(UInt64)
Writes a System.UInt64 value.
Declaration
public virtual void WriteValue(ulong value)
Parameters
Type | Name | Description |
---|---|---|
System.UInt64 | value | The System.UInt64 value to write. |
WriteValue(Uri)
Writes a System.Uri value.
Declaration
public virtual void WriteValue(Uri value)
Parameters
Type | Name | Description |
---|---|---|
System.Uri | value | The System.Uri value to write. |
WriteValueDelimiter()
Writes the JSON value delimiter.
Declaration
protected virtual void WriteValueDelimiter()
WriteWhitespace(String)
Writes out the given white space.
Declaration
public virtual void WriteWhitespace(string ws)
Parameters
Type | Name | Description |
---|---|---|
System.String | ws | The string of white space characters. |
Explicit Interface Implementations
| Improve this Doc View SourceIDisposable.Dispose()
Declaration
void IDisposable.Dispose()