Home > Refactorings > Refactorings – Use Implicit Line Continuation

Refactorings – Use Implicit Line Continuation

June 30th, 2011

The Use Implicit Line Continuation is a Visual Basic language specific refactoring available in Visual Studio 2010 that removes redundant line-continuation underscore characters from an entire source file.

Visual Basic language version 10 has been improved in the area of line-continuation characters. Now, there are a lot of places in the code where an underscore is not necessary anymore, which means that Visual Basic is smarter about auto-detecting line continuation scenarios, and as a result, no longer expect you to explicitly indicate that the statement continues on the next code line. For example, the underscore is no longer necessary in the following cases:

  • After the following punctuators: comma ‘,’, open parenthesis ‘(‘, open curly brace ‘{‘, begin embedded expression in XML ‘<%=’.
  • Before the following punctuators: close parenthesis ‘)’, close curly brace ‘}’, end embedded expression in XML ‘%>’.
  • After an open angle bracket ‘<‘ in an attribute context, before a close angle bracket ‘>’ in an attribute context, and after a close angle bracket in a non-file-level attribute context.
  • After binary operators in expression contexts.
  • Before and after query expression operators.
  • and others.

Consider the following code:

Refactor! Use Implicit Line Continuation refactoring sample code

To apply the refactoring move the editor caret to one of the underscore characters in the code. Before applying the Use Implicit Continuation refactoring, you can see the preview hint:

Refactor! Use Implicit Line Continuation refactoring preview

Once the refactoring is applied you will get the following result:

Refactor! Use Implicit Line Continuation refactoring result

Note that a few underscores are left after the refactoring is performed, because they are actually needed in the code. If you remove them, the code is no longer compilable.

—–
Products: Refactor! Pro
Versions: 11.1 and up
VS IDEs: any
Updated: Jun/30/2011
ID: R031

Similar Posts: