I am using the CreateTable method in SQLite-Net, which takes a type argument to specify what kind of table is being created. For example:
database.CreateTable<Client>();
Where client is defined as:
[Table("Client")]
public class Client
{
[PrimaryKey]
public int ClientID { get; set; }
public string Name { get; set; }
public string Type { get; set; }
}
Would create a table with the schema defined in the client class, so having ClientID, Name, and Type columns.
I would like to use a string array, holding the names of the tables I want to create, to run CreateTable on all of the classes named in the array. However I'm unsure on how to use a string as a type parameter in a generic method.
It would look something like this:
string[] tables = new string[]{"Class1","Class2"};
for(int i = 0; i < tables.Length; i++){
database.CreateTable<tables[i]>();
}
Which would do the same thing as this:
database.CreateTable<Class1>():
database.CreateTable<Class2>();
I've already tried to do it like this:
Type tabletype = Type.GetType("Client");
database.CreateTable<tabletype>();
But I get an error which says "The type or namespace name 'tabletype' could not be found". All the tables are defined as classes in the same namespace.
Thanks.