private void Serialize(BsonSerializationContext context, BsonSerializationArgs args, TClass value)
        {
            CheckItemMap();
            var writer = context.Writer;
            var list   = value as IEnumerable;

            if (list == null)
            {
                writer.WriteNull();
            }
            else
            {
                writer.WriteStartArray();
                foreach (var i in list)
                {
                    if (i == null)
                    {
                        BsonSerializer.Serialize(writer, (object)null);
                    }
                    else
                    {
                        var mref = new MongoDBRef(ClassMappingExtensions.GetCollectionForType(itemType), BsonValue.Create(itemIdMap.Getter.Invoke(i)));
                        BsonSerializer.Serialize(writer, mref);
                    }
                }
                writer.WriteEndArray();
            }
        }
Example #2
0
        private void Serialize(BsonSerializationContext context, BsonSerializationArgs args, TClass value)
        {
            CheckItemMap();

            if (value == null)
            {
                this.dbRef.Serialize(context, args, null);
            }
            else
            {
                var idref = new MongoDBRef(ClassMappingExtensions.GetCollectionForType(itemType), BsonValue.Create(itemIdMap.Getter.Invoke(value)));

                this.dbRef.Serialize(context, args, idref);
            }
        }