Home > Code Analysis > Code Issues of the dead code type for qualifiers

Code Issues of the dead code type for qualifiers

September 14th, 2012

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:

CodeRush Redundant base qualifier

How to fix:

  • Apply the Remove Redundant Qualifier code fix:

CodeRush Redundant base qualifier result

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:

CodeRush Redundant this qualifier

How to fix:

  • Apply the Remove Redundant Qualifier code fix:

CodeRush Redundant this qualifier result

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:

CodeRush Redundant type qualifier

How to fix:

  • Apply the Remove Type Qualifier or Remove Type Qualifier (remove all) code fixes:

CodeRush Redundant type qualifier result

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:

CodeRush Can remove type qualifier

How to fix:

  • Apply the Remove Type Qualifier or Remove Type Qualifier (remove all) code fixes:

CodeRush Can remove type qualifier result

—–
Products: CodeRush Pro
Versions: 12.1 and up
VS IDEs: 2008 and up
Updated: Sep/04/2012
ID: C186

Similar Posts: