Table of Contents

Class MaterializedOnDemandBsonDocument

Namespace
MongoDB.Bson
Assembly
MongoDB.Bson.dll

Represents a BSON document that is not materialized until you start using it.

[BsonSerializer(typeof(MaterializedOnDemandBsonDocumentSerializer))]
public abstract class MaterializedOnDemandBsonDocument : BsonDocument, IComparable<BsonValue>, IConvertible, IEquatable<BsonValue>, IComparable<BsonDocument>, IConvertibleToBsonDocument, IEnumerable<BsonElement>, IEnumerable, IEquatable<BsonDocument>, IDisposable
Inheritance
MaterializedOnDemandBsonDocument
Implements
Derived
Inherited Members
Extension Methods

Constructors

MaterializedOnDemandBsonDocument()

Initializes a new instance of the MaterializedOnDemandBsonDocument class.

protected MaterializedOnDemandBsonDocument()

Properties

ElementCount

Gets the number of elements.

public override int ElementCount { get; }

Property Value

int

Elements

Gets the elements.

public override IEnumerable<BsonElement> Elements { get; }

Property Value

IEnumerable<BsonElement>

IsDisposed

Gets a value indicating whether this instance is disposed.

public bool IsDisposed { get; }

Property Value

bool

true if this instance is disposed; otherwise, false.

IsMaterialized

Gets a value indicating whether this instance is materialized.

public bool IsMaterialized { get; }

Property Value

bool

true if this instance is materialized; otherwise, false.

this[int]

Gets or sets a value by position.

public override BsonValue this[int index] { get; set; }

Parameters

index int

The position.

Property Value

BsonValue

The value.

this[string]

Gets or sets a value by name.

public override BsonValue this[string name] { get; set; }

Parameters

name string

The name.

Property Value

BsonValue

The value.

this[string, BsonValue]

Gets the value of an element or a default value if the element is not found.

[Obsolete("Use GetValue(string name, BsonValue defaultValue) instead.")]
public override BsonValue this[string name, BsonValue defaultValue] { get; }

Parameters

name string

The name of the element.

defaultValue BsonValue

The default value to return if the element is not found.

Property Value

BsonValue

Teh value of the element or a default value if the element is not found.

Names

Gets the element names.

public override IEnumerable<string> Names { get; }

Property Value

IEnumerable<string>

RawValues

Gets the raw values (see BsonValue.RawValue).

[Obsolete("Use Values instead.")]
public override IEnumerable<object> RawValues { get; }

Property Value

IEnumerable<object>

Values

Gets the values.

public override IEnumerable<BsonValue> Values { get; }

Property Value

IEnumerable<BsonValue>

Methods

Add(BsonElement)

Adds an element to the document.

public override BsonDocument Add(BsonElement element)

Parameters

element BsonElement

The element to add.

Returns

BsonDocument

The document (so method calls can be chained).

Add(params BsonElement[])

Adds a list of elements to the document.

[Obsolete("Use AddRange(IEnumerable<BsonElement> elements) instead.")]
public override BsonDocument Add(params BsonElement[] elements)

Parameters

elements BsonElement[]

The list of elements.

Returns

BsonDocument

The document (so method calls can be chained).

Add(Dictionary<string, object>)

Adds elements to the document from a dictionary of key/value pairs.

[Obsolete("Use AddRange instead.")]
public override BsonDocument Add(Dictionary<string, object> dictionary)

Parameters

dictionary Dictionary<string, object>

The dictionary.

Returns

BsonDocument

The document (so method calls can be chained).

Add(Dictionary<string, object>, IEnumerable<string>)

Adds elements to the document from a dictionary of key/value pairs.

[Obsolete("Use AddRange(IEnumerable<BsonElement> elements) instead.")]
public override BsonDocument Add(Dictionary<string, object> dictionary, IEnumerable<string> keys)

Parameters

dictionary Dictionary<string, object>

The dictionary.

keys IEnumerable<string>

Which keys of the hash table to add.

Returns

BsonDocument

The document (so method calls can be chained).

Add(IDictionary<string, object>)

Adds elements to the document from a dictionary of key/value pairs.

[Obsolete("Use AddRange instead.")]
public override BsonDocument Add(IDictionary<string, object> dictionary)

Parameters

dictionary IDictionary<string, object>

The dictionary.

Returns

BsonDocument

The document (so method calls can be chained).

Add(IDictionary<string, object>, IEnumerable<string>)

Adds elements to the document from a dictionary of key/value pairs.

[Obsolete("Use AddRange(IEnumerable<BsonElement> elements) instead.")]
public override BsonDocument Add(IDictionary<string, object> dictionary, IEnumerable<string> keys)

Parameters

dictionary IDictionary<string, object>

The dictionary.

keys IEnumerable<string>

Which keys of the hash table to add.

Returns

BsonDocument

