Version 3.3.1.2

JsonDataWriter class

Namespace: Sirenix.Serialization
Assembly: Sirenix.Serialization
public class JsonDataWriter : BaseDataWriter, IDataWriter, IDisposable
Writes json data to a stream that can be read by a JsonDataReader.
Inheritance
See Also

Constructors

JsonDataWriter()
public JsonDataWriter()
JsonDataWriter(Stream, SerializationContext, Boolean)
Initializes a new instance of the JsonDataWriter class.
public JsonDataWriter(Stream stream, SerializationContext context, bool formatAsReadable = true)
Parameters
System.IO.Stream stream

The base stream of the writer.

SerializationContext context

The serialization context to use.

System.Boolean formatAsReadable

Whether the json should be packed, or formatted as human-readable.

Fields

EnableTypeOptimization
Whether to enable an optimization that ensures any given type name is only written once into the json stream, and thereafter kept track of by ID.
public bool EnableTypeOptimization
FormatAsReadable
Gets or sets a value indicating whether the json should be packed, or formatted as human-readable.
public bool FormatAsReadable

Methods

BeginArrayNode(Int64)
Begins an array node of the given length.
public override void BeginArrayNode(long length)
Parameters
System.Int64 length

The length of the array to come.

BeginReferenceNode(String, Type, Int32)
Writes the beginning of a reference node.

This call MUST eventually be followed by a corresponding call to Sirenix.Serialization.IDataWriter.EndNode(System.String), with the same name.

public override void BeginReferenceNode(string name, Type type, int id)
Parameters
System.String name

The name of the reference node.

System.Type type

The type of the reference node. If null, no type metadata will be written.

System.Int32 id

The id of the reference node. This id is acquired by calling TryRegisterInternalReference(Object, out Int32).

BeginStructNode(String, Type)
Begins a struct/value type node. This is essentially the same as a reference node, except it has no internal reference id.

This call MUST eventually be followed by a corresponding call to Sirenix.Serialization.IDataWriter.EndNode(System.String), with the same name.

public override void BeginStructNode(string name, Type type)
Parameters
System.String name

The name of the struct node.

System.Type type

The type of the struct node. If null, no type metadata will be written.

Dispose()
Disposes all resources kept by the data writer, except the stream, which can be reused later.
public override void Dispose()
EndArrayNode()
Ends the current array node, if the current node is an array node.
public override void EndArrayNode()
EndNode(String)
Ends the current node with the given name. If the current node has another name, an System.InvalidOperationException is thrown.
public override void EndNode(string name)
Parameters
System.String name

The name of the node to end. This has to be the name of the current node.

FlushToStream()
Flushes everything that has been written so far to the writer's base stream.
public override void FlushToStream()
GetDataDump()
public override string GetDataDump()
Returns
System.String

MarkJustStarted()
Enable the "just started" flag, causing the writer to start a new "base" json object container.
public void MarkJustStarted()
PrepareNewSerializationSession()
Tells the writer that a new serialization session is about to begin, and that it should clear all cached values left over from any prior serialization sessions. This method is only relevant when the same writer is used to serialize several different, unrelated values.
public override void PrepareNewSerializationSession()
WriteBoolean(String, Boolean)
Writes a System.Boolean value to the stream.
public override void WriteBoolean(string name, bool value)
Parameters
System.String name

The name of the value. If this is null, no name will be written.

System.Boolean value

The value to write.

WriteByte(String, Byte)
Writes a System.Byte value to the stream.
public override void WriteByte(string name, byte value)
Parameters
System.String name

The name of the value. If this is null, no name will be written.

System.Byte value

The value to write.

WriteChar(String, Char)
Writes a System.Char value to the stream.
public override void WriteChar(string name, char value)
Parameters
System.String name

The name of the value. If this is null, no name will be written.

System.Char value

The value to write.

WriteDecimal(String, Decimal)
Writes a System.Decimal value to the stream.
public override void WriteDecimal(string name, decimal value)
Parameters
System.String name

The name of the value. If this is null, no name will be written.

