Code fixes for code issues for switch (select) statements
You might have already learned that CodeRush suggests several code issues that highlight the switch (Select in VB) statement with hints and warnings when it has suspicious code. For example, when the switch statement handles only a subset of the possible enumeration values it is checking for, this may be a sign of incomplete code.
Until recently, there were no code fixes of those code issues. Now, they appear:
- Add Missing Case Statements – adds all missing case statements to the switch statement.
- Add Default Case Branch – adds the default case branch to the switch statement.
Consider the following code:
The DayOfWeek enumeration contain seven enumeration elements for each day of a week. In the code above one of the days is missing (Wednesday). The expression of the switch statement is highlighted with a code issue of the suggestion type, and the following hint appears if you hover over it:
There are two code issues listed in the hint and both have the corresponding fixes which can be seen in the preview hint before applying:
Add Missing Case Statements
Add Default Case Branch
NOTE: please take into account the “Versions” field at the bottom of the post, to determine the build number for which the content is applied. Click here to see the latest officially released version.—– Products: CodeRush Pro Versions: 12.1 and up VS IDEs: 2008 and up Updated: Apr/23/2012 ID: U013