Visual Studio环境使用宏自动添加文件注释
2013-03-13 17:10
148 查看
其实,我们每天都在搞编程,其中的很多的步骤其实都是重复的,不如,我们为文件添加注释,这些工作其实没什么技术含量,但是,这些也是我们作为一个程序员的基本素质,因为我们有责任让我们的代码保持清晰、可读,所以我们需要添加一些注释信息。特别是涉及到算法的代码,关键的地方,或者是比较有争议的地方更加应该添加注释,不仅是为了提醒自己,更是为了让其他人也能容易的阅读。
Visual Studio自动添加文件注释的方法,在这里我选择的是宏的功能,宏就是一段VBA的脚本,Visual Studio支持用户自定义快捷键和宏关联起来,所以我们完全写一个宏,完成自己的功能。作为一个学技术的开发人员,在这里就不说技术了,我们只谈论代码,至于如何去实施,就请参考微软的帮助文档吧!下面是我写的一个宏,主要完成的功能是添加文件注释、多行注释和单行注释。
Visual Studio自动添加文件注释的方法,在这里我选择的是宏的功能,宏就是一段VBA的脚本,Visual Studio支持用户自定义快捷键和宏关联起来,所以我们完全写一个宏,完成自己的功能。作为一个学技术的开发人员,在这里就不说技术了,我们只谈论代码,至于如何去实施,就请参考微软的帮助文档吧!下面是我写的一个宏,主要完成的功能是添加文件注释、多行注释和单行注释。
Option Strict Off Option Explicit Off Imports System Imports EnvDTE Imports EnvDTE80 Imports System.Diagnostics Public Module ModuleComment Sub AddSingleComment() DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "/* */" DTE.ActiveDocument.Selection.CharLeft(False, 3) End Sub Sub AddMutiComment() DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.StartOfLine() DTE.ActiveDocument.Selection.Text = "/* ------------------------------------------------------------------------- */" DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.StartOfLine() DTE.ActiveDocument.Selection.Text = "/* */" DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.StartOfLine() DTE.ActiveDocument.Selection.Text = "/* ------------------------------------------------------------------------- */" DTE.ActiveDocument.Selection.LineUp() DTE.ActiveDocument.Selection.CharLeft(False, 76) End Sub Sub AddFileComment() Dim doc As Document Dim docName As String Dim companyName As String = "华中师范大学计算机科学系" Dim authorName As String = "张永昌" 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 = "* ===========================================================================" DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "*" DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "* 文件名: " + docName DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "* 描述: " DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "*" ' Write author name tag (optional) DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "* 版本: 1.0" DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "* 创建时间: " + String.Format("{0:d}", Date.Now) + " " + String.Format("{0}:{1}:{2}", DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second) DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "* 编译环境: Visual Studio 2005" DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "*" DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "* 作者: " + authorName DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "* 单位: " + companyName DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "*" DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "* ===========================================================================" DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "*****************************************************************************/" DTE.ActiveDocument.Selection.NewLine() End Sub End Module
相关文章推荐
- 关于使用 Visual Studio 开发环境收费的问题,博友们谁有经验分享一下。
- 让中文环境的Visual Studio 2005使用英文版的项目模板
- 关于使用 Visual Studio 开发环境收费的问题,博友们谁有经验分享一下。
- Visual Studio 2010环境下Sqlite3加密版(由wxSqlite制作)使用方法
- 关于使用 Visual Studio 开发环境收费的问题,博友们谁有经验分享一下。
- 使用visual studio 2013 快速搭建phonegap开发环境
- Visual Studio 2008不能在64位环境下使用SharePoint工作流模板
- Windows7 visual studio 2010下MFC中正确使用GDI+的环境配置
- 在Visual Studio中使用MonoTouch开发iOS应用程序(上):环境配置
- 使用Visual Studio 2005搭建opengl开发环境
- Visual Studio 2010环境下Sqlite3加密版(由wxSqlite制作)使用方法
- 关于使用 Visual Studio 开发环境收费的问题,博友们谁有经验分享一下。
- 如何在Visual Studio 2010中使用CppUTest建立TDD的Code Kata的环境
- 在visual studio 2012 环境下开发windows phone 怎么安装使用silverlight for windows phoneToolkit
- 如何Visual Studio环境使用 C++ Boost库,详细步骤
- 在Visual Studio中使用MonoTouch开发iOS应用程序(上):环境配置
- 在Windows的Visual Studio环境中安装与使用CLAPACK
- 【可视化编程】实验1: Visual Studio环境的使用
- python使用Visual Studio 2015作为IDE开发django项目的环境部署
- 使用Visual Studio一劳永逸式配置OpenGL开发环境(GLFW3+GLAD)