惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - Justin Shen

[.Net 4.0]泛型的协变,以及高阶函数对泛型的影响 Part 1 随笔 - WCF and Data Service - Justin Shen 面向对象语言中的Environment和Binding 元数据 有多少东西需要学习? [电子书下载]Dissecting a C# Application: Inside SharpDevelop [MSDNTV]Don Box再次出击 :) 追踪你的时间使用状况 听说《csdn开发高手》停刊了 在nant中改变编译的目标平台 让使用MSN就像访问网页一样容易! System.String是不可变的字符串吗? 对中国计算机大学教育的一些牢骚 [VS2005]做了两个Code Expansion用的Code Snippet。 VC2005中依然没有Refactoring和Code Expansion. [C++/CLI]在栈上声明Reference Type [C++/CLI] 析构函数等于IDisposable::Dispose()方法 用80386汇编来编写asp.net页面。 关于C#泛型中的new()约束
[VS2005 Tip]定制Code Expansion。
Justin Shen · 2004-10-27 · via 博客园 - Justin Shen

上篇文章里,我向大家介绍了在VS2005的IDE中,利用code expansion功能,自动生成Property的方法,事实上,在VS2005里已经预制了相当多的用来代码扩展(Code Expansion)的代码片断(Code Snippet),"prop"就是一个例子。在Tools菜单下,有一个叫作Code Snippets Manager的工具,在里面可以看到预定义的所有的Code Snippet。

那么我们是不是可以自定义一个Code Snippet用来作Code Expansion呢?经过试验,答案是肯定的!下面我们来看一下怎么完成这个工作。

首先,每个Code Snippet都对应了一个XML文件。在Code Snippets Manager中,我们可以看到这些XML的存放地点。如图:

打开这个XML文件,可以看到如下的内容:


我来解释一下其中主要的标签的作用:

<Shortcut>prop</Shortcut> 

定义了用来扩展的缩写是prop

定义了这个Snippet是用来作Code Expansion的。SnippetType的可能的取值还有

<SnippetType>SurroundsWith</SnippetType> 

你猜得没错这个就是用来设置Intellisense中的Surround With的功能的。一个Snippet可以同时拥有这两个类型。

<Declarations>标签中定义了扩展之后,需要用户填写的部分。每个<Literal>标签定义一个变量。<Default>定义了默认的取值。

最重要的就是<Code>中的内容了,这个就是扩展后的样子了。

下面我写了一个用来自动扩展出一个NUnit的TestFixture的Code Snippet。

注意在这里,我在<Code>中使用了$end$这个预设的变量,这个变量表明了在输入完所有的Literal之后,光标将停留的位置。

写完了之后,将这个XML文件保存到一个新建的目录。然后在Code Snippets Manager中,加入这个目录,然后就可以在IDE中使用这个Code Snippet了。

现在,按下tstFix之后按Tab键,就会自动生成一个带有[TestFixture]属性的类了。

大家还可以按照这个方法去试一下Surround With的功能。