KnowDotNet Visual Organizer

NET Refactor - Smart Commenter

Solve Your Comment Maintenance Problem

Smart Commenting is a new concept in composing and maintaining comments in your code. It's one thing to write correct comments when you are creating a new method, but it's something else again to try to keep those comments updated as you change the code that the comments describe. One of the most frustrating things about updating comments is that they are formatted manually, with no ability to make changes to them without having to reformat two or more lines, especially if you wish to keep some simblance of uniformity in the comment block.

That's the problem that NET Refactors Smart Commenting feature attacks. With this feature, you can create the comments initially by using the Smart Commenter and from then on, you will have no problem in capturing those comments in a word wrapping dialog. Having the ability to do this, makes the job of editing the block of comments a piece of cake!

The Smart Commenter dialog is shown in Figure 1.

Figure 1 - Smart Commenter Dialog

Smart Commenter Dialog



The code block shown in Figure 1 is obviously from a VB.NETcode window, but the Smart Commenter recognizes C# Block Comments and C# single line commnts. One of the nice things about this feature, is that you do not have to select the code to be processed (although you can), just place the cursor anywhere in the comment block and select the Smart Commenter menu option. Smart Commenter will capture the comment block, regardless of whether it is in VB.NET, or C#, and if C#, it can handle a block of comments that is blocked (/*..*/) or a block of single line comments (//).

As mentioned previously, the best case scenario is to create your comment block in the dialog to start with. When you save the comments, two unique characters precede each line of comment to tell the dialog, for future editing, whether or not a line is wrapped. The special characters are meant to be unobtrusive and a quick glance at the comment block, you might not even notice the subtle difference between a line that will wrap and one that won't wrap when reloaded into the dialog.

These two special characters follow the comment character for respective language, VB or C#. They are:

~ = This line will wrap to the next line.
- = This line will be terminated by a hard return and will not wrap to the next line.

The characters appear to be much more different in this help file than they do in the Visual Studio .NET IDE.  An example of a block of comments in VB.NET might look as follows:


'~ This will be a long line of comment, so we want it to wrap
'~ to the next line. This will continue the thought so that this
'- line will wrap also. The next line will end the wrapping.
'- 1) Numbered line will not wrap..
'- 2) Second Numbered Line..
'~ This line will wrap to the next line, as it again is a longer.
'- line. You get the picuture..


If the comments were not originally created in the Smart Commenter dialog, there is logic built into to attempt to determine if the lines should wrap or not. The algorithm for this is a best guess algorithm, considering line length, lines beginning with indentation, numbers, etc.

IntelliWrap only has to do with comment blocks that were not originally created with Smart Commenter.

You can turn the "IntelliWrap" feature on or off by clicking the checkbox on the dialog. If you make changes to the code in the box, the checkbox will be disabled. You can also force wrapping of the whole selection by clicking the Wrap This Block checkbox. Once you make any changes to the text, both of the checkboxes will be disabled. While the checkboxes are enabled, checking and unchecking either toggles the state of the text in the edit window. The state of the IntelliWrap checkbox will be treated as a preference and saved for future use.

The Up/Down control allows you to scroll the comments and see how they will actually wrap, so that WYSIWYG!  This allows you to build your comments with indentations for numbered lists and indentations.  With the UpDown control, you can see the block as it will be stored in your code window.

Try NET Refactor Free for 15 days or purchase now by clicking Download or Purchase.

Top of Page

Writing Add-Ins for Visual Studio .NET
Writing Add-ins for Visual Studio .NET
by Les Smith
Apress Publishing