/// <summary>
        /// Maps a BSON document to a resource type
        /// </summary>
        /// <param name="doc"></param>
        /// <returns></returns>
        private dynamic MapResource(BsonDocument doc)
        {
            var jObj = JObject.Parse(JsonSerializer.Serialize(doc));

            jObj.Remove("_id");
            return(JsonConvert.DeserializeObject <ExpandoObject>(jObj.ToString()));
        }
        /// <summary>
        /// Maps a BSON document to a resource type
        /// </summary>
        /// <param name="resource"></param>
        /// <returns></returns>
        private BsonDocument MapDocument(dynamic resource)
        {
            dynamic jObj = JObject.Parse(JsonConvert.SerializeObject(resource));

            jObj._id = resource.Id;
            return(JsonSerializer.Deserialize(jObj.ToString()));
        }
Esempio n. 3
0
        public void BsonToJsonTest()
        {
            var property = new Property {
                Value = "Test"
            };
            var settings = new Settings(Guid.NewGuid());

            settings.Add(Guid.NewGuid(), property);

            var document = BsonMapper.Global.ToDocument(settings);
            var json     = JsonSerializer.Serialize(document);

            var restored = JsonConvert.DeserializeObject <Settings>(json);
        }