Class BsonSerializer
- Namespace
- MongoDB.Bson.Serialization
- Assembly
- MongoDB.Bson.dll
A static class that represents the BSON serialization functionality.
public static class BsonSerializer
- Inheritance
-
BsonSerializer
- Inherited Members
Properties
SerializerRegistry
Gets the serializer registry.
public static IBsonSerializerRegistry SerializerRegistry { get; }
Property Value
UseNullIdChecker
Gets or sets whether to use the NullIdChecker on reference Id types that don't have an IdGenerator registered.
public static bool UseNullIdChecker { get; set; }
Property Value
UseZeroIdChecker
Gets or sets whether to use the ZeroIdChecker on value Id types that don't have an IdGenerator registered.
public static bool UseZeroIdChecker { get; set; }
Property Value
Methods
Deserialize(BsonDocument, Type, Action<Builder>)
Deserializes an object from a BsonDocument.
public static object Deserialize(BsonDocument document, Type nominalType, Action<BsonDeserializationContext.Builder> configurator = null)
Parameters
document
BsonDocumentThe BsonDocument.
nominalType
TypeThe nominal type of the object.
configurator
Action<BsonDeserializationContext.Builder>The configurator.
Returns
- object
A deserialized value.
Deserialize(IBsonReader, Type, Action<Builder>)
Deserializes a value.
public static object Deserialize(IBsonReader bsonReader, Type nominalType, Action<BsonDeserializationContext.Builder> configurator = null)
Parameters
bsonReader
IBsonReaderThe BsonReader.
nominalType
TypeThe nominal type of the object.
configurator
Action<BsonDeserializationContext.Builder>The configurator.
Returns
- object
A deserialized value.
Deserialize(byte[], Type, Action<Builder>)
Deserializes an object from a BSON byte array.
public static object Deserialize(byte[] bytes, Type nominalType, Action<BsonDeserializationContext.Builder> configurator = null)
Parameters
bytes
byte[]The BSON byte array.
nominalType
TypeThe nominal type of the object.
configurator
Action<BsonDeserializationContext.Builder>The configurator.
Returns
- object
A deserialized value.
Deserialize(Stream, Type, Action<Builder>)
Deserializes an object from a BSON Stream.
public static object Deserialize(Stream stream, Type nominalType, Action<BsonDeserializationContext.Builder> configurator = null)
Parameters
stream
StreamThe BSON Stream.
nominalType
TypeThe nominal type of the object.
configurator
Action<BsonDeserializationContext.Builder>The configurator.
Returns
- object
A deserialized value.
Deserialize(TextReader, Type, Action<Builder>)
Deserializes an object from a JSON TextReader.
public static object Deserialize(TextReader textReader, Type nominalType, Action<BsonDeserializationContext.Builder> configurator = null)
Parameters
textReader
TextReaderThe JSON TextReader.
nominalType
TypeThe nominal type of the object.
configurator
Action<BsonDeserializationContext.Builder>The configurator.
Returns
- object
A deserialized value.
Deserialize(string, Type, Action<Builder>)
Deserializes an object from a JSON string.
public static object Deserialize(string json, Type nominalType, Action<BsonDeserializationContext.Builder> configurator = null)
Parameters
json
stringThe JSON string.
nominalType
TypeThe nominal type of the object.
configurator
Action<BsonDeserializationContext.Builder>The configurator.
Returns
- object
A deserialized value.
Deserialize<TNominalType>(BsonDocument, Action<Builder>)
Deserializes an object from a BsonDocument.
public static TNominalType Deserialize<TNominalType>(BsonDocument document, Action<BsonDeserializationContext.Builder> configurator = null)
Parameters
document
BsonDocumentThe BsonDocument.
configurator
Action<BsonDeserializationContext.Builder>The configurator.
Returns
- TNominalType
A deserialized value.
Type Parameters
TNominalType
The nominal type of the object.
Deserialize<TNominalType>(IBsonReader, Action<Builder>)
Deserializes a value.
public static TNominalType Deserialize<TNominalType>(IBsonReader bsonReader, Action<BsonDeserializationContext.Builder> configurator = null)
Parameters
bsonReader
IBsonReaderThe BsonReader.
configurator
Action<BsonDeserializationContext.Builder>The configurator.
Returns
- TNominalType
A deserialized value.
Type Parameters
TNominalType
The nominal type of the object.
Deserialize<TNominalType>(byte[], Action<Builder>)
Deserializes an object from a BSON byte array.
public static TNominalType Deserialize<TNominalType>(byte[] bytes, Action<BsonDeserializationContext.Builder> configurator = null)
Parameters
bytes
byte[]The BSON byte array.
configurator
Action<BsonDeserializationContext.Builder>The configurator.
Returns
- TNominalType
A deserialized value.
Type Parameters
TNominalType
The nominal type of the object.
Deserialize<TNominalType>(Stream, Action<Builder>)
Deserializes an object from a BSON Stream.
public static TNominalType Deserialize<TNominalType>(Stream stream, Action<BsonDeserializationContext.Builder> configurator = null)
Parameters
stream
StreamThe BSON Stream.
configurator
Action<BsonDeserializationContext.Builder>The configurator.
Returns
- TNominalType
A deserialized value.
Type Parameters
TNominalType
The nominal type of the object.
Deserialize<TNominalType>(TextReader, Action<Builder>)
Deserializes an object from a JSON TextReader.
public static TNominalType Deserialize<TNominalType>(TextReader textReader, Action<BsonDeserializationContext.Builder> configurator = null)
Parameters
textReader
TextReaderThe JSON TextReader.
configurator
Action<BsonDeserializationContext.Builder>The configurator.
Returns
- TNominalType
A deserialized value.
Type Parameters
TNominalType
The nominal type of the object.
Deserialize<TNominalType>(string, Action<Builder>)
Deserializes an object from a JSON string.
public static TNominalType Deserialize<TNominalType>(string json, Action<BsonDeserializationContext.Builder> configurator = null)
Parameters
json
stringThe JSON string.
configurator
Action<BsonDeserializationContext.Builder>The configurator.
Returns
- TNominalType
A deserialized value.
Type Parameters
TNominalType
The nominal type of the object.
IsTypeDiscriminated(Type)
Returns whether the given type has any discriminators registered for any of its subclasses.
public static bool IsTypeDiscriminated(Type type)
Parameters
type
TypeA Type.
Returns
- bool
True if the type is discriminated.
LookupActualType(Type, BsonValue)
Looks up the actual type of an object to be deserialized.
public static Type LookupActualType(Type nominalType, BsonValue discriminator)
Parameters
Returns
- Type
The actual type of the object.
LookupDiscriminatorConvention(Type)
Looks up the discriminator convention for a type.
public static IDiscriminatorConvention LookupDiscriminatorConvention(Type type)
Parameters
type
TypeThe type.
Returns
- IDiscriminatorConvention
A discriminator convention.
LookupIdGenerator(Type)
Looks up an IdGenerator.
public static IIdGenerator LookupIdGenerator(Type type)
Parameters
type
TypeThe Id type.
Returns
- IIdGenerator
An IdGenerator for the Id type.
LookupSerializer(Type)
Looks up a serializer for a Type.
public static IBsonSerializer LookupSerializer(Type type)
Parameters
type
TypeThe Type.
Returns
- IBsonSerializer
A serializer for the Type.
LookupSerializer<T>()
Looks up a serializer for a Type.
public static IBsonSerializer<T> LookupSerializer<T>()
Returns
- IBsonSerializer<T>
A serializer for type T.
Type Parameters
T
The type.
RegisterDiscriminator(Type, BsonValue)
Registers the discriminator for a type.
public static void RegisterDiscriminator(Type type, BsonValue discriminator)
Parameters
RegisterDiscriminatorConvention(Type, IDiscriminatorConvention)
Registers the discriminator convention for a type.
public static void RegisterDiscriminatorConvention(Type type, IDiscriminatorConvention convention)
Parameters
type
TypeType type.
convention
IDiscriminatorConventionThe discriminator convention.
RegisterGenericSerializerDefinition(Type, Type)
Registers a generic serializer definition for a generic type.
public static void RegisterGenericSerializerDefinition(Type genericTypeDefinition, Type genericSerializerDefinition)
Parameters
genericTypeDefinition
TypeThe generic type.
genericSerializerDefinition
TypeThe generic serializer definition.
RegisterIdGenerator(Type, IIdGenerator)
Registers an IdGenerator for an Id Type.
public static void RegisterIdGenerator(Type type, IIdGenerator idGenerator)
Parameters
type
TypeThe Id Type.
idGenerator
IIdGeneratorThe IdGenerator for the Id Type.
RegisterSerializationProvider(IBsonSerializationProvider)
Registers a serialization provider.
public static void RegisterSerializationProvider(IBsonSerializationProvider provider)
Parameters
provider
IBsonSerializationProviderThe serialization provider.
RegisterSerializer(Type, IBsonSerializer)
Registers a serializer for a type.
public static void RegisterSerializer(Type type, IBsonSerializer serializer)
Parameters
type
TypeThe type.
serializer
IBsonSerializerThe serializer.
RegisterSerializer<T>(IBsonSerializer<T>)
Registers a serializer for a type.
public static void RegisterSerializer<T>(IBsonSerializer<T> serializer)
Parameters
serializer
IBsonSerializer<T>The serializer.
Type Parameters
T
The type.
Serialize(IBsonWriter, Type, object, Action<Builder>, BsonSerializationArgs)
Serializes a value.
public static void Serialize(IBsonWriter bsonWriter, Type nominalType, object value, Action<BsonSerializationContext.Builder> configurator = null, BsonSerializationArgs args = default)
Parameters
bsonWriter
IBsonWriterThe BsonWriter.
nominalType
TypeThe nominal type of the object.
value
objectThe object.
configurator
Action<BsonSerializationContext.Builder>The serialization context configurator.
args
BsonSerializationArgsThe serialization args.
Serialize<TNominalType>(IBsonWriter, TNominalType, Action<Builder>, BsonSerializationArgs)
Serializes a value.
public static void Serialize<TNominalType>(IBsonWriter bsonWriter, TNominalType value, Action<BsonSerializationContext.Builder> configurator = null, BsonSerializationArgs args = default)
Parameters
bsonWriter
IBsonWriterThe BsonWriter.
value
TNominalTypeThe object.
configurator
Action<BsonSerializationContext.Builder>The serialization context configurator.
args
BsonSerializationArgsThe serialization args.
Type Parameters
TNominalType
The nominal type of the object.
TryRegisterSerializer(Type, IBsonSerializer)
Tries to register a serializer for a type.
public static bool TryRegisterSerializer(Type type, IBsonSerializer serializer)
Parameters
type
TypeThe type.
serializer
IBsonSerializerThe serializer.
Returns
- bool
True if the serializer was registered on this call, false if the same serializer was already registered on a previous call, throws an exception if a different serializer was already registered.
TryRegisterSerializer<T>(IBsonSerializer<T>)
Tries to register a serializer for a type.
public static bool TryRegisterSerializer<T>(IBsonSerializer<T> serializer)
Parameters
serializer
IBsonSerializer<T>The serializer.
Returns
- bool
True if the serializer was registered on this call, false if the same serializer was already registered on a previous call, throws an exception if a different serializer was already registered.
Type Parameters
T
The type.