【安裝】VS2010中爲類、函數代碼添加版權註釋信息

VS2010中爲類、函數代碼添加版權註釋信息

VS2010中爲類、函數代碼添加版權註釋信息分爲兩步

1.新建宏

在VS2010左側找到Macro 資源管理器,找到已經存在的宏項目samples。



雙擊任一模塊,進入Microsoft Visual Studio Macros。在下拉欄(圖中紅色標出)選擇添加模塊。



接着就可以對添加的模塊進行編輯。代碼可以在網上找到。下面會附出我自己的編輯後的代碼。


編輯完成後記得保存


2.綁定快捷鍵

工具---選項





依次操作。選擇鍵盤,選擇默認值,在“顯示命令包含”輸出相關信息快速定位添加的宏,按快捷鍵,分配,確定。

分配後的結果圖。記得點擊確定


完成之後就可以測試效果了,下面是我的測試效果圖





代碼:

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics


Public Module FunctionNote
    Sub AddFunComment()
        Dim DocSel As EnvDTE.TextSelection
        DocSel = DTE.ActiveDocument.Selection
        DocSel.NewLine()
        DocSel.Text = "/*******************************************************************"
        DocSel.NewLine()
        DocSel.Text = "* Name: "
        DocSel.NewLine()
        DocSel.Text = "* Function: "
        DocSel.NewLine()
        DocSel.Text = "* Parameter: "
        DocSel.NewLine()
        DocSel.Text = "* Return: "
        DocSel.NewLine()
        DocSel.Text = "* Author: Happy"
        DocSel.NewLine()
        DocSel.Text = "* Mail: [email protected]"
        DocSel.NewLine()
        DocSel.Text = "* Date: " + System.DateTime.Now.ToLongDateString()
        DocSel.NewLine()
        DocSel.Text = "*******************************************************************/"
    End Sub
End Module

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics

Public Module HeadFileNote
    Sub DocumentFileHeader()
        Dim doc As Document
        Dim docName As String
        Dim companyName As String = "NERCITA"
        Dim authorName As String = "Happy"
        Dim copyrightText As String = String.Format("Copyright (c) {0} {1}. All rights reserved.", Date.Now.Year, companyName)
        ' 從程序中獲得文件的名字
        doc = DTE.ActiveDocument
        '獲得當前編輯類的名字
        docName = doc.Name

        ' 將添加焦點定位在文件首部
        DTE.ActiveDocument.Selection.StartOfDocument()

        ' 添加一個版權說明
        DTE.ActiveDocument.Selection.Text = "/***************************************************************/" '以String類型添加自己想要的符號、文字
        DTE.ActiveDocument.Selection.NewLine()
        ' 添加一個空行
        DTE.ActiveDocument.Selection.Text = "/* @ FileName: " + docName + ""
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "/* @ " + copyrightText

        ' 添加用戶相關信息
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "/* @ Author: " + authorName + ""
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "/* @ Date: " + String.Format("{0:D}", Date.Now) + ""
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "/* @ Description: "
        DTE.ActiveDocument.Selection.Text = "*/"
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "/***************************************************************/"
        DTE.ActiveDocument.Selection.NewLine()
    End Sub
End Module

參考鏈接

http://www.cnblogs.com/CookBlack/archive/2011/03/04/1971283.html#printSource

http://wenku.baidu.com/view/8ae46fa5b0717fd5360cdc1a.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章