在Visual Studio中给源代码添加文件头注释

这里我向大家介绍一个Visual studio的宏(Macro)来给源代码添加注释。

打开Visual studio->Tools->Macros->Marcros IDE,添加下面的代码:

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
 
Public Module MyVisualStudioModule
    Sub DocumentFileHeader()
        Dim doc As Document
        Dim docName As String
        Dim companyName As String = "YOUR COMPANY NAME"
        Dim authorName As String = "YOUR NAME"
        Dim copyrightText As String = String.Format("Copyright (c) {0} {1}. All rights reserved.", Date.Now.Year, companyName)
 
        ' Get the name of this object from the file name
        doc = DTE.ActiveDocument
 
        ' Get the name of the current document
        docName = doc.Name
 
        ' Set selection to top of document
        DTE.ActiveDocument.Selection.StartOfDocument()
 
        ' Write copyright tag
        DTE.ActiveDocument.Selection.Text = "//------------------------------------------------------------------------------"
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "// <copyright file=""" + docName + """ company=""" + companyName + """>"
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "//     " + copyrightText
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "// </copyright>"
 
        ' Write author name tag (optional)
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "// <author>" + authorName + "</author>"
        DTE.ActiveDocument.Selection.NewLine()
 
        DTE.ActiveDocument.Selection.Text = "// <date>" + String.Format("{0:D}", Date.Now) + "</date>"
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "// <description>"
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "// </description>"
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "//------------------------------------------------------------------------------"
        DTE.ActiveDocument.Selection.NewLine()
    End Sub
End Module

这样,当你每次运行这个宏的时候,都会给你Visual studio的当前的文档添加如下格式的文件头注释:

//------------------------------------------------------------------------------
// <copyright file="YOUR FILE NAME.cs" company="YOUR COMPANY NAME">
//     Copyright (c) 2009 YOUR COMPANY NAME. All rights reserved.
// </copyright>
// <author>YOUR NAME</author>
// <date>Monday, March 02, 2009</date>
// <description>
// </description>
//------------------------------------------------------------------------------

看起来还挺COOL的,哈。

转载于:https://www.cnblogs.com/deepnight/archive/2010/11/15/1877569.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值