FrancineTaylor
asked on
Syntax for method to shape data table into collection of objects (can't get generics right)
Here's what I'm trying to accomplish:
public TCollection<TInterface> ShapeDataTable<TInterface, TImplementation, TCollection>(DataTable dataTable)
where TImplementation : TInterface
where TCollection : List
{
TCollection<TInterface> _returnData = new TCollection<TInterface>();
if (dataTable.Rows.Count > 0)
{
foreach (DataRow row in dataTable.Rows)
{
TInterface dataobj = Activator.CreateInstance<T Implementa tion>();
ShapeRow<TInterface>(row, dataobj);
_returnData.Add((TInterfac e)dataobj) ;
}
}
return _returnData;
}
I'm getting errors on TCollection:
"Using the generic type 'System.Collections.Generi c.List<T> requires 1 type arguments"
"The type parameter 'TCollection' cannot be used with type arguments
What do I need to do to get this method compiling?
public TCollection<TInterface> ShapeDataTable<TInterface,
where TImplementation : TInterface
where TCollection : List
{
TCollection<TInterface> _returnData = new TCollection<TInterface>();
if (dataTable.Rows.Count > 0)
{
foreach (DataRow row in dataTable.Rows)
{
TInterface dataobj = Activator.CreateInstance<T
ShapeRow<TInterface>(row, dataobj);
_returnData.Add((TInterfac
}
}
return _returnData;
}
I'm getting errors on TCollection:
"Using the generic type 'System.Collections.Generi
"The type parameter 'TCollection' cannot be used with type arguments
What do I need to do to get this method compiling?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER