Table of Contents

Class BsonClassMap

Namespace
MongoDB.Bson.Serialization
Assembly
MongoDB.Bson.dll

Represents a mapping between a class and a BSON document.

public class BsonClassMap
Inheritance
BsonClassMap
Derived
BsonClassMap<TClass>
Inherited Members
Extension Methods

Constructors

BsonClassMap(Type)

Initializes a new instance of the BsonClassMap class.

public BsonClassMap(Type classType)

Parameters

classType Type

The class type.

BsonClassMap(Type, BsonClassMap)

Initializes a new instance of the BsonClassMap class.

public BsonClassMap(Type classType, BsonClassMap baseClassMap)

Parameters

classType Type

Type of the class.

baseClassMap BsonClassMap

The base class map.

Properties

AllMemberMaps

Gets all the member maps (including maps for inherited members).

public ReadOnlyCollection<BsonMemberMap> AllMemberMaps { get; }

Property Value

ReadOnlyCollection<BsonMemberMap>

BaseClassMap

Gets the base class map.

public BsonClassMap BaseClassMap { get; }

Property Value

BsonClassMap

ClassType

Gets the class type.

public Type ClassType { get; }

Property Value

Type

ConventionPack

Gets the conventions used for auto mapping.

public IConventionPack ConventionPack { get; }

Property Value

IConventionPack

CreatorMaps

Gets the constructor maps.

public IEnumerable<BsonCreatorMap> CreatorMaps { get; }

Property Value

IEnumerable<BsonCreatorMap>

DeclaredMemberMaps

Gets the declared member maps (only for members declared in this class).

public IEnumerable<BsonMemberMap> DeclaredMemberMaps { get; }

Property Value

IEnumerable<BsonMemberMap>

Discriminator

Gets the discriminator.

public string Discriminator { get; }

Property Value

string

DiscriminatorIsRequired

Gets whether a discriminator is required when serializing this class.

public bool DiscriminatorIsRequired { get; }

Property Value

bool

ExtraElementsMemberMap

Gets the member map of the member used to hold extra elements.

public BsonMemberMap ExtraElementsMemberMap { get; }

Property Value

BsonMemberMap

HasCreatorMaps

Gets whether this class map has any creator maps.

public bool HasCreatorMaps { get; }

Property Value

bool

HasRootClass

Gets whether this class has a root class ancestor.

public bool HasRootClass { get; }

Property Value

bool

IdMemberMap

Gets the Id member map (null if none).

public BsonMemberMap IdMemberMap { get; }

Property Value

BsonMemberMap

IgnoreExtraElements

Gets whether extra elements should be ignored when deserializing.

public bool IgnoreExtraElements { get; }

Property Value

bool

IgnoreExtraElementsIsInherited

Gets whether the IgnoreExtraElements value should be inherited by derived classes.

public bool IgnoreExtraElementsIsInherited { get; }

Property Value

bool

IsAnonymous

Gets whether this class is anonymous.

public bool IsAnonymous { get; }

Property Value

bool

IsFrozen

Gets whether the class map is frozen.

public bool IsFrozen { get; }

Property Value

bool

IsRootClass

Gets whether this class is a root class.

public bool IsRootClass { get; }

Property Value

bool

KnownTypes

Gets the known types of this class.

public IEnumerable<Type> KnownTypes { get; }

Property Value

IEnumerable<Type>

Methods

AddKnownType(Type)

Adds a known type to the class map.

public void AddKnownType(Type type)

Parameters

type Type

The known type.

AutoMap()

Automaps the class.

public void AutoMap()

CreateInstance()

Creates an instance of the class.

public object CreateInstance()

Returns

object

An object.

Freeze()

Freezes the class map.

public BsonClassMap Freeze()

Returns

BsonClassMap

The frozen class map.

GetMemberInfoType(MemberInfo)

Gets the type of a member.

public static Type GetMemberInfoType(MemberInfo memberInfo)

Parameters

memberInfo MemberInfo

The member info.

Returns

Type

The type of the member.

GetMemberMap(string)

Gets a member map (only considers members declared in this class).

public BsonMemberMap GetMemberMap(string memberName)

Parameters

memberName string

The member name.

Returns

BsonMemberMap

The member map (or null if the member was not found).

GetMemberMapForElement(string)

Gets the member map for a BSON element.

public BsonMemberMap GetMemberMapForElement(string elementName)

Parameters

elementName string

The name of the element.

Returns

BsonMemberMap

The member map.

GetRegisteredClassMaps()

Gets all registered class maps.

public static IEnumerable<BsonClassMap> GetRegisteredClassMaps()

Returns

IEnumerable<BsonClassMap>

All registered class maps.

IsClassMapRegistered(Type)

Checks whether a class map is registered for a type.

public static bool IsClassMapRegistered(Type type)

Parameters

type Type

The type to check.

Returns

bool

True if there is a class map registered for the type.

LookupClassMap(Type)

