C# Implement Generics on Export Class

Trying to create an export using Generics.  Most of it works except one piece of code.  Basically I want to pass the model to the export and perform the export in the class.  Here is what I have (error is indicated below).
private void Form1_Load(object sender, EventArgs e)
{
    SQLData<PersonModel> sqldata = new SQLData<PersonModel>();
    List<PersonModel> personModel = sqldata.SelectSPROC("Get_Persons");
    ExportPersons.PerformExport<PersonModel>();
}

Open in new window

public static class ExportPersons
{
    public static void PerformExport<T>()
    {
        ExportExcel<T> exportExcel = new ExportExcel<T>();
        exportExcel.ExportData<T>();
    }
}

Open in new window

    public class ExportExcel<T> : IExportData<T>
    {
        public void ExportData<T>()
        {
            var model = List<T>();  //HERE IS THE ERROR - 'System.Collections.Generic.List<T>' is a 'type' but is used like a 'variable'
        }
    }

Open in new window

    public interface IExportData<T>
    {
        void ExportData<T>();  //HERE - Type parameter 'T' has the same name as the type parameter for the outer type.
    }

Open in new window

LVL 2
CipherISAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
It must be

var model = new List<T>();  

Open in new window


but your use of generics looks more like you should have used normal interfaces instead.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CipherISAuthor Commented:
Normal Interfaces?  Please elaborate.  Reason I'm using generic is because I want to pass different models.
0
CipherISAuthor Commented:
That worked.  Had to make some changes to the code but it worked.  Wish I had Resharper on this computer.
0
CipherISAuthor Commented:
This was the end result.
    public class ExportExcel<T> : IExportData<T>
    {
        public void ExportData<T1>(List<T> value)
        {
            var model = new List<T>(); //WON'T NEED THIS.  I'll get it from "value"
            model = value;
        }
    }

Open in new window

0
ste5anSenior DeveloperCommented:
I have no compiler at hands right now, but this should be the outline:

public interface IModel<T> { IEnumerable<T> GetAll(); }
public interface IExportData { void ExportData(IModel<T> model); }

public class Persons: IModel<Person> {
    // ToDo: Implement GetAll().
}

public class ExportExcel: IExportData
{
    public void ExportData(IModel<T> model)
    {
        List<T> entities = model.GetAll();
    }
}

public static class ExportPersons
{
    public static void PerformExport(IModel<Person> model)
    {
        ExportExcel exportExcel = new ExportExcel();
        exportExcel.ExportData(model);
    }
}

private void Form1_Load(object sender, EventArgs e)
{
    Persons persons = new Persons();
    ExportPersons.PerformExport(persons);
}

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.