Table of Contents

Class ObjectSerializer

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

Represents a serializer for objects.

public class ObjectSerializer : ClassSerializerBase<object>, IBsonSerializer<object>, IBsonSerializer
Inheritance
ObjectSerializer
Implements
Inherited Members
Extension Methods

Constructors

ObjectSerializer()

Initializes a new instance of the ObjectSerializer class.

public ObjectSerializer()

ObjectSerializer(IDiscriminatorConvention)

Initializes a new instance of the ObjectSerializer class.

public ObjectSerializer(IDiscriminatorConvention discriminatorConvention)

Parameters

discriminatorConvention IDiscriminatorConvention

The discriminator convention.

Exceptions

ArgumentNullException

discriminatorConvention

ObjectSerializer(IDiscriminatorConvention, GuidRepresentation)

Initializes a new instance of the ObjectSerializer class.

public ObjectSerializer(IDiscriminatorConvention discriminatorConvention, GuidRepresentation guidRepresentation)

Parameters

discriminatorConvention IDiscriminatorConvention

The discriminator convention.

guidRepresentation GuidRepresentation

The Guid representation.

ObjectSerializer(IDiscriminatorConvention, GuidRepresentation, Func<Type, bool>)

Initializes a new instance of the ObjectSerializer class.

public ObjectSerializer(IDiscriminatorConvention discriminatorConvention, GuidRepresentation guidRepresentation, Func<Type, bool> allowedTypes)

Parameters

discriminatorConvention IDiscriminatorConvention

The discriminator convention.

guidRepresentation GuidRepresentation

The Guid representation.

allowedTypes Func<Type, bool>

A delegate that determines what types are allowed.

ObjectSerializer(IDiscriminatorConvention, GuidRepresentation, Func<Type, bool>, Func<Type, bool>)

Initializes a new instance of the ObjectSerializer class.

public ObjectSerializer(IDiscriminatorConvention discriminatorConvention, GuidRepresentation guidRepresentation, Func<Type, bool> allowedDeserializationTypes, Func<Type, bool> allowedSerializationTypes)

Parameters

discriminatorConvention IDiscriminatorConvention

The discriminator convention.

guidRepresentation GuidRepresentation

The Guid representation.

allowedDeserializationTypes Func<Type, bool>

A delegate that determines what types are allowed to be deserialized.

allowedSerializationTypes Func<Type, bool>

A delegate that determines what types are allowed to be serialized.

ObjectSerializer(IDiscriminatorConvention, Func<Type, bool>)

Initializes a new instance of the ObjectSerializer class.

public ObjectSerializer(IDiscriminatorConvention discriminatorConvention, Func<Type, bool> allowedTypes)

Parameters

discriminatorConvention IDiscriminatorConvention

The discriminator convention.

allowedTypes Func<Type, bool>

A delegate that determines what types are allowed.

ObjectSerializer(Func<Type, bool>)

Initializes a new instance of the ObjectSerializer class.

public ObjectSerializer(Func<Type, bool> allowedTypes)

Parameters

allowedTypes Func<Type, bool>

A delegate that determines what types are allowed.

Properties

AllAllowedTypes

An allowed types function that returns true for all types.

public static Func<Type, bool> AllAllowedTypes { get; }

Property Value

Func<Type, bool>

AllowedDeserializationTypes

Gets the AllowedDeserializationTypes filter;

public Func<Type, bool> AllowedDeserializationTypes { get; }

Property Value

Func<Type, bool>

AllowedSerializationTypes

Gets the AllowedSerializationTypes filter;

public Func<Type, bool> AllowedSerializationTypes { get; }

Property Value

Func<Type, bool>

DefaultAllowedTypes

An allowed types function that returns true for framework types known to be safe.

public static Func<Type, bool> DefaultAllowedTypes { get; }

Property Value

Func<Type, bool>

DiscriminatorConvention

Gets the discriminator convention.

public IDiscriminatorConvention DiscriminatorConvention { get; }

Property Value

IDiscriminatorConvention

GuidRepresentation

Gets the GuidRepresentation.

public GuidRepresentation GuidRepresentation { get; }

Property Value

GuidRepresentation

Instance

Gets the standard instance.

public static ObjectSerializer Instance { get; }

Property Value

ObjectSerializer

NoAllowedTypes

An allowed types function that returns false for all types.

public static Func<Type, bool> NoAllowedTypes { get; }

Property Value

Func<Type, bool>

Methods

Deserialize(BsonDeserializationContext, BsonDeserializationArgs)

Deserializes a value.

public override object Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)

Parameters

context BsonDeserializationContext

The deserialization context.

args BsonDeserializationArgs

The deserialization args.

Returns

object

A deserialized value.

Equals(object)

public override bool Equals(object obj)

Parameters

obj object

Returns

bool

GetHashCode()

public override int GetHashCode()

Returns

int

Serialize(BsonSerializationContext, BsonSerializationArgs, object)

Serializes a value.

public override void Serialize(BsonSerializationContext context, BsonSerializationArgs args, object value)

Parameters

context BsonSerializationContext

The serialization context.

args BsonSerializationArgs

The serialization args.

value object

The object.

WithDiscriminatorConvention(IDiscriminatorConvention)

Returns a new ObjectSerializer configured the same but with the specified discriminator convention.

public ObjectSerializer WithDiscriminatorConvention(IDiscriminatorConvention discriminatorConvention)

Parameters

discriminatorConvention IDiscriminatorConvention

The discriminator convention.

Returns

ObjectSerializer

An ObjectSerializer with the specified discriminator convention.