Looks up a class map (will AutoMap the class if no class map is registered).

public static BsonClassMap LookupClassMap(Type classType)

Parameters

classType Type

The class type.

Returns

BsonClassMap

The class map.

MapConstructor(ConstructorInfo)

Creates a creator map for a constructor and adds it to the class map.

public BsonCreatorMap MapConstructor(ConstructorInfo constructorInfo)

Parameters

constructorInfo ConstructorInfo

The constructor info.

Returns

BsonCreatorMap

The creator map (so method calls can be chained).

MapConstructor(ConstructorInfo, params string[])

Creates a creator map for a constructor and adds it to the class map.

public BsonCreatorMap MapConstructor(ConstructorInfo constructorInfo, params string[] argumentNames)

Parameters

constructorInfo ConstructorInfo

The constructor info.

argumentNames string[]

The argument names.

Returns

BsonCreatorMap

The creator map (so method calls can be chained).

MapCreator(Delegate)

Creates a creator map and adds it to the class.

public BsonCreatorMap MapCreator(Delegate @delegate)

Parameters

delegate Delegate

The delegate.

Returns

BsonCreatorMap

The factory method map (so method calls can be chained).

MapCreator(Delegate, params string[])

Creates a creator map and adds it to the class.

public BsonCreatorMap MapCreator(Delegate @delegate, params string[] argumentNames)

Parameters

delegate Delegate

The delegate.

argumentNames string[]

The argument names.

Returns

BsonCreatorMap

The factory method map (so method calls can be chained).

MapExtraElementsField(string)

Creates a member map for the extra elements field and adds it to the class map.

public BsonMemberMap MapExtraElementsField(string fieldName)

Parameters

fieldName string

The name of the extra elements field.

Returns

BsonMemberMap

The member map (so method calls can be chained).

MapExtraElementsMember(MemberInfo)

Creates a member map for the extra elements member and adds it to the class map.

public BsonMemberMap MapExtraElementsMember(MemberInfo memberInfo)

Parameters

memberInfo MemberInfo

The member info for the extra elements member.

Returns

BsonMemberMap

The member map (so method calls can be chained).

MapExtraElementsProperty(string)

Creates a member map for the extra elements property and adds it to the class map.

public BsonMemberMap MapExtraElementsProperty(string propertyName)

Parameters

propertyName string

The name of the property.

Returns

BsonMemberMap

The member map (so method calls can be chained).

MapFactoryMethod(MethodInfo)

Creates a creator map for a factory method and adds it to the class.

public BsonCreatorMap MapFactoryMethod(MethodInfo methodInfo)

Parameters

methodInfo MethodInfo

The method info.

Returns

BsonCreatorMap

The creator map (so method calls can be chained).

MapFactoryMethod(MethodInfo, params string[])

Creates a creator map for a factory method and adds it to the class.

public BsonCreatorMap MapFactoryMethod(MethodInfo methodInfo, params string[] argumentNames)

Parameters

methodInfo MethodInfo

The method info.

argumentNames string[]

The argument names.

Returns

BsonCreatorMap

The creator map (so method calls can be chained).

MapField(string)

Creates a member map for a field and adds it to the class map.

public BsonMemberMap MapField(string fieldName)

Parameters

fieldName string

The name of the field.

Returns

BsonMemberMap

The member map (so method calls can be chained).

MapIdField(string)

Creates a member map for the Id field and adds it to the class map.

public BsonMemberMap MapIdField(string fieldName)

Parameters

fieldName string

The name of the Id field.

Returns

BsonMemberMap

The member map (so method calls can be chained).

MapIdMember(MemberInfo)

Creates a member map for the Id member and adds it to the class map.

public BsonMemberMap MapIdMember(MemberInfo memberInfo)

Parameters

memberInfo MemberInfo

The member info for the Id member.

Returns

BsonMemberMap

The member map (so method calls can be chained).

MapIdProperty(string)

Creates a member map for the Id property and adds it to the class map.

public BsonMemberMap MapIdProperty(string propertyName)

Parameters

propertyName string

The name of the Id property.

Returns

BsonMemberMap

The member map (so method calls can be chained).

MapMember(MemberInfo)

Creates a member map for a member and adds it to the class map.

public BsonMemberMap MapMember(MemberInfo memberInfo)

Parameters

memberInfo MemberInfo

The member info.

Returns

BsonMemberMap

The member map (so method calls can be chained).

MapProperty(string)

Creates a member map for a property and adds it to the class map.

public BsonMemberMap MapProperty(string propertyName)

Parameters

propertyName string

The name of the property.

Returns

BsonMemberMap

The member map (so method calls can be chained).

RegisterClassMap(BsonClassMap)

Registers a class map.

public static void RegisterClassMap(BsonClassMap classMap)

Parameters

classMap BsonClassMap

The class map.

RegisterClassMap<TClass>()

Creates and registers a class map.

public static BsonClassMap<TClass> RegisterClassMap<TClass>()

