MongoDB.Bson.Serialization.Serializers.InterfaceSerializer.Serialize C# (CSharp) Метод

Serialize() публичный Метод

Serializes a document to a BsonWriter.
public Serialize ( BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options ) : void
bsonWriter MongoDB.Bson.IO.BsonWriter The BsonWriter.
nominalType System.Type The nominal type.
value object The document.
options IBsonSerializationOptions The serialization options.
Результат void
        public override void Serialize(
            BsonWriter bsonWriter,
            Type nominalType,
            object value,
            IBsonSerializationOptions options)
        {
            if (!nominalType.IsInterface)
            {
                var message = string.Format("Nominal type must be an interface, not {0}.", nominalType.FullName);
                throw new ArgumentException(message, "nominalType");
            }

            if (value == null)
            {
                bsonWriter.WriteNull();
            }
            else
            {
                var actualType = value.GetType();
                var serializer = BsonSerializer.LookupSerializer(actualType);
                serializer.Serialize(bsonWriter, nominalType, value, options);
            }
        }
    }