Class SerializationReader
A SerializationReader instance is used to read stored values and objects from a byte array.
Once an instance is created, use the various methods to read the required data. The data read MUST be exactly the same type and in the same order as it was written.
Implements
Inherited Members
Namespace: SuperOffice.IO
Assembly: SoCore.dll
Syntax
public sealed class SerializationReader : BinaryReader, IDisposable
Constructors
SerializationReader(byte[])
Creates a SerializationReader using a byte[] previous created by SerializationWriter
A MemoryStream is used to access the data without making a copy of it.
Declaration
public SerializationReader(byte[] data)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | The byte[] containining serialized data. |
SerializationReader(Stream)
Creates a SerializationReader based on the passed Stream.
Declaration
public SerializationReader(Stream stream)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The stream containing the serialized data |
Properties
BytesRemaining
Returns the number of bytes or serialized remaining to be processed. Useful for checking that deserialization is complete.
Warning: Retrieving the Position in certain stream types can be expensive, e.g. a FileStream, so use sparingly unless known to be a MemoryStream.
Declaration
public int BytesRemaining { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
DumpStringTables(ArrayList)
A SerializationReader instance is used to read stored values and objects from a byte array.
Once an instance is created, use the various methods to read the required data. The data read MUST be exactly the same type and in the same order as it was written.
Declaration
[Conditional("DEBUG")]
public void DumpStringTables(ArrayList list)
Parameters
| Type | Name | Description |
|---|---|---|
| ArrayList | list |
ReadArrayList()
Returns an ArrayList or null from the stream.
Declaration
public ArrayList ReadArrayList()
Returns
| Type | Description |
|---|---|
| ArrayList | An ArrayList instance. |
ReadBitArray()
Returns a BitArray or null from the stream.
Declaration
public BitArray ReadBitArray()
Returns
| Type | Description |
|---|---|
| BitArray | A BitArray instance. |
ReadBitVector32()
Returns a BitVector32 value from the stream.
Declaration
public BitVector32 ReadBitVector32()
Returns
| Type | Description |
|---|---|
| BitVector32 | A BitVector32 value. |
ReadBooleanArray()
Returns a Boolean[] from the stream.
Declaration
public bool[] ReadBooleanArray()
Returns
| Type | Description |
|---|---|
| bool[] | A Boolean[] instance; or null. |
ReadByteArray()
Returns a Byte[] from the stream.
Declaration
public byte[] ReadByteArray()
Returns
| Type | Description |
|---|---|
| byte[] | A Byte instance; or null. |
ReadBytesDirect(int)
Reads the specified number of bytes directly from the stream.
Declaration
public byte[] ReadBytesDirect(int count)
Parameters
| Type | Name | Description |
|---|---|---|
| int | count | The number of bytes to read |
Returns
| Type | Description |
|---|---|
| byte[] | A byte[] containing the read bytes |
ReadCharArray()
Returns a Char[] from the stream.
Declaration
public char[] ReadCharArray()
Returns
| Type | Description |
|---|---|
| char[] | A Char[] value; or null. |
ReadDateTime()
Returns a DateTime value from the stream.
Declaration
public DateTime ReadDateTime()
Returns
| Type | Description |
|---|---|
| DateTime | A DateTime value. |
ReadDateTimeArray()
Returns a DateTime[] from the stream.
Declaration
public DateTime[] ReadDateTimeArray()
Returns
| Type | Description |
|---|---|
| DateTime[] | A DateTime[] instance; or null. |
ReadDecimalArray()
Returns a Decimal[] from the stream.
Declaration
public decimal[] ReadDecimalArray()
Returns
| Type | Description |
|---|---|
| decimal[] | A Decimal[] instance; or null. |
ReadDoubleArray()
Returns a Double[] from the stream.
Declaration
public double[] ReadDoubleArray()
Returns
| Type | Description |
|---|---|
| double[] | A Double[] instance; or null. |
ReadGuid()
Returns a Guid value from the stream.
Declaration
public Guid ReadGuid()
Returns
| Type | Description |
|---|---|
| Guid | A DateTime value. |
ReadGuidArray()
Returns a Guid[] from the stream.
Declaration
public Guid[] ReadGuidArray()
Returns
| Type | Description |
|---|---|
| Guid[] | A Guid[] instance; or null. |
ReadInt16Array()
Returns an Int16[] from the stream.
Declaration
public short[] ReadInt16Array()
Returns
| Type | Description |
|---|---|
| short[] | An Int16[] instance; or null. |
ReadInt32Array()
Returns an Int32[] from the stream.
Declaration
public int[] ReadInt32Array()
Returns
| Type | Description |
|---|---|
| int[] | An Int32[] instance; or null. |
ReadInt64Array()
Returns an Int64[] from the stream.
Declaration
public long[] ReadInt64Array()
Returns
| Type | Description |
|---|---|
| long[] | An Int64[] instance; or null. |
ReadObject()
Returns an object based on the SerializedType read next from the stream.
Declaration
public object ReadObject()
Returns
| Type | Description |
|---|---|
| object | An object instance. |
ReadObjectArray()
Returns an object[] or null from the stream.
Declaration
public object[] ReadObjectArray()
Returns
| Type | Description |
|---|---|
| object[] | A DateTime value. |
ReadObjectArray(Type)
Returns an object[] or null from the stream. The returned array will be typed according to the specified element type and the resulting array can be cast to the expected type. e.g. string[] myStrings = (string[]) reader.ReadObjectArray(typeof(string));
An exception will be thrown if any of the deserialized values cannot be cast to the specified elementType.
Declaration
public object[] ReadObjectArray(Type elementType)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | elementType | The Type of the expected array elements. null will return a plain object[]. |
Returns
| Type | Description |
|---|---|
| object[] | An object[] instance. |
ReadOptimizedArrayList()
Returns an ArrayList from the stream that was stored optimized.
Declaration
public ArrayList ReadOptimizedArrayList()
Returns
| Type | Description |
|---|---|
| ArrayList | An ArrayList instance. |
ReadOptimizedBitArray()
Returns a BitArray from the stream that was stored optimized.
Declaration
public BitArray ReadOptimizedBitArray()
Returns
| Type | Description |
|---|---|
| BitArray | A BitArray instance. |
ReadOptimizedBitVector32()
Returns a BitVector32 value from the stream that was stored optimized.
Declaration
public BitVector32 ReadOptimizedBitVector32()
Returns
| Type | Description |
|---|---|
| BitVector32 | A BitVector32 value. |
ReadOptimizedBooleanArray()
Returns a Boolean[] from the stream.
Declaration
public bool[] ReadOptimizedBooleanArray()
Returns
| Type | Description |
|---|---|
| bool[] | A Boolean[] instance; or null. |
ReadOptimizedDateTime()
Returns a DateTime value from the stream that was stored optimized.
Declaration
public DateTime ReadOptimizedDateTime()
Returns
| Type | Description |
|---|---|
| DateTime | A DateTime value. |
ReadOptimizedDateTimeArray()
Returns a DateTime[] from the stream.
Declaration
public DateTime[] ReadOptimizedDateTimeArray()
Returns
| Type | Description |
|---|---|
| DateTime[] | A DateTime[] instance; or null. |
ReadOptimizedDecimal()
Returns a Decimal value from the stream that was stored optimized.
Declaration
public decimal ReadOptimizedDecimal()
Returns
| Type | Description |
|---|---|
| decimal | A Decimal value. |
ReadOptimizedDecimalArray()
Returns a Decimal[] from the stream.
Declaration
public decimal[] ReadOptimizedDecimalArray()
Returns
| Type | Description |
|---|---|
| decimal[] | A Decimal[] instance; or null. |
ReadOptimizedInt16()
Returns an Int16 value from the stream that was stored optimized.
Declaration
public short ReadOptimizedInt16()
Returns
| Type | Description |
|---|---|
| short | An Int16 value. |
ReadOptimizedInt16Array()
Returns a Int16[] from the stream.
Declaration
public short[] ReadOptimizedInt16Array()
Returns
| Type | Description |
|---|---|
| short[] | An Int16[] instance; or null. |
ReadOptimizedInt32()
Returns an Int32 value from the stream that was stored optimized.
Declaration
public int ReadOptimizedInt32()
Returns
| Type | Description |
|---|---|
| int | An Int32 value. |
ReadOptimizedInt32Array()
Returns a Int32[] from the stream.
Declaration
public int[] ReadOptimizedInt32Array()
Returns
| Type | Description |
|---|---|
| int[] | An Int32[] instance; or null. |
ReadOptimizedInt64()
Returns an Int64 value from the stream that was stored optimized.
Declaration
public long ReadOptimizedInt64()
Returns
| Type | Description |
|---|---|
| long | An Int64 value. |
ReadOptimizedInt64Array()
Returns a Int64[] from the stream.
Declaration
public long[] ReadOptimizedInt64Array()
Returns
| Type | Description |
|---|---|
| long[] | A Int64[] instance; or null. |
ReadOptimizedObjectArray()
Returns an object[] from the stream that was stored optimized.
Declaration
public object[] ReadOptimizedObjectArray()
Returns
| Type | Description |
|---|---|
| object[] | An object[] instance. |
ReadOptimizedObjectArray(Type)
Returns an object[] from the stream that was stored optimized. The returned array will be typed according to the specified element type and the resulting array can be cast to the expected type. e.g. string[] myStrings = (string[]) reader.ReadOptimizedObjectArray(typeof(string));
An exception will be thrown if any of the deserialized values cannot be cast to the specified elementType.
Declaration
public object[] ReadOptimizedObjectArray(Type elementType)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | elementType | The Type of the expected array elements. null will return a plain object[]. |
Returns
| Type | Description |
|---|---|
| object[] | An object[] instance. |
ReadOptimizedObjectArrayPair(out object[], out object[])
Returns a pair of object[] arrays from the stream that were stored optimized.
Declaration
public void ReadOptimizedObjectArrayPair(out object[] values1, out object[] values2)
Parameters
| Type | Name | Description |
|---|---|---|
| object[] | values1 | |
| object[] | values2 |
ReadOptimizedString()
Returns a string value from the stream that was stored optimized.
Declaration
public string ReadOptimizedString()
Returns
| Type | Description |
|---|---|
| string | A string value. |
ReadOptimizedStringArray()
Returns a string[] from the stream that was stored optimized.
Declaration
public string[] ReadOptimizedStringArray()
Returns
| Type | Description |
|---|---|
| string[] | An string[] instance. |
ReadOptimizedTimeSpan()
Returns a TimeSpan value from the stream that was stored optimized.
Declaration
public TimeSpan ReadOptimizedTimeSpan()
Returns
| Type | Description |
|---|---|
| TimeSpan | A TimeSpan value. |
ReadOptimizedTimeSpanArray()
Returns a TimeSpan[] from the stream.
Declaration
public TimeSpan[] ReadOptimizedTimeSpanArray()
Returns
| Type | Description |
|---|---|
| TimeSpan[] | A TimeSpan[] instance; or null. |
ReadOptimizedType()
Returns a Type from the stream.
Throws an exception if the Type cannot be found.
Declaration
public Type ReadOptimizedType()
Returns
| Type | Description |
|---|---|
| Type | A Type instance. |
ReadOptimizedType(bool)
Returns a Type from the stream.
Throws an exception if the Type cannot be found and throwOnError is true.
Declaration
public Type ReadOptimizedType(bool throwOnError)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | throwOnError |
Returns
| Type | Description |
|---|---|
| Type | A Type instance. |
ReadOptimizedUInt16()
Returns a UInt16 value from the stream that was stored optimized.
Declaration
public ushort ReadOptimizedUInt16()
Returns
| Type | Description |
|---|---|
| ushort | A UInt16 value. |
ReadOptimizedUInt16Array()
Returns a UInt16[] from the stream.
Declaration
public ushort[] ReadOptimizedUInt16Array()
Returns
| Type | Description |
|---|---|
| ushort[] | A UInt16[] instance; or null. |
ReadOptimizedUInt32()
Returns a UInt32 value from the stream that was stored optimized.
Declaration
public uint ReadOptimizedUInt32()
Returns
| Type | Description |
|---|---|
| uint | A UInt32 value. |
ReadOptimizedUInt32Array()
Returns a UInt32[] from the stream.
Declaration
public uint[] ReadOptimizedUInt32Array()
Returns
| Type | Description |
|---|---|
| uint[] | A UInt32[] instance; or null. |
ReadOptimizedUInt64()
Returns a UInt64 value from the stream that was stored optimized.
Declaration
public ulong ReadOptimizedUInt64()
Returns
| Type | Description |
|---|---|
| ulong | A UInt64 value. |
ReadOptimizedUInt64Array()
Returns a UInt64[] from the stream.
Declaration
public ulong[] ReadOptimizedUInt64Array()
Returns
| Type | Description |
|---|---|
| ulong[] | A UInt64[] instance; or null. |
ReadOwnedData(IOwnedDataSerializable, object)
Allows an existing object, implementing IOwnedDataSerializable, to retrieve its owned data from the stream.
Declaration
public void ReadOwnedData(IOwnedDataSerializable target, object context)
Parameters
| Type | Name | Description |
|---|---|---|
| IOwnedDataSerializable | target | Any IOwnedDataSerializable object. |
| object | context | An optional, arbitrary object to allow context to be provided. |
ReadSByteArray()
Returns an SByte[] from the stream.
Declaration
public sbyte[] ReadSByteArray()
Returns
| Type | Description |
|---|---|
| sbyte[] | An SByte[] instance; or null. |
ReadSingleArray()
Returns a Single[] from the stream.
Declaration
public float[] ReadSingleArray()
Returns
| Type | Description |
|---|---|
| float[] | A Single[] instance; or null. |
ReadString()
Called ReadOptimizedString(). This override to hide base BinaryReader.ReadString().
Declaration
public override string ReadString()
Returns
| Type | Description |
|---|---|
| string | A string value. |
Overrides
ReadStringArray()
Returns a string[] or null from the stream.
Declaration
public string[] ReadStringArray()
Returns
| Type | Description |
|---|---|
| string[] | An string[] instance. |
ReadStringDirect()
Returns a string value from the stream.
Declaration
public string ReadStringDirect()
Returns
| Type | Description |
|---|---|
| string | A string value. |
ReadTimeSpan()
Returns a TimeSpan value from the stream.
Declaration
public TimeSpan ReadTimeSpan()
Returns
| Type | Description |
|---|---|
| TimeSpan | A TimeSpan value. |
ReadTimeSpanArray()
Returns a TimeSpan[] from the stream.
Declaration
public TimeSpan[] ReadTimeSpanArray()
Returns
| Type | Description |
|---|---|
| TimeSpan[] | A TimeSpan[] instance; or null. |
ReadTokenizedObject()
Returns the object associated with the object token read next from the stream.
Declaration
public object ReadTokenizedObject()
Returns
| Type | Description |
|---|---|
| object | An object. |
ReadType()
Returns a Type or null from the stream.
Throws an exception if the Type cannot be found.
Declaration
public Type ReadType()
Returns
| Type | Description |
|---|---|
| Type | A Type instance. |
ReadType(bool)
Returns a Type or null from the stream.
Throws an exception if the Type cannot be found and throwOnError is true.
Declaration
public Type ReadType(bool throwOnError)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | throwOnError |
Returns
| Type | Description |
|---|---|
| Type | A Type instance. |
ReadTypedArray()
Returns a typed array from the stream.
Declaration
public Array ReadTypedArray()
Returns
| Type | Description |
|---|---|
| Array | A typed array. |
ReadUInt16Array()
Returns a UInt16[] from the stream.
Declaration
public ushort[] ReadUInt16Array()
Returns
| Type | Description |
|---|---|
| ushort[] | A UInt16[] instance; or null. |
ReadUInt32Array()
Returns a UInt[] from the stream.
Declaration
public uint[] ReadUInt32Array()
Returns
| Type | Description |
|---|---|
| uint[] | A UInt[] instance; or null. |
ReadUInt64Array()
Returns a UInt64[] from the stream.
Declaration
public ulong[] ReadUInt64Array()
Returns
| Type | Description |
|---|---|
| ulong[] | A UInt64[] instance; or null. |