I am fetching the SomeThingType from the db, and then want to make a call to the SomeThing<T>(T value)
. I am getting the type from the db at runtime.
I'm stuck, how can I do this?
ProductType productType = GetProductType(userId);
SomeThingType someThingType = GetSomeThingTypeFromDb(userId);
switch(productType)
{
case ProductType.ONE:
// stuck here
IThing<int> a = new SomeThing<int>(..);
IThing<string> a = new SomeThing<string>(..);
IThing<DateTime> a = new SomeThing<DateTime>(..);
break;
}
I'm stuck on how I can use the correct generic type based on a enumeration value that I retrieve at runtime from the database.
The db value maps to an enumeration that I want to use to figure out which generic type I should use, either a string, int or DateTime.
Is this something that I can solve in c#? Or is this only possible in a dynamic language?