I have a C# solution that reads records from a db and processes them into another db. The records to be processed are essentially one long string that represents the data and then another string "code" that determines how that big data string should be parsed. There are dozens and dozens of different kinds of records; I have them represented as distinct concrete classes that all inherit from an abstract class.
I can generate the code to make classes for the different records easily enough. However, is there a better (i.e. less verbose, more dynamic) way to map the "code" to the class that represents it? Right now I'm just using a huge switch, something like:
BaseRecord record;
switch(code) {
case "A":
record = new A(stringData);
case "B":
record = new B(stringData);
.
.
.
case "Z":
record = new Z(stringData);
where A, B, ..., Z all derive from BaseRecord.
Other than reflection, I can't think of a way to map string representations of class names to the classes they represent.
Other than reflection...
: are you trying to avoid using introspection, and if so, why?switch
and reflection were the only two I could come up with.