0

Hi All,
I have a factory which has some concrete sub classes for generating reports (.txt, .csv,.xls) I want to make the interface of the concrete classes to be generic so that i can pass in diff types of parameters (Instead of DataTable i need to use DataSet or some other class instance as argument). Here is my previous interface.

  interface IReportCreator
  {
        bool Create(DataTable dt);
  }

I made the interface as generic..like the one below

interface IReportCreator<T>
{
    bool Create(T args);
}

Now my question is how can i return the generic interface from the Factory My previous factory code
My previous factory code is like the one below..

class Factory
{
    static IReportCreator  GetReportCreator(string type)
    {
        IReportCreator reportCreator = null;
        if(type == "txt")
            reportCreator = new TextCreator(); 

        if(type == "csv")
            reportCreator = new CSVCreator();

        return reportCreator;
    } 
}

And in the cient.. i call like this

IReportCreator repCreator = Factory.GetReportCreator("txt"); 
repCreator.Create(// the argument);

I want to make the factory as a generic one.. Pls help me to solve this

Any help will be appreciated greatly
Thanks

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Momerath
0

Not sure what you are asking, but to make a generic, you need a generic type indicator

class Factory<T> {
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.