The document (so method calls can be chained).

Add(IEnumerable<BsonElement>)

Adds a list of elements to the document.

[Obsolete("Use AddRange instead.")]
public override BsonDocument Add(IEnumerable<BsonElement> elements)

Parameters

elements IEnumerable<BsonElement>

The list of elements.

Returns

BsonDocument

The document (so method calls can be chained).

Add(IDictionary)

Adds elements to the document from a dictionary of key/value pairs.

[Obsolete("Use AddRange instead.")]
public override BsonDocument Add(IDictionary dictionary)

Parameters

dictionary IDictionary

The dictionary.

Returns

BsonDocument

The document (so method calls can be chained).

Add(IDictionary, IEnumerable)

Adds elements to the document from a dictionary of key/value pairs.

[Obsolete("Use AddRange(IEnumerable<BsonElement> elements) instead.")]
public override BsonDocument Add(IDictionary dictionary, IEnumerable keys)

Parameters

dictionary IDictionary

The dictionary.

keys IEnumerable

Which keys of the hash table to add.

Returns

BsonDocument

The document (so method calls can be chained).

Add(string, BsonValue)

Creates and adds an element to the document.

public override BsonDocument Add(string name, BsonValue value)

Parameters

name string

The name of the element.

value BsonValue

The value of the element.

Returns

BsonDocument

The document (so method calls can be chained).

Add(string, BsonValue, bool)

Creates and adds an element to the document, but only if the condition is true.

public override BsonDocument Add(string name, BsonValue value, bool condition)

Parameters

name string

The name of the element.

value BsonValue

The value of the element.

condition bool

Whether to add the element to the document.

Returns

BsonDocument

The document (so method calls can be chained).

Add(string, Func<BsonValue>, bool)

Creates and adds an element to the document, but only if the condition is true. If the condition is false the value factory is not called at all.

public override BsonDocument Add(string name, Func<BsonValue> valueFactory, bool condition)

Parameters

name string

The name of the element.

valueFactory Func<BsonValue>

A delegate called to compute the value of the element if condition is true.

condition bool

Whether to add the element to the document.

Returns

BsonDocument

The document (so method calls can be chained).

AddRange(Dictionary<string, object>)

Adds elements to the document from a dictionary of key/value pairs.

public override BsonDocument AddRange(Dictionary<string, object> dictionary)

Parameters

dictionary Dictionary<string, object>

The dictionary.

Returns

BsonDocument

The document (so method calls can be chained).

AddRange(IEnumerable<BsonElement>)

Adds a list of elements to the document.

public override BsonDocument AddRange(IEnumerable<BsonElement> elements)

Parameters

elements IEnumerable<BsonElement>

The list of elements.

Returns

BsonDocument

The document (so method calls can be chained).

AddRange(IEnumerable<KeyValuePair<string, object>>)

Adds elements to the document from a dictionary of key/value pairs.

public override BsonDocument AddRange(IEnumerable<KeyValuePair<string, object>> dictionary)

Parameters

dictionary IEnumerable<KeyValuePair<string, object>>

The dictionary.

Returns

BsonDocument

The document (so method calls can be chained).

AddRange(IDictionary)

Adds elements to the document from a dictionary of key/value pairs.

public override BsonDocument AddRange(IDictionary dictionary)

Parameters

dictionary IDictionary

The dictionary.

Returns

BsonDocument

The document (so method calls can be chained).

Clear()

Clears the document (removes all elements).

public override void Clear()

Clone()

Creates a shallow clone of the document (see also DeepClone).

public override BsonValue Clone()

Returns

BsonValue

A shallow clone of the document.

CompareTo(BsonDocument)

Compares this document to another document.

public override int CompareTo(BsonDocument other)

Parameters

other BsonDocument

The other document.

Returns

int

A 32-bit signed integer that indicates whether this document is less than, equal to, or greather than the other.

CompareTo(BsonValue)

Compares the BsonDocument to another BsonValue.

public override int CompareTo(BsonValue other)

Parameters

other BsonValue

The other BsonValue.

Returns

int

A 32-bit signed integer that indicates whether this BsonDocument is less than, equal to, or greather than the other BsonValue.

Contains(string)

Tests whether the document contains an element with the specified name.

public override bool Contains(string name)

Parameters

name string

The name of the element to look for.

Returns

bool

True if the document contains an element with the specified name.

ContainsValue(BsonValue)

Tests whether the document contains an element with the specified value.

public override bool ContainsValue(BsonValue value)

Parameters

value BsonValue

The value of the element to look for.

Returns

bool

True if the document contains an element with the specified value.

DeepClone()

Creates a deep clone of the document (see also Clone).

public override BsonValue DeepClone()

Returns

BsonValue

A deep clone of the document.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Dispose(bool)

Releases unmanaged and - optionally - managed resources.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

Equals(object)

Determines whether the specified object, is equal to this instance.

public override bool Equals(object obj)

Parameters

obj object

The object to compare with this instance.

Returns

bool

true if the specified object is equal to this instance; otherwise, false.

GetElement(int)

Gets an element of this document.

public override BsonElement GetElement(int index)

Parameters

index int

The zero based index of the element.

Returns

BsonElement

The element.

GetElement(string)

Gets an element of this document.

public override BsonElement GetElement(string name)

Parameters

name string

The name of the element.

Returns

BsonElement

A BsonElement.

GetEnumerator()

Gets an enumerator that can be used to enumerate the elements of this document.

public override IEnumerator<BsonElement> GetEnumerator()

Returns

IEnumerator<BsonElement>

An enumerator.

GetHashCode()

Returns a hash code for this instance.

public override int GetHashCode()

Returns

int

A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.

GetValue(int)

Gets the value of an element.

public override BsonValue GetValue(int index)

Parameters

index int

The zero based index of the element.

Returns

BsonValue

The value of the element.

GetValue(string)

Gets the value of an element.

public override BsonValue GetValue(string name)

Parameters

name string

The name of the element.

Returns

BsonValue

The value of the element.

GetValue(string, BsonValue)

Gets the value of an element or a default value if the element is not found.

public override BsonValue GetValue(string name, BsonValue defaultValue)

Parameters

name string

The name of the element.

defaultValue BsonValue

The default value returned if the element is not found.

Returns

BsonValue

The value of the element or the default value if the element is not found.

InsertAt(int, BsonElement)

Inserts a new element at a specified position.

public override void InsertAt(int index, BsonElement element)

Parameters

index int

The position of the new element.

element BsonElement

The element.

Materialize()

Materializes the BsonDocument.

protected abstract IEnumerable<BsonElement> Materialize()

Returns

IEnumerable<BsonElement>

The materialized elements.

MaterializeCompleted()

Informs subclasses that the Materialize process completed so they can free any resources related to the unmaterialized state.

protected abstract void MaterializeCompleted()

Merge(BsonDocument)

Merges another document into this one. Existing elements are not overwritten.

public override BsonDocument Merge(BsonDocument document)

Parameters

document BsonDocument

The other document.

Returns

BsonDocument

The document (so method calls can be chained).

Merge(BsonDocument, bool)

Merges another document into this one, specifying whether existing elements are overwritten.

public override BsonDocument Merge(BsonDocument document, bool overwriteExistingElements)

Parameters

document BsonDocument

The other document.

overwriteExistingElements bool

Whether to overwrite existing elements.

Returns

BsonDocument

The document (so method calls can be chained).

Remove(string)

Removes an element from this document (if duplicate element names are allowed then all elements with this name will be removed).

public override void Remove(string name)

Parameters

name string

The name of the element to remove.

RemoveAt(int)

Removes an element from this document.

public override void RemoveAt(int index)

Parameters

index int

The zero based index of the element to remove.

RemoveElement(BsonElement)

Removes an element from this document.

public override void RemoveElement(BsonElement element)

Parameters

element BsonElement

The element to remove.

Set(int, BsonValue)

Sets the value of an element.

public override BsonDocument Set(int index, BsonValue value)

Parameters

index int

The zero based index of the element whose value is to be set.

value BsonValue

The new value.

Returns

BsonDocument

The document (so method calls can be chained).

Set(string, BsonValue)

Sets the value of an element (an element will be added if no element with this name is found).

public override BsonDocument Set(string name, BsonValue value)

Parameters

name string

The name of the element whose value is to be set.

value BsonValue

The new value.

Returns

BsonDocument

The document (so method calls can be chained).

SetElement(BsonElement)

Sets an element of the document (replaces any existing element with the same name or adds a new element if an element with the same name is not found).

public override BsonDocument SetElement(BsonElement element)

Parameters

element BsonElement

The new element.

Returns

BsonDocument

The document.

SetElement(int, BsonElement)

Sets an element of the document (replacing the existing element at that position).

public override BsonDocument SetElement(int index, BsonElement element)

Parameters

index int

The zero based index of the element to replace.

element BsonElement

The new element.

Returns

BsonDocument

The document.

ThrowIfDisposed()

Throws if disposed.

protected void ThrowIfDisposed()

Exceptions

ObjectDisposedException

TryGetElement(string, out BsonElement)

Tries to get an element of this document.

public override bool TryGetElement(string name, out BsonElement value)

Parameters

name string

The name of the element.

value BsonElement

The element.

Returns

bool

True if an element with that name was found.

TryGetValue(string, out BsonValue)

Tries to get the value of an element of this document.

public override bool TryGetValue(string name, out BsonValue value)

Parameters

name string

The name of the element.

value BsonValue

The value of the element.

Returns

bool

True if an element with that name was found.