I want to iterate through types in an assembly and if a type is a subclass of a specified interface, I want to create an object of the type and add it to a list like so:
var tasks = new List<IScheduledTask>();
foreach (Type t in Assembly.GetExecutingAssembly().GetTypes())
{
if (t.IsSubclassOf(typeof(IScheduledTask)))
{
tasks.Add(new t());
}
}
Obviously this above does not work. How can you achieve what I am seeking?