VS2005中创建自己的代码段
VS2005中提供了代码段的便捷功能,敲入一个关键字,当其在下拉列表中显示图标为一个文件的时候,敲两下TAB键,便能快速的获取这个代码片段,剩下所需做的就是移动到对应的位置,填入参数性质的东西替换预留的位置。
当然大多数常见的代码段,微软都为我们提前准备了。例如:if,for ……
但是,有时候我们也会遇到重复写两部分或以上数量代码的时候,那么就需要定义我们自己的代码段了。
在VS2005中步骤如下:
1 文件——新建——文件——XML文件
2 在第二行,Ctrl+K ,Ctrl+X列表中选择Snippet
3 Title、Author、Description填入对应的内容。Shortcut设置代码段的快捷编码,例如:mysnippet1
4 有几个预留代码位置,便需要重复几次Literal节点,设置显示的预留位置ID名和默认值
5 修改Code节点的Language属性为CSharp(VJSharp,VB,XML)
6 Code节点的<![CDATA[ 与 ]]> 之间,填入自己的代码段
7 保存,并改变此XML文件的扩展名为snippet,并保存在某个文件夹下
8 工具——代码段管理器——添加自己的放代码段文件夹
这样再此在VS2005中写代码时,便可以敲入自编的代码段快捷编码,然后按TAB两次,就能获取到自己的代码段了。在项目中的话,好的代码段也能快捷地供他人分享。
一个供参考的示例代码段XML设置文件:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
附加解释:
$end$:这是一个特殊参数,用于指定用户在代码段字段中填写完内容并按下 Enter 键后光标所在的位置。
$selected$:这是一个特殊参数,只对 SurroundsWith 类型的代码段有意义。