Version 3.3.1.2

BaseDataWriter class

Namespace: Sirenix.Serialization
Assembly: Sirenix.Serialization
public abstract class BaseDataWriter : BaseDataReaderWriter, IDataWriter, IDisposable
Provides basic functionality and overridable abstract methods for implementing a data writer.

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

Inheritance
See Also

Constructors

BaseDataWriter(Stream, SerializationContext)
Initializes a new instance of the BaseDataWriter class.
protected BaseDataWriter(Stream stream, SerializationContext context)
Parameters
System.IO.Stream stream

The base stream of the writer.

SerializationContext context

The serialization context to use.

Exceptions
System.ArgumentNullException

The stream or context is null.

System.ArgumentException

Cannot write to the stream.

Properties

Context
Gets the serialization context.
public SerializationContext Context { get; set; }
Stream
Gets or sets the base stream of the writer.
public virtual Stream Stream { get; set; }
Exceptions
System.ArgumentNullException

value

System.ArgumentException

Cannot write to stream

Methods

BeginArrayNode(Int64)
Begins an array node of the given length.
public abstract 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 abstract 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 abstract 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 and streams kept by the data writer.
public abstract void Dispose()
EndArrayNode()
Ends the current array node, if the current node is an array node.
public abstract 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 abstract 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 virtual 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.
public abstract 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.
public virtual void PrepareNewSerializationSession()
WriteBoolean(String, Boolean)
Writes a System.Boolean value to the stream.
public abstract 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 abstract 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 abstract 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 abstract 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 abstract 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 abstract 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 abstract 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 abstract 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 abstract 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 abstract 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 abstract 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 abstract 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 abstract 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 abstract 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 abstract 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.
public abstract 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 abstract 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 abstract 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 abstract 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 abstract 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 abstract 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.