-
C#教程之C#实现为类和函数代码自动添加版权注释
本文实例讲述了C#实现为类和函数代码自动添加版权注释信息的方法,分享给大家供大家参考之用。具体方法如下:
以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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/*---------------------------------------------------------------- // 版权所有。 // // 文件名: // 文件功能描述: // // // 创建标识: // // 修改标识: // 修改描述: // // 修改标识: // 修改描述: //----------------------------------------------------------------*/ 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: 在此处添加构造函数逻辑 // } } /*---------------------------------------------------------------- // 版权所有。 // // 文件名: // 文件功能描述: // // // 创建标识: // // 修改标识: // 修改描述: // // 修改标识: // 修改描述: //----------------------------------------------------------------*/ 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
Imports System Imports EnvDTE Imports EnvDTE80 Imports EnvDTE90 Imports System.Diagnostics Public Module Module1 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 = "* 作 者: Lonkil" DocSel.NewLine() DocSel.Text = "* 电子邮箱: lonkil{AT}gmail.com ( {AT} -> @ )" DocSel.NewLine() DocSel.Text = "* 创建日期: " + System.DateTime.Now.ToLongDateString() DocSel.NewLine() DocSel.Text = "*******************************************************************/" End Sub End Module Imports System Imports EnvDTE Imports EnvDTE80 Imports EnvDTE90 Imports System.Diagnostics Public Module Module1 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 = "* 作 者: Lonkil" DocSel.NewLine() DocSel.Text = "* 电子邮箱: lonkil{AT}gmail.com ( {AT} -> @ )" DocSel.NewLine() DocSel.Text = "* 创建日期: " + System.DateTime.Now.ToLongDateString() DocSel.NewLine() DocSel.Text = "*******************************************************************/" End Sub End Module |
具体的创建步骤:vs2010 IDE -> 工具 -> 宏 -> 新建宏项目,选择要保存的位置。然后将要上面的脚本复制进去,保存即可。
具体的使用:为你编写的宏绑定快捷键,vs2010 IDE -> 工具 -> 选项 -> 在左边列表中选择“键盘” -> 在右边的“显示命令包含”中,选择你创建宏-> 将光标定位到”按快捷键”处 -> 输入你想命名的快捷键,比如”Alt+C”,保存即可。
有一点需要注意:Visual Studio 2005 Team Suite 需要打上SP1补丁,宏方能使用否则无效。
相信本文所述对大家的C#程序设计有一定的借鉴价值。
栏目列表
最新更新
python爬虫及其可视化
使用python爬取豆瓣电影短评评论内容
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
SQL SERVER中递归
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
uniapp/H5 获取手机桌面壁纸 (静态壁纸)
[前端] DNS解析与优化
为什么在js中需要添加addEventListener()?
JS模块化系统
js通过Object.defineProperty() 定义和控制对象
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比