One of the problems in your code I mentioned can be easily resolved and save a lot of time and enable some maintainability of the application, which is now pretty much killed. I mean repeated code "
", etc. Instead, simply define an array of case. What you do also provokes you to write long
statement, which is always hard to support. Instead, you should have a dictionary of keys: index type is the key codes or a character, value types is whatever is associated with the key; some class or structure.
A very universal extension of this idea is shown in my CodeProject article: Dynamic Method Dispatcher
]. (Full name "Dynamic Method Dispatcher", No more long switch statements!
; the "short description" part of the title now disappeared from the article pages; I'll have to ask to restore it, because lack of it may mangle the meaning of the title.)
This approach is very easy to use and completely eliminate a need of long
statements. The key can be anything, even a type. And a value can be anything, including, most importantly, a delegate instance. This delegate instance provides the most of flexibility: it replaced any arbitrary block of code in switch case
statement. Indeed, no more long switch statements!
Please understand that no one here tries to brain-wash you with technological stuff and force you into extra work, just the opposite, such works attempt to make your life better. We human are not designed to do a lot of boring tedious work, but most of us are pretty good with abstractions and using elegant techniques.