I have this code snippet that I want to simplify:
switch (typeString)
{
case "boolean":
CreateSimpleRows<bool>(ref group, value);
break;
case "datetime":
CreateSimpleRows<DateTime>(ref group, value);
break;
case "double":
CreateSimpleRows<double>(ref group, value);
break;
case "int32":
CreateSimpleRows<int>(ref group, value);
break;
case "int64":
CreateSimpleRows<long>(ref group, value);
break;
case "string":
CreateSimpleRows<string>(ref group, value);
break;
}
The method is declared as CreateSimpleRows<T>
. I tried passing a System.Type instance, but that didn't work.
I came across this answer to a similar question: Pass An Instantiated System.Type as a Type Parameter for a Generic Class
I've checked and I've seen that there's a MakeGenericMethod in the MethodInfo class. Thing is, I don't know how to convert "CreateSimpleRows" into a MethodInfo instance.
Is what I'm thinking of achieving even possible? Thanks in advance for the replies.