I'm trying to create a layer over dapper and want to create a method that uses the QueryMultiple method. I want to map an incoming list of types in string format (determined at runtime) with the QueryMultiple's Read method. When trying to use the Read method I can't find a way to make the generic argument accept the type i'm creating.
Can anyone please help me on how to correctly provide the type?
Here's the code:
using (SqlConnection conn = GetNewConnection())
{
conn.Open();
var multi = conn.QueryMultiple(sql, param);
foreach (string typeName in ListOfTypes) //Iterate a List of types in string format.
{
Type elementType= Type.GetType(typeName);
var res= multi.Read<elementType>(); //Error: The type or namespace name 'combinedType' could not be found (are you missing a using directive or an assembly reference?)
//Add result to a dictionary
}
}