Returns

BsonClassMap<TClass>

The class map.

Type Parameters

TClass

The class.

RegisterClassMap<TClass>(Action<BsonClassMap<TClass>>)

Creates and registers a class map.

public static BsonClassMap<TClass> RegisterClassMap<TClass>(Action<BsonClassMap<TClass>> classMapInitializer)

Parameters

classMapInitializer Action<BsonClassMap<TClass>>

The class map initializer.

Returns

BsonClassMap<TClass>

The class map.

Type Parameters

TClass

The class.

Reset()

Resets the class map back to its initial state.

public void Reset()

SetCreator(Func<object>)

Sets the creator for the object.

public BsonClassMap SetCreator(Func<object> creator)

Parameters

creator Func<object>

The creator.

Returns

BsonClassMap

The class map (so method calls can be chained).

SetDiscriminator(string)

Sets the discriminator.

public void SetDiscriminator(string discriminator)

Parameters

discriminator string

The discriminator.

SetDiscriminatorIsRequired(bool)

Sets whether a discriminator is required when serializing this class.

public void SetDiscriminatorIsRequired(bool discriminatorIsRequired)

Parameters

discriminatorIsRequired bool

Whether a discriminator is required.

SetExtraElementsMember(BsonMemberMap)

Sets the member map of the member used to hold extra elements.

public void SetExtraElementsMember(BsonMemberMap memberMap)

Parameters

memberMap BsonMemberMap

The extra elements member map.

SetIdMember(BsonMemberMap)

Sets the Id member.

public void SetIdMember(BsonMemberMap memberMap)

Parameters

memberMap BsonMemberMap

The Id member (null if none).

SetIgnoreExtraElements(bool)

Sets whether extra elements should be ignored when deserializing.

public void SetIgnoreExtraElements(bool ignoreExtraElements)

Parameters

ignoreExtraElements bool

Whether extra elements should be ignored when deserializing.

SetIgnoreExtraElementsIsInherited(bool)

Sets whether the IgnoreExtraElements value should be inherited by derived classes.

public void SetIgnoreExtraElementsIsInherited(bool ignoreExtraElementsIsInherited)

Parameters

ignoreExtraElementsIsInherited bool

Whether the IgnoreExtraElements value should be inherited by derived classes.

SetIsRootClass(bool)

Sets whether this class is a root class.

public void SetIsRootClass(bool isRootClass)

Parameters

isRootClass bool

Whether this class is a root class.

TryRegisterClassMap<TClass>()

Registers a class map if it is not already registered.

public static bool TryRegisterClassMap<TClass>()

Returns

bool

True if this call registered the class map, false if the class map was already registered.

Type Parameters

TClass

The class.

TryRegisterClassMap<TClass>(BsonClassMap<TClass>)

Registers a class map if it is not already registered.

public static bool TryRegisterClassMap<TClass>(BsonClassMap<TClass> classMap)

Parameters

classMap BsonClassMap<TClass>

The class map.

Returns

bool

True if this call registered the class map, false if the class map was already registered.

Type Parameters

TClass

The class.

TryRegisterClassMap<TClass>(Action<BsonClassMap<TClass>>)

Registers a class map if it is not already registered.

public static bool TryRegisterClassMap<TClass>(Action<BsonClassMap<TClass>> classMapInitializer)

Parameters

classMapInitializer Action<BsonClassMap<TClass>>

The class map initializer (only called if the class map is not already registered).

Returns

bool

True if this call registered the class map, false if the class map was already registered.

Type Parameters

TClass

The class.

TryRegisterClassMap<TClass>(Func<BsonClassMap<TClass>>)

Registers a class map if it is not already registered.

public static bool TryRegisterClassMap<TClass>(Func<BsonClassMap<TClass>> classMapFactory)

Parameters

classMapFactory Func<BsonClassMap<TClass>>

The class map factory (only called if the class map is not already registered).

Returns

bool

True if this call registered the class map, false if the class map was already registered.

Type Parameters

TClass

The class.

UnmapConstructor(ConstructorInfo)

Removes a creator map for a constructor from the class map.

public void UnmapConstructor(ConstructorInfo constructorInfo)

Parameters

constructorInfo ConstructorInfo

The constructor info.

UnmapFactoryMethod(MethodInfo)

Removes a creator map for a factory method from the class map.

public void UnmapFactoryMethod(MethodInfo methodInfo)

Parameters

methodInfo MethodInfo

The method info.

UnmapField(string)

Removes the member map for a field from the class map.

public void UnmapField(string fieldName)

Parameters

fieldName string

The name of the field.

UnmapMember(MemberInfo)

Removes a member map from the class map.

public void UnmapMember(MemberInfo memberInfo)

Parameters

memberInfo MemberInfo

The member info.

UnmapProperty(string)

Removes the member map for a property from the class map.

public void UnmapProperty(string propertyName)

Parameters

propertyName string

The name of the property.