public static T ConvertBsonToObject <T>(this BsonDocument input)
 {
     try
     {
         var type = input.GetTypeFromBson();
         if (type != null)
         {
             return((T)input.ConvertBsonToObject(type));
         }
         var valueType = typeof(T);
         if (valueType.IsInterface || valueType.IsAbstract)
         {
             return(default(T));
         }
         return(BsonSerializer.Deserialize <T>(input));
     }
     catch { return(default(T)); }
 }
 public object Find(string key, string entityName, string fullName, out MethodResponse response)
 {
     response = new MethodResponse();
     try
     {
         var          collection = db.GetCollection <BsonDocument>(entityName);
         BsonDocument obj        = null;
         obj = collection.Find(new { _id = key }.ToBsonDocument()).FirstOrDefault();
         if (obj == null)
         {
             response.Success = false;
             return(null);
         }
         var returnObj = obj.ConvertBsonToObject();
         response.Success = returnObj != null;
         return(returnObj);
     }
     catch (Exception ex)
     {
         response.ResponseMessage = ex.Message;
         response.ResponseObject  = ex;
         return(null);
     }
 }
 private T BsonConvertTo <T>(BsonDocument bson)
 {
     return(bson.ConvertBsonToObject <T>());
 }