Version 2.1.0.0

IDataWriter interface

Namespace: Sirenix.Serialization
Assembly: Sirenix.Serialization
public interface IDataWriter : IDisposable
Provides a set of methods for reading data stored in a format that can be read by a corresponding IDataReader class.

If you implement this interface, it is VERY IMPORTANT that you implement each method to the *exact* specifications the documentation specifies.

It is strongly recommended to inherit from the BaseDataWriter class if you wish to implement a new data writer.

See Also
  • System.IDisposable

Properties

Binder
Gets or sets the reader's serialization binder.
TwoWaySerializationBinder Binder { get; set; }
Context
Gets the serialization context.
SerializationContext Context { get; set; }
IsInArrayNode
Gets a value indicating whether the writer is in an array node.
bool IsInArrayNode { get; }

Methods

BeginArrayNode(Int64)
Begins an array node of the given length.
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 EndNode(String), with the same name.

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 EndNode(String), with the same name.

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.

EndArrayNode()
Ends the current array node, if the current node is an array node.
void EndArrayNode()
EndNode(String)
Ends the current node with the given name. If the current node has another name, an System.InvalidOperationException is thrown.
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.
void FlushToStream()
GetDataDump()
Gets a dump of the data currently written by the writer. The format of this dump varies, but should be useful for debugging purposes.
string GetDataDump()
Returns
System.String

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.
void PrepareNewSerializationSession()
WriteBoolean(String, Boolean)
Writes a System.Boolean value to the stream.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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).

WriteSByte(String, SByte)
Writes an System.SByte value to the stream.
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.
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.
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.
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.
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.
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.