I’m trying to dynamically generate reports and email them to the appropriate users is this possible or can does the compiler need the type before runtime.
static void Main(string[] args) {
ArrayList ReportsTypes = new ArrayList();
ReportsTypes.Add(typeof(AgentPPL));
foreach(Type t in ReportsTypes) {
InitilizeReports<t>(); // <- Error
}
}
static void InitilizeReports<T>() where T : new() {
T r = new T();
IReportDocument rd = (IReportDocument)r;
rd.DocumentName = "SomeReport";
ExportReport(rd);
}
What I’d really like to do is grab a string out of the database and convert the string to a type but I doubt thats possible but what about creating an array of types like in my example what am doing wrong here. Any help is much appreciated I’ve been spinning my wheels for a while just to get my templates working.
You could modify the code just a bit and use reflection instead: