Listar <T> a la Lista <objeto>
Tengo una función donde cualquier tipo delist<>
se puede pasar a. La función entoncesdetermines que escriben la lista es. Mi problema es que estoy pasando una lista y luego la convierto, pero luego cuandoasignar mi lista a la lista aprobada Me sale un error:
Cannot convert type 'System.Collection.Generic.List<ADMPortal_2.Modles.ProductionPending>' to 'System.Collections.List<T>
CÓDIG
lamada @Database que devuelve los resultados en una tabla de datos que luego se convertirá a su tipo de lista. Esta función debe poder devolver cualquier tipo de lista, p. Lista, Lista, etc.
string cnnStr = ConfigurationManager.ConnectionStrings["conChdbd1"].ConnectionString;
OracleConnection cnn;
OracleDataReader dr;
public List<T> Execute<T>(string strSql, List<T> list)
{
using (OracleConnection conn = new OracleConnection(cnnStr))
{
using (OracleCommand objCommand = new OracleCommand(strSql, conn))
{
objCommand.CommandType = CommandType.Text;
DataTable dt = new DataTable();
OracleDataAdapter adp = new OracleDataAdapter(objCommand);
conn.Open();
adp.Fill(dt);
if (dt != null)
{
list = ConvertToList(dt, list).ToList();
}
}
}
return list;
}
Aquí el error ocurre cuandoasignación a la lista
public List<T> ConvertToList<T>(DataTable dt, List<T> list)
{
if (list.GetType() == typeof(List<ProductionPending>))
{
list = ConvertToProductionPending(dt, (list as List<ProductionPending>));
}
else if (list.GetType() == typeof(List<ProductionRecent>))
{
list = ConvertToProductionRecent(dt, (list as List<ProductionRecent>));
}
else if (list.GetType() == typeof(List<MirrorDeployments>))
{
list = ConvertToMirror(dt, (list as List<MirrorDeployments>));
}
return list;
}
Aquí las funciones de conversión
private List<ProductionPending> ConvertToProductionPending(DataTable dt, List<ProductionPending> list)
{
// Convert here
return list;
}
private List<ProductionRecent> ConvertToProductionRecent(DataTable dt, List<ProductionRecent> list)
{
// Convert here
return list;
}
private List<MirrorDeployments> ConvertToMirror(DataTable dt, List<MirrorDeployments> list)
{
// Convert here
return list;
}