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
TypeThe class type.
BsonClassMap(Type, BsonClassMap)
Initializes a new instance of the BsonClassMap class.
public BsonClassMap(Type classType, BsonClassMap baseClassMap)
Parameters
classType
TypeType of the class.
baseClassMap
BsonClassMapThe base class map.
Properties
AllMemberMaps
Gets all the member maps (including maps for inherited members).
public ReadOnlyCollection<BsonMemberMap> AllMemberMaps { get; }
Property Value
BaseClassMap
Gets the base class map.
public BsonClassMap BaseClassMap { get; }
Property Value
ClassType
Gets the class type.
public Type ClassType { get; }
Property Value
ConventionPack
Gets the conventions used for auto mapping.
public IConventionPack ConventionPack { get; }
Property Value
CreatorMaps
Gets the constructor maps.
public IEnumerable<BsonCreatorMap> CreatorMaps { get; }
Property Value
DeclaredMemberMaps
Gets the declared member maps (only for members declared in this class).
public IEnumerable<BsonMemberMap> DeclaredMemberMaps { get; }
Property Value
Discriminator
Gets the discriminator.
public string Discriminator { get; }
Property Value
DiscriminatorIsRequired
Gets whether a discriminator is required when serializing this class.
public bool DiscriminatorIsRequired { get; }
Property Value
ExtraElementsMemberMap
Gets the member map of the member used to hold extra elements.
public BsonMemberMap ExtraElementsMemberMap { get; }
Property Value
HasCreatorMaps
Gets whether this class map has any creator maps.
public bool HasCreatorMaps { get; }
Property Value
HasRootClass
Gets whether this class has a root class ancestor.
public bool HasRootClass { get; }
Property Value
IdMemberMap
Gets the Id member map (null if none).
public BsonMemberMap IdMemberMap { get; }
Property Value
IgnoreExtraElements
Gets whether extra elements should be ignored when deserializing.
public bool IgnoreExtraElements { get; }
Property Value
IgnoreExtraElementsIsInherited
Gets whether the IgnoreExtraElements value should be inherited by derived classes.
public bool IgnoreExtraElementsIsInherited { get; }
Property Value
IsAnonymous
Gets whether this class is anonymous.
public bool IsAnonymous { get; }
Property Value
IsFrozen
Gets whether the class map is frozen.
public bool IsFrozen { get; }
Property Value
IsRootClass
Gets whether this class is a root class.
public bool IsRootClass { get; }
Property Value
KnownTypes
Gets the known types of this class.
public IEnumerable<Type> KnownTypes { get; }
Property Value
Methods
AddKnownType(Type)
Adds a known type to the class map.
public void AddKnownType(Type type)
Parameters
type
TypeThe 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
MemberInfoThe 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
stringThe 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
stringThe 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
TypeThe 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
TypeThe 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
ConstructorInfoThe 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
ConstructorInfoThe 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
DelegateThe 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
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
stringThe 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
MemberInfoThe 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
stringThe 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
MethodInfoThe 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
MethodInfoThe 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
stringThe 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
stringThe 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
MemberInfoThe 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
stringThe 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
MemberInfoThe 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
stringThe 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
BsonClassMapThe 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
Returns
- BsonClassMap
The class map (so method calls can be chained).
SetDiscriminator(string)
Sets the discriminator.
public void SetDiscriminator(string discriminator)
Parameters
discriminator
stringThe discriminator.
SetDiscriminatorIsRequired(bool)
Sets whether a discriminator is required when serializing this class.
public void SetDiscriminatorIsRequired(bool discriminatorIsRequired)
Parameters
discriminatorIsRequired
boolWhether 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
BsonMemberMapThe extra elements member map.
SetIdMember(BsonMemberMap)
Sets the Id member.
public void SetIdMember(BsonMemberMap memberMap)
Parameters
memberMap
BsonMemberMapThe Id member (null if none).
SetIgnoreExtraElements(bool)
Sets whether extra elements should be ignored when deserializing.
public void SetIgnoreExtraElements(bool ignoreExtraElements)
Parameters
ignoreExtraElements
boolWhether 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
boolWhether 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
boolWhether 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
ConstructorInfoThe constructor info.
UnmapFactoryMethod(MethodInfo)
Removes a creator map for a factory method from the class map.
public void UnmapFactoryMethod(MethodInfo methodInfo)
Parameters
methodInfo
MethodInfoThe method info.
UnmapField(string)
Removes the member map for a field from the class map.
public void UnmapField(string fieldName)
Parameters
fieldName
stringThe name of the field.
UnmapMember(MemberInfo)
Removes a member map from the class map.
public void UnmapMember(MemberInfo memberInfo)
Parameters
memberInfo
MemberInfoThe member info.
UnmapProperty(string)
Removes the member map for a property from the class map.
public void UnmapProperty(string propertyName)
Parameters
propertyName
stringThe name of the property.