Coding with Snippets

Another feature that can come in handy is the C#Builder Snippets window. Snippets are blocks of reusable code you can copy and paste into your source code. In addition to using presupplied snippets, you can add new snippets and categorize them as desired.

Snippets appear in the Tool Palette when you are using the C# source code editor. Chapter 1 already described how to add and remove categories and the shortcut filters, so this section only discusses using snippets themselves.

Using a snippet is easy. Just select the snippet needed and drag and drop it into the code editor where it should go. It will format automatically and just needs to be customized.

It is also possible to add custom snippets to an existing or new category. For practice, open a C# source code file in C#Builder and type the following using statement:

 using() { } 

Select the using statement, press and hold down the Alt key, and drag the selected text into the Snippets window. When snippets are in the Tool Palette, they may be dragged and dropped to other locations or categories as desired. Remember from Chapter 1 that right-clicking on the Tool Palette toolbar and selecting Add New Category will add a new Snippets category just for your code. A new snippet cannot be moved from the editor into any category other than the Code Snippets category. Even if you try to add a new snippet from the code editor into a custom category, the snippet will always land in the Code Snippets category. To get a snippet into a custom category, create the new category if it doesn't exist, add the new snippet to the Code Snippets category, and then do a drag-and-drop (no special keys) from the Code Snippets category to the new category. Figure 2.2 shows the Snippets window with the new snippet in a new category.

Figure 2.2. The Snippets window.

graphics/02fig02.jpg



C# Builder KickStart
C# Builder KickStart
ISBN: 672325896
EAN: N/A
Year: 2003
Pages: 165

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net