Tanky WooRSS

VS2008利用宏添加注释模板

27 Jan 2011
这篇博客是从旧博客 WordPress 迁移过来,内容可能存在转换异常。

程序注释的重要性毋庸置疑,一个大型的项目通常情况下都是几个软件工程师合作出来的成果,假如该项目中的代码注释不全,那会给将来的维护者带来无穷无尽的隐患。

通用的办法是给自己工程里面的函数添加注释——使用宏。

1.打开Visual Studio 2008(2005一样适用)开发工具,单击“工具→宏→新建宏项目”,然后按照步骤建立注释宏,添加如下代码并保存。

2.打开 菜单 --> 工具-->选项 --> 键盘 ,在列表框中选择刚才添加的Macro,然后在 按快捷键中输入快捷键,点击"分配" 。

注释宏的代码如下:

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 = "* 作    者: Tanky Woo"
    DocSel.NewLine()
    DocSel.Text = "* 博    客: (1)www.WuTianQi.com | (2)www.TankyWoo.com"
    DocSel.NewLine()
    DocSel.Text = "* 电子邮箱:admin@TankyWoo.com"
    DocSel.NewLine()
    DocSel.Text = "* 日    期:" + System.DateTime.Now.ToLongDateString()
    DocSel.NewLine()
    DocSel.Text = "*******************************************************************/"
End Sub