How does Visual Studio use Code Snippet to increase programming speed !!!,

Source: Internet
Author: User

How does Visual Studio use Code Snippet to increase programming speed !!!,
 

When using Code Snippet to simplify Coding during development, do you often encounter the need to repeat some similar Code, such as whether for and foreach are often used? When writing these two loop statements, do you need to double a character or use the Code Snippet tool provided by Visual Studio to automatically generate them?
Magic
You only need to enter for in the code editor, and the following red box appears in the automatic prompt box of Visual Studio. In this case, you only need to press the tab key twice, the for loop statement is automatically completed (as shown in Figure 2), and the index is selected by default for modification.


Figure 1 automatic prompt box


Figure 2 Automatic completion cycle statement
Is it amazing? Like this, switch and cw (Console. writeLine), ctor (constructor), prop (attribute), and so on, flexible use of this can make your Coding work get twice the result with half the effort. For more default CodeSnippet, refer to resource [1].
However, each project has its own particularity. By default, if the Code Snippet cannot meet your needs, you need to automatically scale it out.
The secret of Code Snippet [C #]
Before you start writing your own Code Snippet, you must first understand how this is done.
It is actually just an xml, but it only contains elements that only known by Visual Studio. These elements define how to complete the code for US (, code Snippet uses different elements for different languages such as VB, C #, and CSS. This article describes all the elements in C # language ).

 

Attribute. Snippet file source code: C: \ Program Files (x86) \ Microsoft Visual Studio 14.0 \ VC # \ Snippets \ 2052 \ Visual C #

<? Xml version = "1.0" encoding = "UTF-8"?>
<CodeSnippets xmlns = "http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format = "1.0.0">
<Header>
<Title> attribute </Title>
<Shortcut> Attribute </Shortcut>
<Description> code snippet using the features of the suggested mode </Description>
<Author> Microsoft Corporation </Author>
<SnippetTypes>
<SnippetType> Expansion </SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID> name </ID>
<ToolTip> feature name </ToolTip>
<Default> My </Default>
</Literal>
<Literal>
<ID> target </ID>
<Default> All </Default>
</Literal>
<Literal>
<ID> inherited </ID>
<Default> false </Default>
</Literal>
<Literal>
<ID> allowmultiple </ID>
<Default> true </Default>
</Literal>
<Literal Editable = "false">
<ID> SystemAttribute </ID>
<Function> SimpleTypeName (global: System. Attribute) </Function>
</Literal>
<Literal Editable = "false">
<ID> SystemAttributeUsage </ID>
<Function> SimpleTypeName (global: System. AttributeUsage) </Function>
</Literal>
<Literal Editable = "false">
<ID> SystemAttributeTargets </ID>
<Function> SimpleTypeName (global: System. AttributeTargets) </Function>
</Literal>
<Literal Editable = "false">
<ID> Exception </ID>
<Function> SimpleTypeName (global: System. NotImplementedException) </Function>
</Literal>
</Declarations>
<Code Language = "csharp"> <! [CDATA [[$ SystemAttributeUsage $ ($ SystemAttributeTargets $. $ target $, Inherited = $ inherited $, AllowMultiple = $ allowmultiple $)]
Sealed class $ name $ Attribute: $ SystemAttribute $
{
// See the attribute guidelines
// Http://go.microsoft.com/fwlink? LinkId = 85236
Readonly string positionalString;

// This is a positional argument
Public $ name $ Attribute (string positionalString)
{
This. positionalString = positionalString;

// TODO: Implement code here
$ End $ throw new $ Exception $ ();
}

Public string PositionalString
{
Get {return positionalString ;}
}

// This is a named argument
Public int NamedInt {get; set ;}
}]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

To be continued...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.