(* Copyright (c) 2015 Max Hirschhorn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *)

namespace BsonProvider.Runtime.Serialization

open MongoDB.Bson
open MongoDB.Bson.Serialization
open MongoDB.Bson.Serialization.Serializers

open BsonProvider.Runtime

type MySerializer() =
    inherit BsonBaseSerializer()

    override __.Serialize(writer, nominalType, value, options) =
        BsonSerializer.Serialize(writer, typeof<obj>, null, options)

    override __.Deserialize(reader, nominalType, actualType, options) =
        let value = BsonSerializer.Deserialize(reader, nominalType, options)
        BsonTop.Create(value :?> BsonValue, "$") |> box

(* Copyright (c) 2015 Max Hirschhorn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *)

namespace BsonProvider.Runtime.Serialization

open MongoDB.Bson
open MongoDB.Bson.Serialization
open MongoDB.Bson.Serialization.Serializers

open BsonProvider.Runtime

type MySerializer() =
    inherit BsonBaseSerializer()

    override __.Serialize(writer, nominalType, value, options) =
        match value with
        | :? IBsonTop as top ->
            BsonSerializer.Serialize(writer, typeof<BsonValue>, top.BsonValue, options)
        | _ -> failwith "Expected an IBsonTop"

    override __.Deserialize(reader, nominalType, actualType, options) =
        let value = BsonSerializer.Deserialize(reader, nominalType, options)
        BsonTop.Create(value :?> BsonValue, "$") |> box

Use a more correct Serialize() implementation.
Use a more correct Serialize() implementation.
