Version 3.3.1.2

JsonDataReader class

Namespace: Sirenix.Serialization
Assembly: Sirenix.Serialization
public class JsonDataReader : BaseDataReader, IDataReader, IDisposable
Reads json data from a stream that has been written by a JsonDataWriter.
Inheritance
See Also

Constructors

JsonDataReader()
public JsonDataReader()
JsonDataReader(Stream, DeserializationContext)
Initializes a new instance of the JsonDataReader class.
public JsonDataReader(Stream stream, DeserializationContext context)
Parameters
System.IO.Stream stream

The base stream of the reader.

DeserializationContext context

The deserialization context to use.

Properties

Stream
Gets or sets the base stream of the reader.
public override Stream Stream { get; set; }

Methods

Dispose()
Disposes all resources kept by the data reader, except the stream, which can be reused later.
public override void Dispose()
EnterArray(out Int64)
Tries to enters an array node. This will succeed if the next entry is an StartOfArray.

This call MUST (eventually) be followed by a corresponding call to

This call will change the values of the Sirenix.Serialization.IDataReader.IsInArrayNode, Sirenix.Serialization.IDataReader.CurrentNodeName, Sirenix.Serialization.IDataReader.CurrentNodeId and Sirenix.Serialization.IDataReader.CurrentNodeDepth properties to the correct values for the current array node.

public override bool EnterArray(out long length)
Parameters
System.Int64 length

The length of the array that was entered.

Returns
System.Boolean

true if an array was entered, otherwise false

EnterNode(out Type)
Tries to enter a node. This will succeed if the next entry is an StartOfNode.

This call MUST (eventually) be followed by a corresponding call to

This call will change the values of the Sirenix.Serialization.IDataReader.IsInArrayNode, Sirenix.Serialization.IDataReader.CurrentNodeName, Sirenix.Serialization.IDataReader.CurrentNodeId and Sirenix.Serialization.IDataReader.CurrentNodeDepth properties to the correct values for the current node.

public override bool EnterNode(out Type type)
Parameters
System.Type type

The type of the node. This value will be null if there was no metadata, or if the reader's serialization binder failed to resolve the type name.

Returns
System.Boolean

true if entering a node succeeded, otherwise false

ExitArray()
Exits the closest array. This method will keep skipping entries using until an EndOfArray is reached, or the end of the stream is reached.

This call MUST have been preceded by a corresponding call to Sirenix.Serialization.IDataReader.EnterArray(System.Int64@).

This call will change the values of the Sirenix.Serialization.IDataReader.IsInArrayNode, Sirenix.Serialization.IDataReader.CurrentNodeName, Sirenix.Serialization.IDataReader.CurrentNodeId and Sirenix.Serialization.IDataReader.CurrentNodeDepth to the correct values for the node that was prior to the exited array node.

public override bool ExitArray()
Returns
System.Boolean

true if the method exited an array, false if it reached the end of the stream.

ExitNode()
Exits the current node. This method will keep skipping entries using until an EndOfNode is reached, or the end of the stream is reached.

This call MUST have been preceded by a corresponding call to Sirenix.Serialization.IDataReader.EnterNode(System.Type@).

This call will change the values of the Sirenix.Serialization.IDataReader.IsInArrayNode, Sirenix.Serialization.IDataReader.CurrentNodeName, Sirenix.Serialization.IDataReader.CurrentNodeId and Sirenix.Serialization.IDataReader.CurrentNodeDepth to the correct values for the node that was prior to the current node.

public override bool ExitNode()
Returns
System.Boolean

true if the method exited a node, false if it reached the end of the stream.

GetDataDump()
public override string GetDataDump()
Returns
System.String

PeekEntry()
Peeks the current entry.
protected override EntryType PeekEntry()
Returns
EntryType

The peeked entry.

PeekEntry(out String)
Peeks ahead and returns the type of the next entry in the stream.
public override EntryType PeekEntry(out string name)
Parameters
System.String name

The name of the next entry, if it has one.

Returns
EntryType

The type of the next entry.

PrepareNewSerializationSession()
Tells the reader 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 reader is used to deserialize several different, unrelated values.
public override void PrepareNewSerializationSession()
ReadBoolean(out Boolean)
Reads a System.Boolean value. This call will succeed if the next entry is an Boolean.

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public override bool ReadBoolean(out bool value)
Parameters
System.Boolean value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadByte(out Byte)
Reads a System.Byte value. This call will succeed if the next entry is an Integer.

If the value of the stored integer is smaller than System.Byte.MinValue or larger than System.Byte.MaxValue, the result will be default(System.Byte).

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public override bool ReadByte(out byte value)
Parameters
System.Byte value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadChar(out Char)
Reads a System.Char value. This call will succeed if the next entry is an String.

If the string of the entry is longer than 1 character, the first character of the string will be taken as the result.

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public override bool ReadChar(out char value)
Parameters
System.Char value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadDecimal(out Decimal)
Reads a System.Decimal value. This call will succeed if the next entry is an FloatingPoint or an Integer.

