In C# is it possible, without reflection, to instantiate all class found in a namespace?
I have a list of script class. All in same folder. All implementing my base class BaseScript
. I need to run all of them every hours. I already have the time and events. I also already have a List<BaseScript> ListOfScripts
. But now I'm doing this:
public class Program
{
private static List<BaseScript> ListOfScrpits { get; set; }
static void Main(string[] args)
{
ListOfScrpits = new List<BaseScript>
{
new DoThis(),
new DoThat(),
new DoSomethingElse()
};
Timer timer = new Timer();
timer.Interval = 600000; // 10 * 60 seconds
timer.Elapsed += new ElapsedEventHandler(OnTimer);
timer.Start();
}
private static void OnTimer(object sender, ElapsedEventArgs e)
{
// TODO
}
}
Can I create my list of scripts dynamically?