I have an app that contains a lot of pages that need to be added to a report. The number of pages grows quickly so I want to be able to populate the report with them dynamically. The methods below return the list of pages correctly but I cant get it to add the page to the report.
I get Argument 1: cannot convert from 'System.Type' to 'Reports.Pages.PageBase' How can I correct this?
private void AddAllPages()
{
var pages = FindSubClassesOf<PageBase>();
foreach (var pg in pages)
{
Report.Pages.Add(pg);
}
}
public IEnumerable<Type> FindSubClassesOf<TBaseType>()
{
var baseType = typeof(TBaseType);
var assembly = baseType.Assembly;
return assembly.GetTypes().Where(t => t.IsSubclassOf(baseType));
}