利用Visual Studio 2008宏实现自动注释
创始人
2024-07-23 20:41:25
0

1. 在Tool中选择Macros,打开Macro IDE

2. 在MyMacros 删除默认文件 Module1.vb,添加文件CommentHelper.Vb代码内容

  1. Imports System  
  2. Imports EnvDTE  
  3. Imports EnvDTE80  
  4. Imports EnvDTE90  
  5. Imports System.Diagnostics  
  6. '注释帮助模块  
  7. Public Module CommentHelper  
  8. Sub AddClassComment()  
  9. '定义选择区域  
  10. Dim DocSel As EnvDTE.TextSelection  
  11. '初始化选择区域是当前文档的选择  
  12. DocSel = DTE.ActiveDocument.Selection  
  13. '选择区域移动到文档的开头  
  14. DocSel.StartOfDocument()  
  15. DocSel.Text = "/*******************************************************************" 
  16. DocSel.NewLine()  
  17. DocSel.Text = "* Copyright (C) abc Corporation" 
  18. DocSel.NewLine()  
  19. DocSel.Text = "* All rights reserved." 
  20. DocSel.NewLine()  
  21. DocSel.Text = "*" 
  22. DocSel.NewLine()  
  23. DocSel.Text = "Author: HBB0b0 (hbb0b0@163.com)" 
  24. DocSel.NewLine()  
  25. DocSel.Text = "Create Date:" + DateTime.Now.ToString()  
  26. DocSel.NewLine()  
  27. DocSel.Text = "Description:" + DTE.ActiveDocument.Name  
  28. DocSel.NewLine()  
  29. DocSel.Text = "*" 
  30. DocSel.NewLine()  
  31. DocSel.Text = "* Date Author Description" 
  32. DocSel.NewLine()  
  33. DocSel.Text = "*******************************************************************/" 
  34. DocSel.NewLine()  
  35. End Sub 
  36. End Module 

3. 在需要添加注释的项目中打开Macro 浏览器,如果看不到AddClassComment宏,则需要导入宏项目

4. 打开需要注释文件,双击或运行AddClassComment,就会添加如下效果的注释。

  1. /*******************************************************************  
  2. * * Copyright (C) abc Corporation  
  3. * * All rights reserved.  
  4. * *  
  5. * Author: HBB0b0 (hbb0b0@163.com)  
  6. * Create Date:2011-3-21 19:51:03  
  7. * Description:Program.cs  
  8. * *  
  9. * * Date Author Description  
  10. * *******************************************************************/  
  11. using System;  
  12. using System.Collections.Generic;  
  13. using System.Linq;  
  14. using System.Text;  
  15. namespace MacroApplication  
  16. {  
  17. class Program  
  18. {  
  19. static void Main(string[] args)  
  20. {  
  21. }  
  22. }  

如果觉得这种方式不方便,可以把它做成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

【编辑推荐】

 

  1. Visual Studio 2008在Web.config文件中注册web用户控件
  2. Visual Studio 2008中创建web用户控件
  3. Visual Studio 2008的ListView数据排序
  4. Visual Studio 2008的标记导航功能
  5. Visual Studio 2008中绑定ListView控件

相关内容

热门资讯

如何允许远程连接到MySQL数... [[277004]]【51CTO.com快译】默认情况下,MySQL服务器仅侦听来自localhos...
如何利用交换机和端口设置来管理... 在网络管理中,总是有些人让管理员头疼。下面我们就将介绍一下一个网管员利用交换机以及端口设置等来进行D...
施耐德电气数据中心整体解决方案... 近日,全球能效管理专家施耐德电气正式启动大型体验活动“能效中国行——2012卡车巡展”,作为该活动的...
20个非常棒的扁平设计免费资源 Apple设备的平面图标PSD免费平板UI 平板UI套件24平图标Freen平板UI套件PSD径向平...
德国电信门户网站可实时显示全球... 德国电信周三推出一个门户网站,直观地实时提供其安装在全球各地的传感器网络检测到的网络攻击状况。该网站...
为啥国人偏爱 Mybatis,... 关于 SQL 和 ORM 的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行...
《非诚勿扰》红人闫凤娇被曝厕所... 【51CTO.com 综合消息360安全专家提醒说,“闫凤娇”、“非诚勿扰”已经被黑客盯上成为了“木...
2012年第四季度互联网状况报... [[71653]]  北京时间4月25日消息,据国外媒体报道,全球知名的云平台公司Akamai Te...