KnowDotNet NetRefactor

Default Code Completion - CSharpCompleterPlus

CSharpCompleterPlus has numerous default code completion actions built into it. These default actions are described as follows.
Insertion of Braces
The following code lines will have a set of braces with a blank line between them placed after the line as soon as the Enter button is pressed. Note, that you can override any of the default code completion with insertion of a Regex Shortcut.


  • if ( .... )
  • for (int i = 0; i < 10; i++)<BR>
  • foreach(.....)
  • using(.....)
  • else if(....)
  • while(.....)
  • else
  • function definition line
  • class definition line
  • namespace definition line

An example of one of the constructs shown above after the Enter button is pressed is shown below. Note that the cursor is automaticall placed where you can begin typing code without any further manual cursor positioning.

   if(.....)
   {
     |
   }

If you enter a
if(......) {....}, then no code completion will take place. Also, there is a shortcut in the XML file that allows you to override the automatic insertion of braces after an if statement. If you type if(....)nb (nb stands for No Braces), CSharpCompleterPlus will not generate braces. There is also a override for else if(...)nb and else nb to prevent braces from being generated after these statements.

If you do not like
nb, obviously you can change that in the Shortcut Maintenance dialog. The point is that CSharpCompleterPlus does have a default action of inserting braces after these constructs, but typing two extra characters (could be change to "n" or whatever) after the ending ")" will override the brace insertion.

If you enter a
if(....) {, followed by the Enter key, a blank line, followed by a "}". This is shown in the code block below.

   if( .... )
   {
     |
   }

Property Definiton
If a line of code appears to be a property definition line, such as the following

  
public string PropertyName

A dialog will popup prompting you to confirm that the line is a property. The dialog will give you the option of cancelling code completion or creating a ReadOnly (get), WriteOnly (set), or Read and Write (get & set). The dialog will suggest the name of the private variable needed with the property. In the case of the previous example line, the suggested name will be "_PropertyName". If you choose to create a Read & Write property from the example line, the following code will be generated.

   public strng PropertyName
   {
    get{return _PropertyName;}
    set{_PropertyName = value;}
   }


do statement
When you enter a do and press Enter, CSharpCompleterPlus will insert a set of braces {..}. Again, there is a shortcut that will override the standard code completion. That shortcut will look for do exp, where exp can be any expression, such as "a < 10". In that case a code block shown below is generated. <BR>
   do
   {
     |
   } while (a<10);<BR>

switch block
If you enter switch(s) and then press Enter, the following block of code will be generated.

   switch(s)
   {
   case exp1:
    |
    break;
   default:

    break;
   }


The switch block code completion can be overridden by use of the shortcuts. In the shortcuts that ship with CSharpCompleterPlus , there are two swith shortcuts. One is for two cases and the other is for one case. When doing this, you must ensure that the shortcuts are ordered so that the switch with two cases is above the one with one case in the listview. Otherwise, the switch shortut with one case will consume the first case of a two case line and the seconde case will be ignored. That is why the order of shortcuts is so important.

try catch code completion

CSharpCompleterPlus has default code completion for a try block. If you simply type try plus the Enter key, the following block of code will be generated.

try
{
|
}
catch(System.Exception ex)
{

}

You can overide this default code completion by writing a Shortcut, but it will be easier, once you get used to using them, to use the built in Shortcuts,
tc,, tcf, and tf.


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