Estou tentando usar o código abaixo para converter mas ele dá erro em todo lugar que tem o T
e where
. O que poderia ser?
// function that set the given object from the given data row
public static void SetItemFromRow(T item, DataRow row)
where T : new()
{
// go through each column
foreach (DataColumn c in row.Table.Columns)
{
// find the property for the column
PropertyInfo p = item.GetType().GetProperty(c.ColumnName);
// if exists, set the value
if (p != null && row[c] != DBNull.Value)
{
p.SetValue(item, row[c], null);
}
}
}
// function that creates an object from the given data row
public static T CreateItemFromRow(DataRow row)
where T : new()
{
// create a new object
T item = new T();
// set the item
SetItemFromRow(item, row);
// return
return item;
}
// function that creates a list of an object from the given data table
public static List CreateListFromTable(DataTable tbl)
where T : new()
{
// define return list
List lst = new List();
// go through each row
foreach (DataRow r in tbl.Rows)
{
// add to the list
lst.Add(CreateItemFromRow(r));
}
// return the list
return lst;
}