예제 #1
0
        public static BsonDocument Build(object o)
        {
            BsonDocument document = BSONBuilder.Build(o);

            HandlePersistentChildCollections(o, document);
            return(document);
        }
예제 #2
0
        private static void HandlePersistentChildCollections(object parentObject, BsonDocument parentDocument)
        {
            Type parentType = parentObject.GetType();
            List <PropertyInfo> childCollectionProperties = parentType.GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(PersistentCollection))).ToList();

            foreach (PropertyInfo propertyInfo in childCollectionProperties)
            {
                IList     childObjectCollection = (IList)propertyInfo.GetValue(parentObject, null);
                BsonArray array = new BsonArray();

                for (int i = 0; i < childObjectCollection.Count; i++)
                {
                    object       childObject   = childObjectCollection[i];
                    BsonDocument childDocument = BSONBuilder.Build(childObject);
                    array.Add(childDocument);

                    HandlePersistentChildCollections(childObject, childDocument);
                }

                parentDocument.Add(propertyInfo.Name, array);
            }
        }