Link to home
Start Free TrialLog in
Avatar of FrancineTaylor
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<TImplementation>();
            ShapeRow<TInterface>(row, dataobj);
            _returnData.Add((TInterface)dataobj);
        }
    }
    return _returnData;
}

I'm getting errors on TCollection:
    "Using the generic type 'System.Collections.Generic.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?
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of FrancineTaylor
FrancineTaylor

ASKER

Perfect!  Thanks for your help, kaufmed.