Table of Contents

Method ToBson

Namespace
MongoDB.Bson
Assembly
MongoDB.Bson.dll

ToBson<TNominalType>(TNominalType, IBsonSerializer<TNominalType>, BsonBinaryWriterSettings, Action<Builder>, BsonSerializationArgs, int)

Serializes an object to a BSON byte array.

public static byte[] ToBson<TNominalType>(this TNominalType obj, IBsonSerializer<TNominalType> serializer = null, BsonBinaryWriterSettings writerSettings = null, Action<BsonSerializationContext.Builder> configurator = null, BsonSerializationArgs args = default, int estimatedBsonSize = 0)

Parameters

obj TNominalType

The object.

serializer IBsonSerializer<TNominalType>

The serializer.

writerSettings BsonBinaryWriterSettings

The writer settings.

configurator Action<BsonSerializationContext.Builder>

The serialization context configurator.

args BsonSerializationArgs

The serialization args.

estimatedBsonSize int

The estimated size of the serialized object

Returns

byte[]

A BSON byte array.

Type Parameters

TNominalType

The nominal type of the object.

ToBson(object, Type, BsonBinaryWriterSettings, IBsonSerializer, Action<Builder>, BsonSerializationArgs, int)

Serializes an object to a BSON byte array.

public static byte[] ToBson(this object obj, Type nominalType, BsonBinaryWriterSettings writerSettings = null, IBsonSerializer serializer = null, Action<BsonSerializationContext.Builder> configurator = null, BsonSerializationArgs args = default, int estimatedBsonSize = 0)

Parameters

obj object

The object.

nominalType Type

The nominal type of the object..

writerSettings BsonBinaryWriterSettings

The writer settings.

serializer IBsonSerializer

The serializer.

configurator Action<BsonSerializationContext.Builder>

The serialization context configurator.

args BsonSerializationArgs

The serialization args.

estimatedBsonSize int

The estimated size of the serialized object.

Returns

byte[]

A BSON byte array.

Exceptions

ArgumentNullException

nominalType

ArgumentException

serializer