Current Position : HOME > Gynopathy > Visual Studio Tip: Creating Your Own Code Snippets
Visual Studio Tip: Creating Your Own Code Snippets
POST:2008-09-12 19:14:07
I recently blogged about using code snippets as a shortcut to writing more code in less time. In this post, I'm going to walk you through the steps to create custom snippets that you can install into Visual Studio for use in your own projects To get started, let's take a look at the anatomy of a snippet. A snippet is nothing more than an XML file, with a .snippet extension, containing configuration settings. If you open up the file foreach.snippet (located in "\VC#\Snippets\1033\Visual C#") you'll find the following XML, which defines the foreach snippet: As you can see, the XML used to define the snippet is fairly straight-forward. I'll go over it section by section and explain how each setting is used. Anatomy of a Code Snippet After the XML declaration element, a element acts as the root element and contains all the code snippet definitions in the file. While there can certainly be more than one snippet per file, it is usually considered good practice to only define one snippet per file. The parent element also contains a namespace definition, http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet, which is required if you want Visual Studio intellisense when designing your own code snippets. Inside the element, each snippet is defined by its own element. This element contains a Format attribute, which is used to define the version of snippet. While the version of the snippet is up to the developer, the Format attribute is required. Each element contains two inner elements, and . The element contains all of the snippet's details, such as title, description, author, etc. The element contains the literal, references, and code definitions. The element contains any or all of the following elements: : Contains the title of the snippet. This element is required. : The shortcut by which the snippet can be inserted in Visual Studio. This shortcut appears in Visual Studio's intellisense. This element is not required, but the code snippet will not appear in intellisense if it is not defined. : A brief description of the snippet's purpose. : The author of the code snippet. : Contains a collection of elements, each of which describes how the snippet is inserted into the code. A element is not required, and leaving it out will cause Visual Studio to insert the code snippet wherever the cursor is. When used, this element can have the following values: Expansion: Allows the code snippet to be inserted at the cursor. SurroundsWith: Allows the code snippet to be placed around a selected piece of code. Refactoring: This SnippetType specifies that the code snippet is used during refactoring. However, it cannot be used in custom code snippets. : Contains a list of elements, each of which represent a standard way for online content providers to add custom keywords for searching and categorization. : A URL that provides information about the snippet. The element contains any or all of the following elements: : Specifies the parameterized code template that you want to insert into your source file. This element is required, and can contain the following attributes: Language: Specifies the language of the snippet. This attribute is required and can have the following values: VB, CSharp, or XML. Delimiter: Specifies the delimiter used to describe literals and objects in code. By default, the delimiter is $. As you will see, when defining a element in the block, it will search through all code in the element and replace anything containing the literal's id, surrounded by the delimiter, defined here. Kind: Specifies the kind of code the snippet contains, which indicates where the snippet must be inserted. This attribute can have the following values: method body: Specifies that the code snippet is a method body, and therefore, must be inserted inside a method declaration. method decl: Specifies that the code snippet is a method, and therefore, must be inserted inside a class or module. type decl: Specifies that the code snippet is a type, and therefore, must be inserted inside a class, module, or namespace. file: Specifies that the snippet is a full code file. These code snippets can be inserted alone into a code file, or inside a namespace. any: Specifies that the snippet can be inserted anywhere. : Specifies the literals and objects that make up the parts of a code snippet that you can edit when it inserted into your source file. Can contain the following elements: : Identifies a replacement for a piece of code that is contained entirely within the snippet, but will probably be changed after the snippet is inserted into code. The literal end ($end$) is reserved, and is used to mark where the cursor should be placed after the code snippet is inserted. Can contain the following elements: : A unique identifier for the literal. This is a required element. : Described how the literal should be used. : Specifies a function to execute when the literal receives focus in Visual Studio. : The literal's default value when the code snippet is inserted. This is a required element.
http://guardian-dental-insurance-company.samudraonline.com/ guardian dental insurance company [url=http://guardian-dental-insurance-company.samudraonline.com/] guardian dental insurance company [/url] http://progressive-auto-insurance.samudraonline.com/ progressive auto insurance [url=http://progressive-auto-insurance.samudraonline.com/] progressive auto insurance [/url] http://geicko.samudraonline.com/ geicko [url=http://geicko.samudraonline.com/] geicko [/url] http://connecticut-general-life-insurance.samudraonline.com/ connecticut general life insurance [url=http://connecticut-general-life-insurance.samudraonline.com/] connecticut general life insurance [/url] http://genworth-life-insurance-company.samudraonline.com/ genworth life insurance company [url=http://genworth-life-insurance-company.samudraonline.com/] genworth life insurance company [/url] http://essurance-com.samudraonline.com/ essurance.com [url=http://essurance-com.samudraonline.com/] essurance.com [/url] http://aflec-insurance.samudraonline.com/ aflec insurance [url=http://aflec-insurance.samudraonline.com/] aflec insurance [/url] http://geicko-insurance.samudraonline.com/ geicko insurance [url=http://geicko-insurance.samudraonline.com/] geicko insurance [/url] http://great-west-health-insurance.samudraonline.com/ great west health insurance [url=http://great-west-health-insurance.samudraonline.com/] great west health insurance [/url] http://www-directline-com.samudraonline.com/ www.directline.com [url=http://www-directline-com.samudraonline.com/] www.directline.com [/url]
http://gecio-insurance.henryliwag.com/ gecio insurance [url=http://gecio-insurance.henryliwag.com/] gecio insurance [/url] http://apply-for-california-unemployment-insurance.henryliwag.com/ apply for california unemployment insurance [url=http://apply-for-california-unemployment-insurance.henryliwag.com/] apply for california unemployment insurance [/url] http://geicoinsurance-com.henryliwag.com/ geicoinsurance.com [url=http://geicoinsurance-com.henryliwag.com/] geicoinsurance.com [/url] http://insurance.henryliwag.com/ insurance [url=http://insurance.henryliwag.com/] insurance [/url] http://american-income-life-insurance-company.henryliwag.com/ american income life insurance company [url=http://american-income-life-insurance-company.henryliwag.com/] american income life insurance company [/url] http://geico-com.henryliwag.com/ geico.com [url=http://geico-com.henryliwag.com/] geico.com [/url] http://www-wellsfargo-com.henryliwag.com/ www.wellsfargo.com [url=http://www-wellsfargo-com.henryliwag.com/] www.wellsfargo.com [/url] http://www-webjet-com-au.henryliwag.com/ www.webjet.com.au [url=http://www-webjet-com-au.henryliwag.com/] www.webjet.com.au [/url] http://aiginsurance-com.henryliwag.com/ aiginsurance.com [url=http://aiginsurance-com.henryliwag.com/] aiginsurance.com [/url] http://www-aflac-com.henryliwag.com/ www.aflac.com [url=http://www-aflac-com.henryliwag.com/] www.aflac.com [/url]
affordable auto insu POST: 2008-11-22 06:37:52
http://american-income-life-insurance-company.skylightsofwesttexas.com/ american income life insurance company [url=http://american-income-life-insurance-company.skylightsofwesttexas.com/] american income life insurance company [/url] http://insurance.skylightsofwesttexas.com/ insurance [url=http://insurance.skylightsofwesttexas.com/] insurance [/url] http://geicoinsurance-com.skylightsofwesttexas.com/ geicoinsurance.com [url=http://geicoinsurance-com.skylightsofwesttexas.com/] geicoinsurance.com [/url] http://apply-for-california-unemployment-insurance.skylightsofwesttexas.com/ apply for california unemployment insurance [url=http://apply-for-california-unemployment-insurance.skylightsofwesttexas.com/] apply for california unemployment insurance [/url] http://gecio-insurance.skylightsofwesttexas.com/ gecio insurance [url=http://gecio-insurance.skylightsofwesttexas.com/] gecio insurance [/url] http://gieco-auto-insurance.skylightsofwesttexas.com/ gieco auto insurance [url=http://gieco-auto-insurance.skylightsofwesttexas.com/] gieco auto insurance [/url] http://valley-forge-life-insurance.skylightsofwesttexas.com/ valley forge life insurance [url=http://valley-forge-life-insurance.skylightsofwesttexas.com/] valley forge life insurance [/url] http://www-esurance-com.skylightsofwesttexas.com/ www.esurance.com [url=http://www-esurance-com.skylightsofwesttexas.com/] www.esurance.com [/url] http://wawanesa-auto-insurance.skylightsofwesttexas.com/ wawanesa auto insurance [url=http://wawanesa-auto-insurance.skylightsofwesttexas.com/] wawanesa auto insurance [/url] http://site-www-infinityauto-com-infinity-auto-insurance.skylightsofwesttexas.com/ site:www.infinityauto.com infinity auto insurance [url=http://site-www-infinityauto-com-infinity-auto-insurance.skylightsofwesttexas.com/] site:www.infinityauto.com infinity auto insurance [/url]