Class MaterializedOnDemandBsonDocument
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
Elements
Gets the elements.
public override IEnumerable<BsonElement> Elements { get; }
Property Value
IsDisposed
Gets a value indicating whether this instance is disposed.
public bool IsDisposed { get; }
Property Value
- bool
trueif this instance is disposed; otherwise,false.
IsMaterialized
Gets a value indicating whether this instance is materialized.
public bool IsMaterialized { get; }
Property Value
- bool
trueif this instance is materialized; otherwise,false.
this[int]
Gets or sets a value by position.
public override BsonValue this[int index] { get; set; }
Parameters
indexintThe position.
Property Value
- BsonValue
The value.
this[string]
Gets or sets a value by name.
public override BsonValue this[string name] { get; set; }
Parameters
namestringThe 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
namestringThe name of the element.
defaultValueBsonValueThe 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
RawValues
Gets the raw values (see BsonValue.RawValue).
[Obsolete("Use Values instead.")]
public override IEnumerable<object> RawValues { get; }
Property Value
Values
Gets the values.
public override IEnumerable<BsonValue> Values { get; }
Property Value
Methods
Add(BsonElement)
Adds an element to the document.
public override BsonDocument Add(BsonElement element)
Parameters
elementBsonElementThe 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
elementsBsonElement[]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
dictionaryDictionary<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
dictionaryDictionary<string, object>The dictionary.
keysIEnumerable<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
dictionaryIDictionary<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
dictionaryIDictionary<string, object>The dictionary.
keysIEnumerable<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
elementsIEnumerable<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
dictionaryIDictionaryThe 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
dictionaryIDictionaryThe dictionary.
keysIEnumerableWhich 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
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
namestringThe name of the element.
valueBsonValueThe value of the element.
conditionboolWhether 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
namestringThe name of the element.
valueFactoryFunc<BsonValue>A delegate called to compute the value of the element if condition is true.
conditionboolWhether 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
dictionaryDictionary<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
elementsIEnumerable<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
dictionaryIEnumerable<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
dictionaryIDictionaryThe 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
otherBsonDocumentThe 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
otherBsonValueThe 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
namestringThe 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
valueBsonValueThe 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
disposingbooltrueto release both managed and unmanaged resources;falseto release only unmanaged resources.
Equals(object)
Determines whether the specified object, is equal to this instance.
public override bool Equals(object obj)
Parameters
Returns
GetElement(int)
Gets an element of this document.
public override BsonElement GetElement(int index)
Parameters
indexintThe 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
namestringThe 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
indexintThe 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
namestringThe 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
namestringThe name of the element.
defaultValueBsonValueThe 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
indexintThe position of the new element.
elementBsonElementThe 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
documentBsonDocumentThe 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
documentBsonDocumentThe other document.
overwriteExistingElementsboolWhether 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
namestringThe name of the element to remove.
RemoveAt(int)
Removes an element from this document.
public override void RemoveAt(int index)
Parameters
indexintThe zero based index of the element to remove.
RemoveElement(BsonElement)
Removes an element from this document.
public override void RemoveElement(BsonElement element)
Parameters
elementBsonElementThe element to remove.
Set(int, BsonValue)
Sets the value of an element.
public override BsonDocument Set(int index, BsonValue value)
Parameters
indexintThe zero based index of the element whose value is to be set.
valueBsonValueThe 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
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
elementBsonElementThe 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
indexintThe zero based index of the element to replace.
elementBsonElementThe new element.
Returns
- BsonDocument
The document.
ThrowIfDisposed()
Throws if disposed.
protected void ThrowIfDisposed()
Exceptions
TryGetElement(string, out BsonElement)
Tries to get an element of this document.
public override bool TryGetElement(string name, out BsonElement value)
Parameters
namestringThe name of the element.
valueBsonElementThe 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
Returns
- bool
True if an element with that name was found.