How would I pass parameters to a parent class when creating an assembly reference of a child class?

Viewed 376

I have autism so I'm sorry if this question is dumb or if you struggle to understand what I'm trying to say. I'm also bad at explaining things, but here it goes:

Structure of my code that is relevant to my problem for context:

    //Debug startup class
    //Live startup class

    //abstract ProjectBaseClass
    //abstract TemplateBaseClass : abstract ProjectBaseClass
    //abstract TemplateHandlerClass : abstract TemplateBaseClass 
    //TemplateClass : abstract TemplateHandlerClass 

The project I'm working on has 200+ templates created already, and I've run into a dilemma. I need to pass a parameter to ProjectBaseClass, but I would prefer not to update the 200 templates to do this, and this parameter needs to be passed on creation of TemplateClass.

TemplateClass is created using Assembly, this happens in Debug like this

var templateName = "NameOfTemplate";
var assembly = typeof(TemplateBaseClass).Assembly;
var classes = assembly.GetTypes().ToList();
var templateType = classes.Single(Object => Object.Name.Equals(templateName));
var template = (TemplateBase)Activator.CreateInstance(templateType);

So, how would I pass a parameter down to the ProjectBaseClass constructor from Activator.CreateInstance(templateType) without messing with any of the TemplateClass constructors?

If this is a bad question, just let me know and I'll delete it :)

0 Answers
Related