Click or drag to resize

BsonMapper Class

Class that converts your entity class to/from BsonDocument If you prefer use a new instance of BsonMapper (not Global), be sure cache this instance for better performance Serialization rules: - Classes must be "public" with a public constructor (without parameters) - Properties must have public getter (can be read-only) - Entity class must have Id property, [ClassName]Id property or [BsonId] attribute - No circular references - Fields are not valid - IList, Array supports - IDictionary supports (Key must be a simple datatype - converted by ChangeType)
Inheritance Hierarchy
SystemObject
  Internal.LiteDBBsonMapper

Namespace: Internal.LiteDB
Assembly: NeoAxis.Core (in NeoAxis.Core.dll) Version: 2026.1.1.0 (2026.1.1.0)
Syntax
C#
public class BsonMapper

The BsonMapper type exposes the following members.

Constructors
 NameDescription
Public methodBsonMapperInitializes a new instance of the BsonMapper class
Top
Properties
 NameDescription
Public propertyEmptyStringToNull Convert EmptyString to Null (default true)
Public propertyEnumAsInteger Get/Set if enum must be converted into Integer value. If false, enum will be converted into String value. MUST BE "true" to support LINQ expressions (default false)
Public propertyIncludeFields Get/Set that mapper must include fields (default: false)
Public propertyIncludeNonPublic Get/Set that mapper must include non public (private, protected and internal) (default: false)
Public propertyMaxDepth Get/Set maximum depth for nested object (default 20)
Public propertyOnDeserialization Gets called before deserialization of a value
Public propertySerializeNullValues Indicate that mapper do not serialize null values (default false)
Public propertyTrimWhitespace Apply .Trim() in strings when serialize (default true)
Top
Methods
 NameDescription
Protected methodBuildEntityMapper Use this method to override how your class can be, by default, mapped from entity to Bson document. Returns an EntityMapper from each requested Type
Public methodDeserialize(Type, BsonValue) Deserilize a BsonValue to .NET object based on type parameter
Public methodDeserializeT(BsonValue) Deserialize a BsonValue to .NET object typed in T
Public methodEntityT Map your entity class to BsonDocument using fluent API
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
Public methodGetExpressionT, K Resolve LINQ expression into BsonExpression
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Protected methodGetIdMember Gets MemberInfo that refers to Id from a document object.
Public methodGetIndexExpressionT, K Resolve LINQ expression into BsonExpression (for index only)
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Protected methodGetTypeCtor Get best construtor to use to initialize this entity. - Look if contains [BsonCtor] attribute - Look for parameterless ctor - Look for first contructor with parameter and use BsonDocument to send RawValue
Protected methodGetTypeMembers Returns all member that will be have mapper between POCO class to document
Protected methodMemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
Public methodRegisterType(Type, FuncObject, BsonValue, FuncBsonValue, Object) Register a custom type serializer/deserialize function
Public methodRegisterTypeT(FuncT, BsonValue, FuncBsonValue, T) Register a custom type serializer/deserialize function
Public methodSerialize(Type, Object) Serialize to BsonValue any .NET object based on type parameter (using mapping rules)
Public methodSerializeT(T) Serialize to BsonValue any .NET object based on T type (using mapping rules)
Public methodToDocument(Type, Object) Serialize a entity class to BsonDocument
Public methodToDocumentT(T) Serialize a entity class to BsonDocument
Public methodToObject(Type, BsonDocument) Deserialize a BsonDocument to entity class
Public methodToObjectT(BsonDocument) Deserialize a BsonDocument to entity class
Public methodToStringReturns a string that represents the current object.
(Inherited from Object)
Public methodUseCamelCase Use lower camel case resolution for convert property names to field names
Public methodUseLowerCaseDelimiter Uses lower camel case with delimiter to convert property names to field names
Top
Fields
 NameDescription
Public fieldStatic memberGlobal Global instance used when no BsonMapper are passed in LiteDatabase ctor
Public fieldResolveCollectionName Custom resolve name collection based on Type
Public fieldResolveFieldName A resolver name for field
Public fieldResolveMember A custom callback to change MemberInfo behavior when converting to MemberMapper. Use mapper.ResolveMember(Type entity, MemberInfo property, MemberMapper documentMappedField) Set FieldName to null if you want remove from mapped document
Top
Extension Methods
 NameDescription
Public Extension MethodMethodInvoke Calls the object method by name.
(Defined by ObjectEx)
Public Extension MethodPropertyGet Gets the value of the object property by name.
(Defined by ObjectEx)
Public Extension MethodPropertyGetT Gets the value of the object property by name.
(Defined by ObjectEx)
Public Extension MethodPropertySet Sets the value of the object property by name.
(Defined by ObjectEx)
Top
See Also