Indeed it does. Thank you. I was under the impression that if the method that returned derived reports ultimately returned a list of the base report, then the client would get the properties defined in the base report.
But it's up to the client to determine what types of reports are in the list, so this works: // client-side List<Report> reports = provider.GetReports(); foreach (ReportA item in reports) WL(item.MyName); Thanks again. ________________________________________ From: Discussion of advanced .NET topics. [EMAIL PROTECTED] On Behalf Of Brandon Willoughby [EMAIL PROTECTED] Sent: Friday, December 14, 2007 12:44 PM To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM Subject: Re: [ADVANCED-DOTNET] Method that returns List<BaseClass> 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 =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com