1. 在Tool中选择Macros,打开Macro IDE
2. 在MyMacros 删除默认文件 Module1.vb,添加文件CommentHelper.Vb代码内容
- Imports System
- Imports EnvDTE
- Imports EnvDTE80
- Imports EnvDTE90
- Imports System.Diagnostics
- '注释帮助模块
- Public Module CommentHelper
- Sub AddClassComment()
- '定义选择区域
- Dim DocSel As EnvDTE.TextSelection
- '初始化选择区域是当前文档的选择
- DocSel = DTE.ActiveDocument.Selection
- '选择区域移动到文档的开头
- DocSel.StartOfDocument()
- DocSel.Text = "/*******************************************************************"
- DocSel.NewLine()
- DocSel.Text = "* Copyright (C) abc Corporation"
- DocSel.NewLine()
- DocSel.Text = "* All rights reserved."
- DocSel.NewLine()
- DocSel.Text = "*"
- DocSel.NewLine()
- DocSel.Text = "Author: HBB0b0 (hbb0b0@163.com)"
- DocSel.NewLine()
- DocSel.Text = "Create Date:" + DateTime.Now.ToString()
- DocSel.NewLine()
- DocSel.Text = "Description:" + DTE.ActiveDocument.Name
- DocSel.NewLine()
- DocSel.Text = "*"
- DocSel.NewLine()
- DocSel.Text = "* Date Author Description"
- DocSel.NewLine()
- DocSel.Text = "*******************************************************************/"
- DocSel.NewLine()
- End Sub
- End Module
3. 在需要添加注释的项目中打开Macro 浏览器,如果看不到AddClassComment宏,则需要导入宏项目
4. 打开需要注释文件,双击或运行AddClassComment,就会添加如下效果的注释。
- /*******************************************************************
- * * Copyright (C) abc Corporation
- * * All rights reserved.
- * *
- * Author: HBB0b0 (hbb0b0@163.com)
- * Create Date:2011-3-21 19:51:03
- * Description:Program.cs
- * *
- * * Date Author Description
- * *******************************************************************/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace MacroApplication
- {
- class Program
- {
- static void Main(string[] args)
- {
- }
- }
- }
如果觉得这种方式不方便,可以把它做成ToolBar,下个项目使用的只需要运行ToolBar中的对应按钮就可以了。
1. 在Tools中选择自定义
2. 新添ToolBar 名称为CommentHelper
3. 在命令页签Macros选择AddClassComment
4. 按住Macro.MyMacros.CommentHelper.AddClassComment,把它拖到CommentHelper容器上
5. 拖放后的效果如下
6. 在以后的使用时不用再次打开宏项目,直接单击CommentHelper中AddClassComment按钮就可以添加类注释了。
原文链接:http://www.cnblogs.com/hbb0b0/archive/2011/03/22/1990670.html
【编辑推荐】