C# MongoDB complex class serialization

后端 未结 3 1718
鱼传尺愫
鱼传尺愫 2020-12-30 15:45

I\'m working with C# MongoDB driver and I have this rather complex JSON struct to save:

{
    \"name\" : \"value\",
    \"age\": 1,
    \"isFemale\": true,
          


        
3条回答
  •  -上瘾入骨i
    2020-12-30 16:19

    Try to read the documentation more carefully, within the Serializer Registry section (http://mongodb.github.io/mongo-csharp-driver/2.4/reference/bson/serialization/#serializer-registry):

    The serializer registry contains all the IBsonSerializers that have been registered. It can be accessed via the SerializerRegistry property of the static class BsonSerializer.

    To register a serializer use either

    BsonSerializer.RegisterSerializer(Type, IBsonSerializer)    
    

    or

    BsonSerializer.RegisterSerializer(IBsonSerializer)
    

    This will add them to

    BsonSerializer.SerializerRegistry
    

    Checkout the APIs for these classes here - http://mongodb.github.io/mongo-csharp-driver/2.4/apidocs/html/T_MongoDB_Bson_Serialization_BsonSerializer.htm

提交回复
热议问题