System.Decimal value

The value to write.

WriteDouble(String, Double)
Writes a System.Double value to the stream.
public override void WriteDouble(string name, double value)
Parameters
System.String name

The name of the value. If this is null, no name will be written.

System.Double value

The value to write.

WriteExternalReference(String, Guid)
Writes an external guid reference to the stream.
public override void WriteExternalReference(string name, Guid guid)
Parameters
System.String name

The name of the value. If this is null, no name will be written.

System.Guid guid

The value to write.

WriteExternalReference(String, Int32)
Writes an external index reference to the stream.
public override void WriteExternalReference(string name, int index)
Parameters
System.String name

The name of the value. If this is null, no name will be written.

System.Int32 index

The value to write.

WriteExternalReference(String, String)
Writes an external string reference to the stream.
public override void WriteExternalReference(string name, string id)
Parameters
System.String name

The name of the value. If this is null, no name will be written.

System.String id

The value to write.

WriteGuid(String, Guid)
Writes a System.Guid value to the stream.
public override void WriteGuid(string name, Guid value)
Parameters
System.String name

The name of the value. If this is null, no name will be written.

System.Guid value

The value to write.

WriteInt16(String, Int16)
Writes a System.Int16 value to the stream.
public override void WriteInt16(string name, short value)
Parameters
System.String name

The name of the value. If this is null, no name will be written.

System.Int16 value

The value to write.

WriteInt32(String, Int32)
Writes an System.Int32 value to the stream.
public override void WriteInt32(string name, int value)
Parameters
System.String name

The name of the value. If this is null, no name will be written.

System.Int32 value

The value to write.

WriteInt64(String, Int64)
Writes a System.Int64 value to the stream.
public override void WriteInt64(string name, long value)
Parameters
System.String name

The name of the value. If this is null, no name will be written.

System.Int64 value

The value to write.

WriteInternalReference(String, Int32)
Writes an internal reference to the stream.
public override void WriteInternalReference(string name, int id)
Parameters
System.String name

The name of the value. If this is null, no name will be written.

System.Int32 id

The value to write.

WriteNull(String)
Writes a null value to the stream.
public override void WriteNull(string name)
Parameters
System.String name

The name of the value. If this is null, no name will be written.

WritePrimitiveArray<T>(T[])
Writes a primitive array to the stream.
public override void WritePrimitiveArray<T>(T[] array)
    where T : struct
Parameters
T[] array

The primitive array to write.

Type Parameters
T

The element type of the primitive array. Valid element types can be determined using IsPrimitiveArrayType(Type).

Exceptions
System.ArgumentException

Type + typeof(T).Name + is not a valid primitive array type.

System.ArgumentNullException

array

WriteSByte(String, SByte)
Writes an System.SByte value to the stream.
public override void WriteSByte(string name, sbyte value)
Parameters
System.String name

The name of the value. If this is null, no name will be written.

System.SByte value

The value to write.

WriteSingle(String, Single)
Writes a System.Single value to the stream.
public override void WriteSingle(string name, float value)
Parameters
System.String name

The name of the value. If this is null, no name will be written.

System.Single value

The value to write.

WriteString(String, String)
Writes a System.String value to the stream.
public override void WriteString(string name, string value)
Parameters
System.String name

The name of the value. If this is null, no name will be written.

System.String value

The value to write.

WriteUInt16(String, UInt16)
Writes an System.UInt16 value to the stream.
public override void WriteUInt16(string name, ushort value)
Parameters
System.String name

The name of the value. If this is null, no name will be written.

System.UInt16 value

The value to write.

WriteUInt32(String, UInt32)
Writes an System.UInt32 value to the stream.
public override void WriteUInt32(string name, uint value)
Parameters
System.String name

The name of the value. If this is null, no name will be written.

System.UInt32 value

The value to write.

WriteUInt64(String, UInt64)
Writes an System.UInt64 value to the stream.
public override void WriteUInt64(string name, ulong value)
Parameters
System.String name

The name of the value. If this is null, no name will be written.

System.UInt64 value

The value to write.