Hi,
I know it's a bit late to answer this question, but you could use reflection to construct the generic method with something similar to this:
?>(objeto.collectionName);
// get `db` type because we need the method information from the type
var dbType = db.GetType();
// get generic method `GetCollection<T>`
var genericMethod = dbType.GetMethod("GetCollection");
// construct the method using `typeO` for T like `GetCollection<typeO>`
var methodInfo = mi.MakeGenericMethod(typeO);
// prepare the `objeto` arguments
object[] args = { objeto };
// call the method using instance `db` and argument `objeto`
var collection = methodInfo.Invoke(db, args);
And then, instead of the following code
var list = (System.Collections.IList)info.GetValue(objeto, null);
foreach (var item in list)
{
PropertyInfo[] propertieS = ret.GetProperties();
foreach (var ppi in propertieS)
{
InsertMongoDb(?????)
}
}
you can use:
var list = (System.Collections.IList)info.GetValue(objeto, null);
foreach (var item in list)
InsertMongoDb(item);
Good luck and have a nice day!