Table of Contents

Class BsonWriter

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

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

public abstract class BsonWriter : IBsonWriter, IDisposable
Inheritance
BsonWriter
Implements
Derived
Inherited Members
Extension Methods

Constructors

BsonWriter(BsonWriterSettings)

Initializes a new instance of the BsonWriter class.

protected BsonWriter(BsonWriterSettings settings)

Parameters

settings BsonWriterSettings

The writer settings.

Properties

Disposed

Gets whether the BsonWriter has been disposed.

public bool Disposed { get; }

Property Value

bool

Name

Gets the name of the element being written.

protected string Name { get; }

Property Value

string

Position

Gets the position. Not all writers are able to report the position. Those that can't simply return zero.

public abstract long Position { get; }

Property Value

long

The position.

SerializationDepth

Gets the current serialization depth.

public int SerializationDepth { get; }

Property Value

int

Settings

Gets the settings of the writer.

public BsonWriterSettings Settings { get; }

Property Value

BsonWriterSettings

State

Gets the current state of the writer.

public BsonWriterState State { get; protected set; }

Property Value

BsonWriterState

Methods

Close()

Closes the writer.

public abstract void Close()

Dispose()

Disposes of any resources used by the writer.

public void Dispose()

Dispose(bool)

Disposes of any resources used by the writer.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

True if called from Dispose.

Flush()

Flushes any pending data to the output destination.

public abstract void Flush()

PopElementNameValidator()

Pops the element name validator.

public void PopElementNameValidator()

PopSettings()

Pops the settings.

public void PopSettings()

PushElementNameValidator(IElementNameValidator)

Pushes the element name validator.

public void PushElementNameValidator(IElementNameValidator validator)

Parameters

validator IElementNameValidator

The validator.

PushSettings(Action<BsonWriterSettings>)

Pushes new settings for the writer.

public void PushSettings(Action<BsonWriterSettings> configurator)

Parameters

configurator Action<BsonWriterSettings>

The settings configurator.

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 BsonWriterState[])

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

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

Parameters

methodName string

The name of the method.

validStates BsonWriterState[]

The valid states.

WriteBinaryData(BsonBinaryData)

Writes BSON binary data to the writer.

public abstract void WriteBinaryData(BsonBinaryData binaryData)

Parameters

binaryData BsonBinaryData

The binary data.

WriteBoolean(bool)

Writes a BSON Boolean to the writer.

public abstract void WriteBoolean(bool value)

Parameters

value bool

The Boolean value.

WriteBytes(byte[])

Writes BSON binary data to the writer.

public abstract void WriteBytes(byte[] bytes)

Parameters

bytes byte[]

The bytes.

WriteDateTime(long)

Writes a BSON DateTime to the writer.

public abstract void WriteDateTime(long value)

Parameters

value long

The number of milliseconds since the Unix epoch.

WriteDecimal128(Decimal128)

Writes a BSON Decimal128 to the writer.

public abstract void WriteDecimal128(Decimal128 value)

Parameters

value Decimal128

The Decimal128 value.

WriteDouble(double)

Writes a BSON Double to the writer.

public abstract void WriteDouble(double value)

Parameters

value double

The Double value.

WriteEndArray()

Writes the end of a BSON array to the writer.

public virtual void WriteEndArray()

WriteEndDocument()

Writes the end of a BSON document to the writer.

public virtual void WriteEndDocument()

WriteInt32(int)

Writes a BSON Int32 to the writer.

public abstract void WriteInt32(int value)

Parameters

value int

The Int32 value.

WriteInt64(long)

Writes a BSON Int64 to the writer.

public abstract void WriteInt64(long value)

Parameters

value long

The Int64 value.

WriteJavaScript(string)

Writes a BSON JavaScript to the writer.

public abstract void WriteJavaScript(string code)

Parameters

code string

The JavaScript code.

WriteJavaScriptWithScope(string)

Writes a BSON JavaScript to the writer (call WriteStartDocument to start writing the scope).

public abstract void WriteJavaScriptWithScope(string code)

Parameters

code string

The JavaScript code.

WriteMaxKey()

Writes a BSON MaxKey to the writer.

public abstract void WriteMaxKey()

WriteMinKey()

Writes a BSON MinKey to the writer.

public abstract void WriteMinKey()

WriteName(string)

Writes the name of an element to the writer.

public virtual void WriteName(string name)

Parameters

name string

The name of the element.

WriteNull()

Writes a BSON null to the writer.

public abstract void WriteNull()

WriteObjectId(ObjectId)

Writes a BSON ObjectId to the writer.

public abstract void WriteObjectId(ObjectId objectId)

Parameters

objectId ObjectId

The ObjectId.

WriteRawBsonArray(IByteBuffer)

Writes a raw BSON array.

public virtual void WriteRawBsonArray(IByteBuffer slice)

Parameters

slice IByteBuffer

The byte buffer containing the raw BSON array.

WriteRawBsonDocument(IByteBuffer)

Writes a raw BSON document.

public virtual void WriteRawBsonDocument(IByteBuffer slice)

Parameters

slice IByteBuffer

The byte buffer containing the raw BSON document.

WriteRegularExpression(BsonRegularExpression)

Writes a BSON regular expression to the writer.

public abstract void WriteRegularExpression(BsonRegularExpression regex)

Parameters

regex BsonRegularExpression

A BsonRegularExpression.

WriteStartArray()

Writes the start of a BSON array to the writer.

public virtual void WriteStartArray()

WriteStartDocument()

Writes the start of a BSON document to the writer.

public virtual void WriteStartDocument()

WriteString(string)

Writes a BSON String to the writer.

public abstract void WriteString(string value)

Parameters

value string

The String value.

WriteSymbol(string)

Writes a BSON Symbol to the writer.

public abstract void WriteSymbol(string value)

Parameters

value string

The symbol.

WriteTimestamp(long)

Writes a BSON timestamp to the writer.

public abstract void WriteTimestamp(long value)

Parameters

value long

The combined timestamp/increment value.

WriteUndefined()

Writes a BSON undefined to the writer.

public abstract void WriteUndefined()