VS中为类,函数代码自动添加版权注释信息

转:http://www.cnblogs.com/CookBlack/archive/2011/03/04/1971283.html

VS中为类,函数代码自动添加版权注释信息

以web项目为例:
一:给类加注释
1.在visual studio 的安装路径下
        如:[盘符]:\Program files\Microsoft Visual Studio 8\Common7\IDE\ItemTemplates\web\cshare\2052\class.zip ,将里面的class.cs改为:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*----------------------------------------------------------------
// 版权所有。
//
// 文件名:
// 文件功能描述:
//
//
// 创建标识:
//
// 修改标识:
// 修改描述:
//
// 修改标识:
// 修改描述:
//----------------------------------------------------------------*/
using System; 
using System.Data; 
using System.Configuration; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Web.UI.HtmlControls; 
 
/// <summary>
/// $safeitemrootname$ 的摘要说明
/// </summary>
public class $safeitemrootname$ 
public $safeitemrootname$() 
    
//
// TODO: 在此处添加构造函数逻辑
//
    
保存文件即可(先解压,在修改)
其他的也是,找到相应的进行修改就可以。我个人还是偏向第二种。去到哪里都成。
二:VS宏脚本添加函数注释模板
现在的IDE越做越强大,为我等懒人省了不少。为了使用将来的代码自己或别人能看懂,注释这种东西必不可少。当为函数添加注释时,格式是固定的。每个函数写一遍,或从别的函数处拷贝过来,即麻烦又容易出错。这种重复劳动让人心烦都有不想写注释的欲望了,这时VS的宏可以干掉这些“脏、乱、累”的体力活。
看了一下,VS2010的宏脚本就是VBScript,很容易上手。我写了一个生成函数注释模板的宏脚本,比较容易,看代码:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics
 
Public Module ModuleTop
     Sub AddFunComment()
         Dim DocSel As EnvDTE.TextSelection
         DocSel = DTE.ActiveDocument.Selection
         DocSel.NewLine()
         DocSel.Text = "/*******************************************************************"
         DocSel.NewLine()
         DocSel.Text = "* 版权所有: "
         DocSel.NewLine()
         DocSel.Text = "* 类 名 称: "
         DocSel.NewLine()
         DocSel.Text = "* 功    能: "
         DocSel.NewLine()
         DocSel.Text = "* 参    数: "
         DocSel.NewLine()
         DocSel.Text = "* 返 回 值: "
         DocSel.NewLine()
         DocSel.Text = "* 作    者:XXXXX"
         DocSel.NewLine()
         DocSel.Text = "* 电子邮箱:XXXXXX@gmail.com"
         DocSel.NewLine()
         DocSel.Text = "* 创建日期: " + System.DateTime.Now.ToString()
         DocSel.NewLine()
         DocSel.Text = "*******************************************************************/"
     End Sub
 
End Module
具体的创建步骤:VS2010 IDE -> 工具 -> 宏 -> 新建宏项目,选择要保存的位置。然后将要上面的脚本复制进去,保存即可。
image
具体的使用:为你编写的宏绑定快捷键,VS2005 IDE -> 工具 -> 选项 -> 在左边列表中选择“键盘” -> 在右边的“显示命令包含”中,选择你创建宏-> 将光标定位到”按快捷键”处 -> 输入你想命名的快捷键,比如”Alt+C”,保存即可。
image
下面在附上一段,类内部的注释
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics
 
Public Module ModuleContent
     Sub AddFunComment()
         Dim DocSel As EnvDTE.TextSelection
         DocSel = DTE.ActiveDocument.Selection
         DocSel.NewLine()
         DocSel.NewLine()
         DocSel.Text = " #region<构造方法和析构方法>"
         DocSel.NewLine()
         DocSel.NewLine()
         DocSel.Text = "#endregion<构造方法和析构方法>"
         DocSel.NewLine()
         DocSel.NewLine()
         DocSel.NewLine()
         DocSel.Text = "#region<常量>"
         DocSel.NewLine()
         DocSel.NewLine()
         DocSel.Text = "#endregion<常量>"
         DocSel.NewLine()
         DocSel.NewLine()
         DocSel.NewLine()
         DocSel.Text = "#region<变量>"
         DocSel.NewLine()
         DocSel.NewLine()
         DocSel.Text = "#endregion<变量>"
         DocSel.NewLine()
         DocSel.NewLine()
         DocSel.NewLine()
         DocSel.Text = "#region<属性>"
         DocSel.NewLine()
         DocSel.NewLine()
         DocSel.Text = "#endregion<属性>"
         DocSel.NewLine()
         DocSel.NewLine()
         DocSel.NewLine()
         DocSel.Text = "#region<方法>"
         DocSel.NewLine()
         DocSel.NewLine()
         DocSel.Text = "#endregion<方法>"
         DocSel.NewLine()
         DocSel.NewLine()
         DocSel.NewLine()
         DocSel.Text = "#region<事件>"
         DocSel.NewLine()
         DocSel.NewLine()
         DocSel.Text = "#endregion<事件>"
     End Sub
 
End Module
实现的效果是
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#region<构造方法和析构方法>
 
#endregion<构造方法和析构方法>
 
 
#region<常量>
 
#endregion<常量>
 
 
#region<变量>
 
#endregion<变量>
 
 
#region<属性>
 
#endregion<属性>
 
 
#region<方法>
 
#endregion<方法>
 
 
#region<事件>
 
#endregion<事件>
快捷键自定义。只要跟现有的冲突就成。

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值