Code Issues of the dead code type for qualifiers
Here are some of the code issues of the dead code type that indicate redundant ‘this’ (‘Me’ in VB), ‘base’ (‘MyBase’ in VB) and type qualifiers.
Redundant base qualifier
Cause:
The only time the base qualifier should be used is when you have an overridden member with the same name in the derived class, but you actually want to call the member in the base class. A keyword like ‘base’ does not make the code readable and should be avoided in all cases unless they are indeed necessary.
Sample:
How to fix:
- Apply the Remove Redundant Qualifier code fix:
Redundant this qualifier
Cause:
The ‘this’ keyword refers to the current instance of the class. The keyword is most of the time technically redundant, because a member is unique in most scenarios. However, there are situations where you must use the ‘this’ keyword, for example to prevent an ambiguity between a member and a function parameter that has the same name as a member. Another important thing to consider is that the ‘this’ keyword is removed by the compiler. So, it is actually down to a personal preference or the coding standard in your team.
Sample:
How to fix:
- Apply the Remove Redundant Qualifier code fix:
Redundant type qualifier
Cause:
Namespaces qualifiers prevent conflicts between the names of classes by isolating the contents of each namespace. A full namespace name qualifier is not required for a class when a corresponding using (or Imports in VB) statement is declared. You can safely remove the namespace qualifier to improve code readability.
Sample:
How to fix:
- Apply the Remove Type Qualifier or Remove Type Qualifier (remove all) code fixes:
Can remove type qualifier
Cause:
This code issue is similar to the ‘Redundant type qualifier‘ code issue. The difference is that this one is shown even when no using statement is declared to the namespace qualifier. Removing a namespace qualifier may increase code readability.
Note that the code issue is not shown if the new using statement with the namespace qualifier will lead to the types ambiguity error.
Sample:
How to fix:
- Apply the Remove Type Qualifier or Remove Type Qualifier (remove all) code fixes: