Class RawBsonDocument
Represents an immutable BSON document that is represented using only the raw bytes.
[BsonSerializer(typeof(RawBsonDocumentSerializer))]
public class RawBsonDocument : BsonDocument, IComparable<BsonValue>, IConvertible, IEquatable<BsonValue>, IComparable<BsonDocument>, IConvertibleToBsonDocument, IEnumerable<BsonElement>, IEnumerable, IEquatable<BsonDocument>, IDisposable
- Inheritance
-
RawBsonDocument
- Implements
- Inherited Members
- Extension Methods
Constructors
RawBsonDocument(IByteBuffer)
Initializes a new instance of the RawBsonDocument class.
public RawBsonDocument(IByteBuffer slice)
Parameters
slice
IByteBufferThe slice.
Exceptions
- ArgumentNullException
slice
- ArgumentException
RawBsonDocument cannot be used with an IByteBuffer that needs disposing.
RawBsonDocument(byte[])
Initializes a new instance of the RawBsonDocument class.
public RawBsonDocument(byte[] bytes)
Parameters
bytes
byte[]The bytes.
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
this[int]
Gets or sets a value by position.
public override BsonValue this[int index] { get; set; }
Parameters
index
intThe 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
stringThe 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
stringThe name of the element.
defaultValue
BsonValueThe 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
Slice
Gets the slice.
public IByteBuffer Slice { get; }
Property Value
- IByteBuffer
The slice.
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
element
BsonElementThe 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
IDictionaryThe 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
IDictionaryThe dictionary.
keys
IEnumerableWhich 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
name
stringThe name of the element.
value
BsonValueThe value of the element.
condition
boolWhether 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
IDictionaryThe 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.
Contains(string)
Tests whether the document contains an element with the specified name.
public override bool Contains(string name)
Parameters
name
stringThe 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
BsonValueThe 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
booltrue
to release both managed and unmanaged resources;false
to release only unmanaged resources.
GetElement(int)
Gets an element of this document.
public override BsonElement GetElement(int index)
Parameters
index
intThe 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
stringThe 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.
GetValue(int)
Gets the value of an element.
public override BsonValue GetValue(int index)
Parameters
index
intThe 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
stringThe 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
stringThe name of the element.
defaultValue
BsonValueThe 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
intThe position of the new element.
element
BsonElementThe element.
Materialize(BsonBinaryReaderSettings)
Materializes the RawBsonDocument into a regular BsonDocument.
public BsonDocument Materialize(BsonBinaryReaderSettings binaryReaderSettings)
Parameters
binaryReaderSettings
BsonBinaryReaderSettingsThe binary reader settings.
Returns
- BsonDocument
A BsonDocument.
Merge(BsonDocument)
Merges another document into this one. Existing elements are not overwritten.
public override BsonDocument Merge(BsonDocument document)
Parameters
document
BsonDocumentThe 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
BsonDocumentThe other document.
overwriteExistingElements
boolWhether 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
stringThe name of the element to remove.
RemoveAt(int)
Removes an element from this document.
public override void RemoveAt(int index)
Parameters
index
intThe zero based index of the element to remove.
RemoveElement(BsonElement)
Removes an element from this document.
public override void RemoveElement(BsonElement element)
Parameters
element
BsonElementThe element to remove.
Set(int, BsonValue)
Sets the value of an element.
public override BsonDocument Set(int index, BsonValue value)
Parameters
index
intThe zero based index of the element whose value is to be set.
value
BsonValueThe 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
element
BsonElementThe 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
intThe zero based index of the element to replace.
element
BsonElementThe new element.
Returns
- BsonDocument
The document.
ThrowIfDisposed()
Throws if disposed.
protected void ThrowIfDisposed()
Exceptions
- ObjectDisposedException
RawBsonDocument
TryGetElement(string, out BsonElement)
Tries to get an element of this document.
public override bool TryGetElement(string name, out BsonElement element)
Parameters
name
stringThe name of the element.
element
BsonElementThe 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.