A singleton code snippet

Source: Internet
Author: User

InVisualstudio2005AndVisualstudio2008, We enterPropEnterTabKey to intelligently insert a segmentCode, Very convenient. For example:

 

 

If you are too lazy, you can also create code segments that you frequently write to improve the efficiency of code writing.Visualstudio2005AndVisualstudio2008, Open the menuTools-code snippets Manager (CTRL + k, CTRL + B)You can viewCode snippetsLocation:

 

 

 

 

Create your ownSingletonCode segment:(Singleton. SNIPPET)

 

<? XML version = "1.0" encoding = "UTF-8" ?>
< Codesnippets Xmlns: xsi = "Http://www.w3.org/2001/XMLSchema-instance" Xmlns: XSD = "Http://www.w3.org/2001/XMLSchema" Xmlns = "Http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet" >
< Codesnippet Format = "1.0.0" >
< Header >
< Title > Singleton </ Title >
< Shortcut > Singleton </ Shortcut >
< Description > Creates a singleton class following the discussion on that post of mine:
Http://blogs.ugidotnet.org/piyo/archive/2005/09/14/Singleton_C_NET.aspx </ Description >
< Helpurl />
< Author > Simone chiaretta </ Author >
< Snippettypes >
< Snippettype > Expansion </ Snippettype >
</ Snippettypes >
< Keywords />
</ Header >
< Snippet >
< References />
< Imports />
< Declarations >
< Literal Editable = "True" >
< ID > Classname </ ID >
< Tooltip > Here the name of your Singleton class </ Tooltip >
< Default > Singleton </ Default >
< Function />
</ Literal >
</ Declarations >
< Code Language = "CSHARP" Kind = "Any" Delimiter = "$" > Public class $ classname $
{
Private Static readonly $ classname $ instance = new $ classname $ ();

Static $ classname $ ()
{
}

Public static $ classname $ getinstance ()
{
Return instance;
}
} </ Code >
</ Snippet >
</ Codesnippet >
</ Codesnippets >

 

 

TheHeaderThis section briefly describesSnippetsSuch as name, shortcut, author, and remarks. In <Snippets> Under a node,SnippetsAnd <Default> Specifies the default value of this attribute. And in the key part <Code>, Use <! [CDATA]> Method definedSnippetsIn$It is very easy to define each attribute by parameter name.

 

(You can use the editor or MicrosoftCodesnippetEditor,Download here)

 

ThenVisualstudio2005AndVisualstudio2008, Open the menuTools-code snippets Manager (CTRL + k, CTRL + B), Click Import, and select SaveSingleton. snippetFile Location.

 

EnterSingleton, And then pressTabTo insertSingletonMode class. The cursor automatically stops at the class name. (You can also right-click and selectInsert snippet...And then select your ownCodesnippetYou can.

 

 

 

You can also create customCodesnippets, Such as a class template,NunitTemplate, readXMLFile code segment, saveXML, ThrowExceptionCode segment,String. isnulloremptyTo improve the efficiency of writing code.

 

(Other Visual Studio skills: to do a good job, you must first sharpen the tool-Visual Studio usage Skills 1)

 

Vs2010 plug-in: snippet designer

There is a visualstudio2010 plug-in snippetdesigner. Select a piece of code, right-click"Export as snippetYou can easily manage and create snippet.

 

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.