利用Visual Studio 2008宏實現自動注釋
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()
- '定義選擇區(qū)域
- Dim DocSel As EnvDTE.TextSelection
- '初始化選擇區(qū)域是當前文檔的選擇
- DocSel = DTE.ActiveDocument.Selection
- '選擇區(qū)域移動到文檔的開頭
- 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
【編輯推薦】