Table of Contents

Class BsonReader

Namespace
MongoDB.Bson.IO
Assembly
MongoDB.Bson.dll

Represents a BSON reader for some external format (see subclasses).

public abstract class BsonReader : IBsonReader, IDisposable
Inheritance
BsonReader
Implements
Derived
Inherited Members
Extension Methods

Constructors

BsonReader(BsonReaderSettings)

Initializes a new instance of the BsonReader class.

protected BsonReader(BsonReaderSettings settings)

Parameters

settings BsonReaderSettings

The reader settings.

Properties

CurrentBsonType

Gets the current BsonType.

public BsonType CurrentBsonType { get; protected set; }

Property Value

BsonType

CurrentName

Gets the current name.

protected string CurrentName { get; set; }

Property Value

string

Disposed

Gets whether the BsonReader has been disposed.

protected bool Disposed { get; }

Property Value

bool

Settings

Gets the settings of the reader.

public BsonReaderSettings Settings { get; }

Property Value

BsonReaderSettings

State

Gets the current state of the reader.

public BsonReaderState State { get; protected set; }

Property Value

BsonReaderState

Methods

Close()

Closes the reader.

public abstract void Close()

Dispose()

Disposes of any resources used by the reader.

public void Dispose()

Dispose(bool)

Disposes of any resources used by the reader.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

True if called from Dispose.

GetBookmark()

Gets a bookmark to the reader's current position and state.

public abstract BsonReaderBookmark GetBookmark()

Returns

BsonReaderBookmark

A bookmark.

GetCurrentBsonType()

Gets the current BsonType (calls ReadBsonType if necessary).

public BsonType GetCurrentBsonType()

Returns

BsonType

The current BsonType.

IsAtEndOfFile()

Determines whether this reader is at end of file.

public abstract bool IsAtEndOfFile()

Returns

bool

Whether this reader is at end of file.

PopSettings()

Pops the settings.

public void PopSettings()

PushSettings(Action<BsonReaderSettings>)

Pushes new settings for the reader.

public void PushSettings(Action<BsonReaderSettings> configurator)

Parameters

configurator Action<BsonReaderSettings>

The settings configurator.

ReadBinaryData()

Reads BSON binary data from the reader.

public abstract BsonBinaryData ReadBinaryData()

Returns

BsonBinaryData

A BsonBinaryData.

ReadBoolean()

Reads a BSON boolean from the reader.

public abstract bool ReadBoolean()

Returns

bool

A Boolean.

ReadBsonType()

Reads a BsonType from the reader.

public abstract BsonType ReadBsonType()

Returns

BsonType

A BsonType.

ReadBytes()

Reads BSON binary data from the reader.

public abstract byte[] ReadBytes()

Returns

byte[]

A byte array.

ReadDateTime()

Reads a BSON DateTime from the reader.

public abstract long ReadDateTime()

Returns

long

The number of milliseconds since the Unix epoch.

ReadDecimal128()

Reads a BSON Decimal128 from the reader.

public abstract Decimal128 ReadDecimal128()

Returns

Decimal128

A Decimal128.

ReadDouble()

Reads a BSON Double from the reader.

public abstract double ReadDouble()

Returns

double

A Double.

ReadEndArray()

Reads the end of a BSON array from the reader.

public abstract void ReadEndArray()

ReadEndDocument()

Reads the end of a BSON document from the reader.

public abstract void ReadEndDocument()

ReadInt32()

Reads a BSON Int32 from the reader.

public abstract int ReadInt32()

Returns

int

An Int32.

ReadInt64()

Reads a BSON Int64 from the reader.

public abstract long ReadInt64()

Returns

long

An Int64.

ReadJavaScript()

Reads a BSON JavaScript from the reader.

public abstract string ReadJavaScript()

Returns

string

A string.

ReadJavaScriptWithScope()

Reads a BSON JavaScript with scope from the reader (call ReadStartDocument next to read the scope).

public abstract string ReadJavaScriptWithScope()

Returns

string

A string.

ReadMaxKey()

Reads a BSON MaxKey from the reader.

public abstract void ReadMaxKey()

ReadMinKey()

Reads a BSON MinKey from the reader.

public abstract void ReadMinKey()

ReadName()

Reads the name of an element from the reader.

public virtual string ReadName()

Returns

string

The name of the element.

ReadName(INameDecoder)

Reads the name of an element from the reader (using the provided name decoder).

public abstract string ReadName(INameDecoder nameDecoder)

Parameters

nameDecoder INameDecoder

The name decoder.

Returns

string

The name of the element.

ReadNull()

Reads a BSON null from the reader.

public abstract void ReadNull()

ReadObjectId()

Reads a BSON ObjectId from the reader.

public abstract ObjectId ReadObjectId()

Returns

ObjectId

An ObjectId.

ReadRawBsonArray()

Reads a raw BSON array.

public virtual IByteBuffer ReadRawBsonArray()

Returns

IByteBuffer

The raw BSON array.

ReadRawBsonDocument()

Reads a raw BSON document.

public virtual IByteBuffer ReadRawBsonDocument()

Returns

IByteBuffer

The raw BSON document.

ReadRegularExpression()

Reads a BSON regular expression from the reader.

public abstract BsonRegularExpression ReadRegularExpression()

Returns

BsonRegularExpression

A BsonRegularExpression.

ReadStartArray()

Reads the start of a BSON array.

public abstract void ReadStartArray()

ReadStartDocument()

Reads the start of a BSON document.

public abstract void ReadStartDocument()

ReadString()

Reads a BSON string from the reader.

public abstract string ReadString()

Returns

string

A String.

ReadSymbol()

Reads a BSON symbol from the reader.

public abstract string ReadSymbol()

Returns

string

A string.

ReadTimestamp()

Reads a BSON timestamp from the reader.

public abstract long ReadTimestamp()

Returns

long

The combined timestamp/increment.

ReadUndefined()

Reads a BSON undefined from the reader.

public abstract void ReadUndefined()

ReturnToBookmark(BsonReaderBookmark)

Returns the reader to previously bookmarked position and state.

public abstract void ReturnToBookmark(BsonReaderBookmark bookmark)

Parameters

bookmark BsonReaderBookmark

The bookmark.

SkipName()

Skips the name (reader must be positioned on a name).

public abstract void SkipName()

SkipValue()

Skips the value (reader must be positioned on a value).

public abstract void SkipValue()

ThrowInvalidContextType(string, ContextType, params ContextType[])

Throws an InvalidOperationException when the method called is not valid for the current ContextType.

protected void ThrowInvalidContextType(string methodName, ContextType actualContextType, params ContextType[] validContextTypes)

Parameters

methodName string

The name of the method.

actualContextType ContextType

The actual ContextType.

validContextTypes ContextType[]

The valid ContextTypes.

ThrowInvalidState(string, params BsonReaderState[])

Throws an InvalidOperationException when the method called is not valid for the current state.

protected void ThrowInvalidState(string methodName, params BsonReaderState[] validStates)

Parameters

methodName string

The name of the method.

validStates BsonReaderState[]

The valid states.

ThrowObjectDisposedException()

Throws an ObjectDisposedException.

protected void ThrowObjectDisposedException()

VerifyBsonType(string, BsonType)

Verifies the current state and BsonType of the reader.

protected void VerifyBsonType(string methodName, BsonType requiredBsonType)

Parameters

methodName string

The name of the method calling this one.

requiredBsonType BsonType

The required BSON type.