Is it possible to retrieve programmatically all the case of a switch ? I don’t have any idea, maybe by IL but not sure how to do …
In fact my global issue is the following : I got a siwtch case with string as property name. The method is very important and a regression is not allowed. I don’t want a refactoring breaking this, so I want a method to test that all case string are in fact real properties of my objects. (NB : the default value return something so I can’t throw an exceptino for a refactored invalid value).
There are ways to avoid using property names as string directly in your code. I’ve posted a code snippet here.
Then, instead of using a switch statement, implement something like this:
When you call both methods, be sure that you use the Member class of the code snippet (see link) instead of using the property names directly. So you can make sure, that your code is refactoring-proof, because it does not contain any “magic strings”.
Best Regards