代码段是微软提供的众多帮助开发的功能之一,非常方便,将我们复用的代码都写成代码段,用到时候敲几个简单的缩写或简写就可以了。
比如你添加构造函数,类中输入ctor,按下tab,就自动的会生成构造函数。
方法中输入mbox,按Tab,就会生成MessageBox.Show("");
还有很多,你可以在D:\Program Files\Microsoft Visual Studio 9.0\VC#\Snippets\2052\Visual C#目录下找找,或是在代码段编辑器中,选择c#,看到所支持的代码段。
言归正传,我们自己能不能创建代码段呢?可以,微软已经给我们方法了,
Creating Code Snippets。自己创建xml文件,自己编写每个节点。
有没有更简单的方法?有。
Snippet Designer
Creating A Snippet From Scratch in VS 2010
The following describes how to create a new snippet file from scratch using the Snippet Designer
Open up the new file dialog
Select the Code Snippet
This will open up a blank snippet editor
Enter the code which you would like to become your snippet
Right click on the variables/symbols you would like to be replacements and choose make replacement
Afterwards you will see this
Repeat this process for all variables/symbols you would like to be replacements
Set your snippet's name and set the shortcut with which you would like to access your snippet
Then Save your snippet and you are done!!
下载地址:
SnippetDesignerFor2008
SnippetDesignerFor2010