I have a block of code like this: (MyClassX is just a shorthand for my business objects, which might extend later ...
var conn = new SQLiteAsyncConnection(dbPath);
conn.CreateTableAsync<MyClass1>().Wait();
conn.CreateTableAsync<MyClass2>().Wait();
conn.CreateTableAsync<MyClass3>().Wait();
conn.CreateTableAsync<MyClass4>().Wait();
conn.CreateTableAsync<MyClass5>().Wait();
...
conn.CreateTableAsync<MyClass20>().Wait();
And would like to somehow refactor it to avoid the repetitiveness and make it more maintainable. One try was something akin to
// Generic Lambda invocation
Action<Type> init_bo = t => conn.GetType().GetMethod("CreateTableAsync")
.MakeGenericMethod(t).Invoke(conn, null);
List<Type> bo_types = new List<Type>() { typeof(MyClass1), typeof(MyClass2),
..., typeof(MyClass20) };
bo_types.ForEach(init_bo);
, which seems not terribly expressive (and does not call Wait()). How could I go about utilizing templates/functional programming to get more expressive and concise code?
Edit: Not a duplicate in my opinion, since I already answered how to call a generic method in the original question, but I was not happy with the resulting code w.r.t. expressiveness.