how can I pass a reference to a generic method?
I have the class below.
public static class DataTableUtil
{
public static List<T> DataTableToList<T>(DataTable dt)
{
List<T> lstItems = new List<T>();
if (dt != null && dt.Rows.Count > 0)
foreach (DataRow row in dt.Rows)
lstItems.Add(ConvertDataRowToGenericType<T>(row));
else
lstItems = null;
return lstItems;
}...
I'm consuming the class this way
var lista = DataTableUtil.DataTableToList<SasRating>(retorno).AsEnumerable();
The SasRating class is a POCO class. I would like to send this parameter dynamically through a factory pattern. It is possible ? How to do this ?
Here's an example of some (invalid) code that demonstrates what I'm looking for:
var genericObj = T;
if(T is SasRating)
{
T = SasRating
}
else
{
T = SasTest;
}
var lista = DataTableUtil.DataTableToList<T>(retorno).AsEnumerable();