利用Visual Studio 2008宏實(shí)現(xiàn)自動(dòng)注釋
1. 在Tool中選擇Macros,打開(kāi)Macro IDE
2. 在MyMacros 刪除默認(rèn)文件 Module1.vb,添加文件CommentHelper.Vb代碼內(nèi)容
- Imports System
- Imports EnvDTE
- Imports EnvDTE80
- Imports EnvDTE90
- Imports System.Diagnostics
- '注釋幫助模塊
- Public Module CommentHelper
- Sub AddClassComment()
- '定義選擇區(qū)域
- Dim DocSel As EnvDTE.TextSelection
- '初始化選擇區(qū)域是當(dāng)前文檔的選擇
- DocSel = DTE.ActiveDocument.Selection
- '選擇區(qū)域移動(dòng)到文檔的開(kāi)頭
- 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. 在需要添加注釋的項(xiàng)目中打開(kāi)Macro 瀏覽器,如果看不到AddClassComment宏,則需要導(dǎo)入宏項(xiàng)目
4. 打開(kāi)需要注釋文件,雙擊或運(yùn)行AddClassComment,就會(huì)添加如下效果的注釋。
- /*******************************************************************
- * * 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)
- {
- }
- }
- }
如果覺(jué)得這種方式不方便,可以把它做成ToolBar,下個(gè)項(xiàng)目使用的只需要運(yùn)行ToolBar中的對(duì)應(yīng)按鈕就可以了。
1. 在Tools中選擇自定義
2. 新添ToolBar 名稱為CommentHelper
3. 在命令頁(yè)簽Macros選擇AddClassComment
4. 按住Macro.MyMacros.CommentHelper.AddClassComment,把它拖到CommentHelper容器上
5. 拖放后的效果如下
6. 在以后的使用時(shí)不用再次打開(kāi)宏項(xiàng)目,直接單擊CommentHelper中AddClassComment按鈕就可以添加類注釋了。
原文鏈接:http://www.cnblogs.com/hbb0b0/archive/2011/03/22/1990670.html
【編輯推薦】