0

I am making a circuit diagram simulator, and I have a setup, where each component has it's own subclass of Component. I.e. LED, FixedResistor, e.t.c. When I create a new component the way I do it is by instantiating it with a string tagged in my xaml file. Currently I have a switch statement with a case for each subclass, but I want to change it to a dictionary based system.

In this there would be a dictionary relating the string to a Type, then I can get this Type as a variable. But in my model, I don't know how to then instantiate the new components as their subclass. It would have to be something like:

string tag = e.Tag
Type type = stringToTypeDictionary[tag]
type  newComponent = new type(parameters)

but of course you can't do this in c#.

Please help, thanks!

0 Answers0