If the stored integer or floating point value is smaller than System.Decimal.MinValue or larger than System.Decimal.MaxValue, the result will be default(System.Decimal).

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public override bool ReadDecimal(out decimal value)
Parameters
System.Decimal value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadDouble(out Double)
Reads a System.Double value. This call will succeed if the next entry is an FloatingPoint or an Integer.

If the stored integer or floating point value is smaller than System.Double.MinValue or larger than System.Double.MaxValue, the result will be default(System.Double).

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public override bool ReadDouble(out double value)
Parameters
System.Double value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadExternalReference(out Guid)
Reads an external reference guid. This call will succeed if the next entry is an ExternalReferenceByGuid.

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public override bool ReadExternalReference(out Guid guid)
Parameters
System.Guid guid

The external reference guid.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadExternalReference(out Int32)
Reads an external reference index. This call will succeed if the next entry is an ExternalReferenceByIndex.

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public override bool ReadExternalReference(out int index)
Parameters
System.Int32 index

The external reference index.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadExternalReference(out String)
Reads an external reference string. This call will succeed if the next entry is an ExternalReferenceByString.

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public override bool ReadExternalReference(out string id)
Parameters
System.String id

The external reference string.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadGuid(out Guid)
Reads a System.Guid value. This call will succeed if the next entry is an Guid.

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public override bool ReadGuid(out Guid value)
Parameters
System.Guid value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadInt16(out Int16)
Reads a System.Int16 value. This call will succeed if the next entry is an Integer.

If the value of the stored integer is smaller than System.Int16.MinValue or larger than System.Int16.MaxValue, the result will be default(System.Int16).

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public override bool ReadInt16(out short value)
Parameters
System.Int16 value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadInt32(out Int32)
Reads an System.Int32 value. This call will succeed if the next entry is an Integer.

If the value of the stored integer is smaller than System.Int32.MinValue or larger than System.Int32.MaxValue, the result will be default(System.Int32).

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public override bool ReadInt32(out int value)
Parameters
System.Int32 value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadInt64(out Int64)
Reads a System.Int64 value. This call will succeed if the next entry is an Integer.

If the value of the stored integer is smaller than System.Int64.MinValue or larger than System.Int64.MaxValue, the result will be default(System.Int64).

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public override bool ReadInt64(out long value)
Parameters
System.Int64 value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadInternalReference(out Int32)
Reads an internal reference id. This call will succeed if the next entry is an InternalReference.

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public override bool ReadInternalReference(out int id)
Parameters
System.Int32 id

The internal reference id.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadNull()
Reads a null value. This call will succeed if the next entry is an Null.

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public override bool ReadNull()
Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadPrimitiveArray<T>(out T[])
Reads a primitive array value. This call will succeed if the next entry is an PrimitiveArray.

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public override bool ReadPrimitiveArray<T>(out T[] array)
    where T : struct
Parameters
T[] array

The resulting primitive array.

Returns
System.Boolean

true if reading a primitive array succeeded, otherwise false

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.

ReadSByte(out SByte)
Reads an System.SByte value. This call will succeed if the next entry is an Integer.

If the value of the stored integer is smaller than System.SByte.MinValue or larger than System.SByte.MaxValue, the result will be default(System.SByte).

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public override bool ReadSByte(out sbyte value)
Parameters
System.SByte value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadSingle(out Single)
Reads a System.Single value. This call will succeed if the next entry is an FloatingPoint or an Integer.

If the stored integer or floating point value is smaller than System.Single.MinValue or larger than System.Single.MaxValue, the result will be default(System.Single).

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public override bool ReadSingle(out float value)
Parameters
System.Single value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadString(out String)
Reads a System.String value. This call will succeed if the next entry is an String.

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public override bool ReadString(out string value)
Parameters
System.String value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadToNextEntry()
Consumes the current entry, and reads to the next one.
protected override EntryType ReadToNextEntry()
Returns
EntryType

The next entry.

ReadUInt16(out UInt16)
Reads an System.UInt16 value. This call will succeed if the next entry is an Integer.

If the value of the stored integer is smaller than System.UInt16.MinValue or larger than System.UInt16.MaxValue, the result will be default(System.UInt16).

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public override bool ReadUInt16(out ushort value)
Parameters
System.UInt16 value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadUInt32(out UInt32)
Reads an System.UInt32 value. This call will succeed if the next entry is an Integer.

If the value of the stored integer is smaller than System.UInt32.MinValue or larger than System.UInt32.MaxValue, the result will be default(System.UInt32).

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public override bool ReadUInt32(out uint value)
Parameters
System.UInt32 value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false

ReadUInt64(out UInt64)
Reads an System.UInt64 value. This call will succeed if the next entry is an Integer.

If the value of the stored integer is smaller than System.UInt64.MinValue or larger than System.UInt64.MaxValue, the result will be default(System.UInt64).

If the call fails (and returns false), it will skip the current entry value, unless that entry is an EndOfNode or an EndOfArray.

public override bool ReadUInt64(out ulong value)
Parameters
System.UInt64 value

The value that has been read.

Returns
System.Boolean

true if reading the value succeeded, otherwise false