I believe if you change your List<ReportA> (inside of GetReports()) to
type List<Report> it might work...

Brandon

Ron Young wrote:
Is the following possible? The compiler tells me no:

class Report
{
}

class ReportA : Report
{
     public string MyName = "ReportA";
}

class ReportProvider
{
     public List<Report> GetReports()
     {
            List<ReportA> reports = new List<ReportA>();
            reports.Add(new Report());
            return reports;
     }
}

I'd like to have that single method in ReportProvider, and hopefully a 
jumptable to return different types of reports:

class ReportProvider
{
       Dictionary<Type, Func<Criteria, List<Report>>> _mappings = new ...

       public ReportProvider()
       {
               _mappings.Add(typeof(BillableHoursReport, 
GetBillableHoursReport));
               _mappings.Add(typeof(DetailByDateReport, GetDetailByDateReport));
       }

       public IList<T> GetReport<T>(Criteria criteria) where T: Report
       {
               Type t = typeof(T);
               return _mappings[t].Invoke(criteria);
       }
       private IList<DetailByDateReport> GetDetailByDateReport(Criteria 
criteria)
       {
               List<DetailByDateReport> results = new ...
               // do stuff
               return results;
       }

       // other get report methods that return derived Report types
}

Thanks

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to