public void SerializeBson(BsonSerializingContext context)
 {
     context.BsonWriter.WriteStartDocument();
     foreach (var item in _values)
     {
         if (context.Filter.IsOk(Proxy, _typeConfig.Type, item.Key))
         {
             context.BsonWriter.WriteName(item.Key);
             _manager.SerializeBsonValue(item.Value, context);
         }
     }
     context.BsonWriter.WriteEndDocument();
 }
Ejemplo n.º 2
0
 public void SerializeBsonValue(object obj, BsonSerializingContext context)
 {
     if (obj == null)
     {
         context.BsonWriter.WriteNull();
     }
     else if (obj is IEntityHandlerProvider provider)
     {
         provider.GetHandler().SerializeBson(context);
     }
     else
     {
         var s = BsonSerializer.LookupDiscriminatorConvention(obj.GetType());
         BsonSerializer.Serialize(context.BsonWriter, obj.GetType(), obj);
     }
 }
Ejemplo n.º 3
0
        public BsonDocument SerializeBson(object obj, Filter filter)
        {
            var result = new BsonDocument();

            using (var writer = new BsonDocumentWriter(result))
            {
                var context = new BsonSerializingContext {
                    Filter = filter, BsonWriter = writer
                };
                lock (this)
                {
                    SerializeBsonValue(obj, context);
                }
            }
            return(result);
        }
Ejemplo n.º 4
0
 public void SerializeBson(BsonSerializingContext context)
 {
     context.BsonWriter.WriteStartDocument();
     foreach (var item in _inner)
     {
         if (string.IsNullOrEmpty(item.Key))
         {
             Log.Warning($"Trying to bserialize empty value for Dictionary of {_typeConfig.ValueType.Type}");
         }
         else if (context.Filter.IsOk(item.Value, _typeConfig.ValueType.Type, null))
         {
             context.BsonWriter.WriteName(item.Key);
             _manager.SerializeBsonValue(item.Value, context);
         }
     }
     context.BsonWriter.WriteEndDocument();
 }