Table of Contents

Class BsonTypeMapper

Namespace
MongoDB.Bson
Assembly
MongoDB.Bson.dll

A static class that maps between .NET objects and BsonValues.

public static class BsonTypeMapper
Inheritance
BsonTypeMapper
Inherited Members

Methods

MapToBsonValue(object)

Maps an object to an instance of the closest BsonValue class.

public static BsonValue MapToBsonValue(object value)

Parameters

value object

An object.

Returns

BsonValue

A BsonValue.

MapToBsonValue(object, BsonType)

Maps an object to a specific BsonValue type.

public static BsonValue MapToBsonValue(object value, BsonType bsonType)

Parameters

value object

An object.

bsonType BsonType

The BsonType to map to.

Returns

BsonValue

A BsonValue of the desired type (or BsonNull.Value if value is null and bsonType is Null).

MapToDotNetValue(BsonValue)

Maps a BsonValue to a .NET value using the default BsonTypeMapperOptions.

public static object MapToDotNetValue(BsonValue bsonValue)

Parameters

bsonValue BsonValue

The BsonValue.

Returns

object

The mapped .NET value.

MapToDotNetValue(BsonValue, BsonTypeMapperOptions)

Maps a BsonValue to a .NET value.

public static object MapToDotNetValue(BsonValue bsonValue, BsonTypeMapperOptions options)

Parameters

bsonValue BsonValue

The BsonValue.

options BsonTypeMapperOptions

The BsonTypeMapperOptions.

Returns

object

The mapped .NET value.

RegisterCustomTypeMapper(Type, ICustomBsonTypeMapper)

Registers a custom type mapper.

public static void RegisterCustomTypeMapper(Type type, ICustomBsonTypeMapper customTypeMapper)

Parameters

type Type

The type.

customTypeMapper ICustomBsonTypeMapper

A custom type mapper.

TryMapToBsonValue(object, out BsonValue)

Tries to map an object to an instance of the closest BsonValue class.

public static bool TryMapToBsonValue(object value, out BsonValue bsonValue)

Parameters

value object

An object.

bsonValue BsonValue

The BsonValue.

Returns

bool

True if the mapping was successfull.