现在大多数公司都规定程序员在程序文件的头部加上版权信息,这样每个人写的文件都可以区分开来,如果某个文件出现问题就可以快速的找到文件的创建人,用最短的时间来解决问题,常常是以下格式:

//======================================================================
//        All rights reserved
//
//        description :
//
//        created by User

//======================================================================

有些人使用Copy和Paste的方式,这样即浪费时间,效果又不是很好,就说上面的时间你就无法去Paste,哈哈,下面我就教大家怎样去添加这些信息,使我们的代码更有个性.
1.在visual studio 2010的安装路径下
        如:[盘符]:\Program files\Microsoft Visual Studio 8\Common7\IDE\ItemTemplatesCache
2.找到文件夹如图所示:

里面可以为各种语言进行修改.如果对WinForm中的类进行修改可以打开CSharp2052Class.zip.其中CSharp2052包括了所有WinForm文件类型的模板.
打开Class.zip里面有一个Class.cs文件,我们对其进行修改,当我们在WinForm中添加类文件的时候,类文件就会自动添加上我们的信息.
如下:

  1. //======================================================================
  2. //
  3. // All rights reserved
  4. //
  5. // filename :$safeitemrootname$
  6. // description :
  7. //
  8. // created by User at $time$
  9. //
  10. //======================================================================
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Text;
  14. namespace $rootnamespace$
  15. {
  16. class $safeitemrootname$
  17. {
  18. }
  19. }

$rootnamespace$为生成类的命名空间的名字,$safeitemrootname$为生成类的类名.
可以看到我们在版权信息中加入了$time$,它就可以直接给我们加入创建的时间.我们可以对CSharp2052中所有的模板进行修改,切忌不要轻易修改系统那些代码,以免影响我们的正常的使用.
对于做Web开发的人员来说可以在ItemTemplatesCacheWebCSharp2052里进行修改.
新建一个类文件就可以实现了插入我们自定义的版权信息.

  1. //======================================================================
  2. //
  3. // All rights reserved
  4. //
  5. // filename :NewClass
  6. // description :
  7. //
  8. // created by User at
  9. //
  10. //======================================================================
  11. using System;
  12. using System.Data;
  13. using System.Configuration;
  14. using System.Web;
  15. using System.Web.Security;
  16. using System.Web.UI;
  17. using System.Web.UI.WebControls;
  18. using System.Web.UI.WebControls.WebParts;
  19. using System.Web.UI.HtmlControls;
  20. /// <summary>
  21. /// NewClass 的摘要说明
  22. /// </summary>
  23. public class NewClass
  24. {
  25. public NewClass()
  26. {
  27. //
  28. // TODO: 在此处添加构造函数逻辑
  29. //
  30. }
  31. }

哈哈,是不是很酷呀!赶快个性一下你的代码吧!

这个是扩展参数

上面提供了部分的参数(希望有人继续补充),已经经本人在VS2010下测试,可以通过

模板

程序注释的重要性毋庸置疑,一个大型的项目通常情况下都是几个软件工程师合作出来的成果,假如该项目中的代码注释不全,那会给将来的维护者带来无穷无尽的隐患。

通用的办法是给自己工程里面的函数添加注释——使用宏。

1.打开Visual Studio 2008(2005一样适用)开发工具,单击“工具→宏→新建宏项目”,然后按照步骤建立注释宏,添加如下代码并保存。

2.打开 菜单 –> 工具–>选项 –> 键盘 ,在列表框中选择刚才添加的Macro,然后在 按快捷键中输入快捷键,点击”分配” 。

注释宏的代码如下:

  1. Sub AddFunComment()
  2. Dim DocSel As EnvDTE.TextSelection
  3. DocSel = DTE.ActiveDocument.Selection
  4. DocSel.NewLine()
  5. DocSel.Text = ""
  6. End Sub

宏代码示例2:

  1. Option Explicit Off
  2. Option Strict Off
  3. Imports System
  4. Imports EnvDTE
  5. Imports EnvDTE80
  6. Imports EnvDTE90
  7. Imports EnvDTE90a
  8. Imports EnvDTE100
  9. Imports System.Diagnostics
  10. Imports VSLangProj
  11. Imports System.IO
  12. Imports System.Text
  13. Imports System.Collections.Generic
  14. Imports System.Runtime.InteropServices
  15. Imports System.Windows.Forms
  16.  
  17. Public Module ModuleName
  18. 'You can just define the variable
  19. Dim document As Document = DTE.ActiveDocument
  20. Dim selection As TextSelection = DTE.ActiveDocument.Selection
  21. Dim headerText As String
  22. Dim filename As String = document.Name
  23. Dim pathname As String = document.Path.ToString()
  24. Dim projectname As String = document.ProjectItem.ContainingProject.Name
  25. Public Sub AddFileHeader()
  26. Try
  27. 'Must set value again because there is singleton module instance
  28. document = DTE.ActiveDocument
  29. selection = DTE.ActiveDocument.Selection
  30. filename = document.Name
  31. pathname = document.Path.ToString()
  32. projectname = document.ProjectItem.ContainingProject.Name
  33. selection.StartOfDocument()
  34. 'deleteExistComment()
  35. insertComment()
  36. Finally
  37. Application.DoEvents()
  38. End Try
  39. End Sub
  40. Private Sub deleteExistComment()
  41. selection.StartOfDocument()
  42. DTE.ExecuteCommand("Edit.Find")
  43. DTE.Windows.Item(filename).Activate()
  44. DTE.Find.FindWhat = "using system"
  45. DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
  46. DTE.Find.MatchCase = False
  47. DTE.Find.MatchWholeWord = False
  48. DTE.Find.Backwards = False
  49. DTE.Find.MatchInHiddenText = True
  50. DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxLiteral
  51. DTE.Find.Action = vsFindAction.vsFindActionFind
  52. If (DTE.Find.Execute() = vsFindResult.vsFindResultNotFound) Then
  53. Return
  54. End If
  55. DTE.Windows.Item(filename).Activate()
  56. DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn)
  57. DTE.ActiveDocument.Selection.LineUp(True, )
  58. DTE.ActiveDocument.Selection.Delete()
  59. DTE.Windows.Item("{CF2DDC32-8CAD-11D2-9302-005345000000}").Close()
  60. End Sub
  61. Private Sub insertComment()
  62. 'selection.StartOfDocument()
  63. selection.Insert("#region (C) Header Region @ " + Date.Today.Year.ToString())
  64. selection.NewLine()
  65. selection.Insert("//==============================================================")
  66. selection.NewLine()
  67. selection.Insert("//")
  68. selection.NewLine()
  69. selection.Insert("// The Herder Region@ " + Date.Today.Year.ToString())
  70. selection.NewLine()
  71. selection.Insert("// Copyright (C) 2010 - " + Date.Today.Year.ToString() + ". All rights reserved.")
  72. selection.NewLine()
  73. selection.Insert("//")
  74. selection.NewLine()
  75. selection.Insert("//")
  76. selection.NewLine()
  77. selection.Insert("// File:")
  78. selection.NewLine()
  79. selection.Insert("// " + filename)
  80. selection.NewLine()
  81. selection.Insert("//")
  82. selection.NewLine()
  83. selection.Insert("// Description: Why do you create this file ")
  84. selection.NewLine()
  85. selection.Insert("//")
  86. selection.NewLine()
  87. selection.Insert("//==============================================================")
  88. selection.NewLine()
  89. selection.Insert("//")
  90. selection.NewLine()
  91. selection.Insert("// $History: " + document.FullName.Substring(document.FullName.IndexOf(":") + ) + " $")
  92. selection.NewLine()
  93. selection.Insert("//")
  94. selection.NewLine()
  95. selection.Insert("// ****************** Version 1 ******************")
  96. selection.NewLine()
  97. selection.Insert("// User: Who Time : " + Date.Now.ToLocalTime().ToString())
  98. selection.NewLine()
  99. selection.Insert("// Updated in: " + projectname + " Project ")
  100. selection.NewLine()
  101. selection.Insert("// Comments: What do you want to do ")
  102. selection.NewLine()
  103. selection.Insert("// ")
  104. selection.NewLine()
  105. selection.NewLine()
  106. selection.Insert("#endregion")
  107. selection.NewLine()
  108. selection.NewLine()
  109. End Sub
  110. End Module
  111.  
  112. ================================================================

创建过程:

1. 新建Macro工程

打开 菜单 -->工具--> 宏 --> 新建宏项目...,根据向导提示建立工程。

2. 编辑Macro工程

打开 菜单 -->工具--> 宏 -->宏资源管理器 ,在红资源管理器中选择新建的工程,修改Module名(右键),在Module名上双击,在打开的Macro IDE中进行编辑。

3. 在Module下,添加要实现的Macro,并实现(内容为下面的代码)。

4. 保存

5.在VS2008中,双击添加的Macro,将执行对应的Macro代码。

6. 建立快捷键

打开 菜单 --> 工具-->选项 --> 键盘 ,在列表框中选择刚才添加的Macro,然后在 按快捷键中输入快捷键,点击"分配" 。

7. 这时候,就可以直接使用快捷键来执行Macro 。

代码实现如下:

  1. Imports System
  2. Imports EnvDTE
  3. Imports EnvDTE80
  4. Imports EnvDTE90
  5. Imports System.Diagnostics
  6. '
  7. Public Module CMonitor
  8. Private Function Copyright()
  9. Copyright = CStr(Date.Today.Year) + "科技 All right reserved"
  10. End Function
  11. Private Function EMailAddress()
  12. EMailAddress = "tangxingqt@163.com"
  13. End Function
  14. Private Function AuthorName()
  15. AuthorName = "兴---"
  16. End Function
  17. Function ProductName()
  18. ProductName = ""
  19. End Function
  20. Private Function GenGUIDString() As String
  21. Dim sGUID As String
  22. sGUID = System.Guid.NewGuid.ToString()
  23. sGUID = UCase(sGUID.Replace("-", "_"))
  24. GenGUIDString = sGUID
  25. End Function
  26. Private Function FileString(ByVal filename As String) As String
  27. FileString = UCase(filename.Replace(".", "_"))
  28. UCase(Left(ActiveDocument.Name, Len(ActiveDocument.Name) - ))
  29. End Function
  30. Sub HeaderFileTemplate()
  31. If ActiveDocument.Language = EnvDTE.Constants.dsCPP Then ' C++
  32. If UCase(Right(ActiveDocument.Name, )) = ".H" Then '头文件
  33. Dim sGUID = GenGUIDString()
  34. Dim sFile = FileString(ActiveDocument.Name)
  35. Dim lens =
  36. Dim strDesc = "" + vbLf + _
  37. "" + vbLf + _
  38. "" + vbLf + _
  39. "" + vbLf + _
  40. "" + vbLf + _
  41. "" + vbLf + _
  42. "" + vbLf + _
  43. "" + vbLf + _
  44. "" + vbLf + _
  45. "" + vbLf + _
  46. "" + vbLf + _
  47. "" + vbLf + _
  48. ActiveDocument.Selection.StartOfDocument()
  49. ActiveDocument.Selection.text() = strDesc
  50. End If
  51. End If
  52. End Sub
  53. Sub ImplFileTemplate()
  54. If ActiveDocument.Language = EnvDTE.Constants.dsCPP Then ' C++
  55. Dim format1 = UCase(Right(ActiveDocument.Name, ))
  56. Dim format2 = UCase(Right(ActiveDocument.Name, ))
  57. If format1 = ".C" Or format2 = ".CPP" Or format2 = ".CXX" Then '实现文件
  58. Dim Descr = "" + vbLf + _
  59. "" + vbLf + _
  60. "" + vbLf + _
  61. "" + vbLf + _
  62. "" + vbLf + _
  63. "" + vbLf + _
  64. "" + vbLf + _
  65. "" + vbLf + _
  66. "" + vbLf + _
  67. "" + vbLf + _
  68. "" + vbLf + _
  69. "" + vbLf + _
  70. "" + vbLf
  71. ActiveDocument.Selection.StartOfDocument()
  72. ActiveDocument.Selection.text = Descr
  73. End If
  74. End If
  75. End Sub
  76. Dim ParamArr()
  77. Function StripTabs(ByVal MyStr)
  78. Do While InStr(MyStr, vbTab) <>
  79. MyStr = Right(MyStr, Len(MyStr) - InStr(MyStr, vbTab))
  80. Loop
  81. StripTabs = Trim(MyStr)
  82. End Function
  83. Sub FunctionDesc()
  84. Dim retTp
  85. Dim Reti
  86. If ActiveDocument.Language = EnvDTE.Constants.dsCPP Then ' C++
  87. Dim Header = Trim(ActiveDocument.Selection.text)
  88. 'Get the function return type.
  89. If Header <> "" Then
  90. Reti = InStr(Header, " ")
  91. Dim Loc = InStr(Header, "(")
  92. If Reti < Loc Then
  93. retTp = StripTabs(Left(Header, Reti))
  94. Header = Right(Header, Len(Header) - Reti)
  95. End If
  96. 'Get the function name.
  97. Loc = InStr(Header, "(") -
  98. Dim Loc2 = InStr(Header, ")")
  99. If Loc > And Loc2 > Then 'make sure there is a '(' and a ')'
  100. Dim fcName = Left(Header, Loc)
  101. Header = Right(Header, Len(Header) - Len(fcName))
  102. 'Do we have storage type on the return type?
  103. Trim(fcName)
  104. If InStr(fcName, " ") <> Then
  105. retTp = retTp + Left(fcName, InStr(fcName, " "))
  106. fcName = Right(fcName, Len(fcName) - InStr(fcName, " "))
  107. End If
  108. 'Get the function parameters.
  109. Dim iPrm =
  110. Dim iPrmA =
  111. Dim prms = Header
  112. 'Count the number of parameters.
  113. Do While InStr(prms, ",") <>
  114. iPrm = iPrm +
  115. prms = Right(prms, Len(prms) - InStr(prms, ","))
  116. Loop
  117. 'Store the parameter list in the array.
  118. If iPrm > Then ' If multiple params.
  119. iPrm = iPrm +
  120. iPrmA = iPrm
  121. ReDim ParamArr(iPrm)
  122. Do While InStr(Header, ",") <>
  123. ParamArr(iPrm) = Left(Header, InStr(Header, ",") - )
  124. 'Remove brace from first parameter.
  125. If InStr(ParamArr(iPrm), " (") <> Then
  126. ParamArr(iPrm) = Right(ParamArr(iPrm), _
  127. Len(ParamArr(iPrm)) - InStr(ParamArr(iPrm), " ("))
  128. Trim(ParamArr(iPrm))
  129. End If
  130. Header = Right(Header, Len(Header) - InStr(Header, ","))
  131. iPrm = iPrm -
  132. Loop
  133. ParamArr(iPrm) = Header
  134. 'Remove trailing brace from last parameter.
  135. If InStr(ParamArr(iPrm), ")") <> Then
  136. ParamArr(iPrm) = Left(ParamArr(iPrm), _
  137. InStr(ParamArr(iPrm), ")") - )
  138. Trim(ParamArr(iPrm))
  139. End If
  140. Else 'Possibly one param.
  141. ReDim ParamArr()
  142. Header = Right(Header, Len(Header) - ) ' Strip the first brace.
  143. Trim(Header)
  144. ParamArr() = StripTabs(Header)
  145. If InStr(ParamArr(), ")") <> Then
  146. ParamArr() = Left(ParamArr(), InStr(ParamArr(), ")") - )
  147. Trim(ParamArr())
  148. iPrmA =
  149. End If
  150. End If
  151. 'Position the cursor one line above the selected text.
  152. ActiveDocument.Selection.LineUp()
  153. ActiveDocument.Selection.LineDown()
  154. ActiveDocument.Selection.StartOfLine()
  155. 'ActiveDocument.Selection = vbLf
  156. Dim Descr = "" + vbLf
  157. ActiveDocument.Selection.text = Descr
  158. End If
  159. End If
  160. End If
  161. End Sub
  162.  
  163. End Module

参数

描述

clrversion

当前系统CLR版本号

GUID [1-10]

生成全局唯一标识符,可以生成10个 (例如:guid1)

itemname

打开添加新建项时输入的文件名称

machinename

当前机器的名称(如:pc1)

registeredorganization

注册的组织名

rootnamespace

命名空间名

safeitemname

保存的文件名

time

当前系统时间,格式:DD/MM/YYYY 00:00:00.

userdomain

用户所在的域

username

当前系统用户名

year

当前系统时间 YYYY

参数

描述

clrversion

当前系统CLR版本号

GUID [1-10]

生成全局唯一标识符,可以生成10个 (例如:guid1)

itemname

打开添加新建项时输入的文件名称

machinename

当前机器的名称(如:pc1)

registeredorganization

注册的组织名

rootnamespace

命名空间名

safeitemname

保存的文件名

time

当前系统时间,格式:DD/MM/YYYY 00:00:00.

userdomain

用户所在的域

username

当前系统用户名

year

当前系统时间 YYYY

VS 自动添加注释的更多相关文章

  1. PowerDesigner 如何添加每个表中共用的字段及自动添加注释

    PowerDesigner 如何添加每个表中共用的字段: 有时候在创建表的时候会有一些共用的字段,但是每一张表都要去创建,这样做很麻烦,特别是这样重复的工作,稍不留意就会出现问题,实际上在PD中有这样 ...

  2. vs 文件头自动添加注释

    原文:vs 文件头自动添加注释 vs2010 C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates ...

  3. (转)Eclipse中自动添加注释(作者,时间)

    方法一:Eclipse中设置在创建新类时自动生成注释  windows-->preference  Java-->Code Style-->Code Templates  code- ...

  4. Unity脚本自动添加注释脚本及排版格式

    Unity脚本自动添加注释脚本及头部注释排版格式 公司开发项目,需要声明版权所有,,,,标注公司名,作者,时间,项目名称及描述等等. 自己总结实现的现成脚本及头部注释排版文本,添加到模版即可. 文件不 ...

  5. eclipse自动添加注释

    自动添加注释 快捷键:alt shift jwindows-->preference Java-->Code Style-->Code Templates code-->new ...

  6. 【Eclipse】如何在Eclipse中如何自动添加注释和自定义注释风格

    背景简介 丰富的注释和良好的代码规范,对于代码的阅读性和可维护性起着至关重要的作用.几乎每个公司对这的要求还是比较严格的,往往会形成自己的一套编码规范.但是再实施过程中,如果全靠手动完成,不仅效率低下 ...

  7. python基础===monkeytype可以自动添加注释的模块!

    monkeytype 一个可以自动添加注释的模块! 先要下载: pip install monkeytype 以官网的sample code为例 #moudle.py def add(a, b): r ...

  8. 如何在Eclipse中如何自动添加注释和自定义注释风格

    1. 如何自动添加注释 可通过如下三种方法自动添加注释: (1)输入“/**”并回车. (2)用快捷键 Alt+Shift+J(先选中某个方法.类名或变量名). (3)在右键菜单中选择“Source ...

  9. Idea_学习_05_Intellij Idea自动添加注释的方法

    二.参考资料 1. Intellij Idea自动添加注释的方法

  10. [转]Intellij Idea自动添加注释的方法

    Intellij Idea自动添加注释的方法 阿历Ali 关注 2017.08.20 21:22* 字数 914 阅读 2741评论 0喜欢 6 程序媛阿历终于要写第一篇关于开发的文章了!!! 阿历用 ...

随机推荐

  1. hrbust1841再就业(状态压缩dp)

    本人刚学压缩dp,只能对这些水题写题解 一方面对自己的理解有加深作用 另一方面希望和各位大牛交流交流..... 如果有对状态dp不太了解的童鞋可以参考入门知识:http://wenku.baidu.c ...

  2. WinForm中MouseEnter和MouseLeave混乱的问题

    MouseEnter+MouseLeave不行,我用了MouseMove+MouseLeave,效果一样 最近做个聊天的系统,仿照qq的界面设计,像qq聊天界面中字体.表情.截图等图片,鼠标放上去显示 ...

  3. appium 常用API

    ''.appium api第二弹 锋利的python,这是初稿,2015/1/5 如有错误的地方,请同学们进行留言,我会及时予以修改,尽量整合一份ok的api 作者:Mads Spiral QQ:79 ...

  4. git pull 然后 ahead of origin/master * commit 消失

    本来显示 your branch is ahead origin/master * commit后来也许在master merge 这个分支后, 然后git pull, 就显示Your branch ...

  5. grep 使用或条件 ( grep -e )

    test@k1rhel5822161:/home/test>cat 31 52 33 24567test@k1rhel5822161:/home/test>grep -e '2|3' 3t ...

  6. javascrpt事件

    1.HTML事件处理程序:就是事件直接写在HTML文档中,其特点就是HTML和Js紧密的结合在一起,缺点就是修改不方便,需要改动js和HTML两处.比如: <button onclick=&qu ...

  7. Linux下怎么删除非空目录

    rm -rf 目录名 解释: 1.r意思是删除目录,f意思是force的缩写,强制删除,不提示. 2.如果目录为空,可以用 "rmdir 目录名"删除. 3.如果目录不为空,可以用 ...

  8. PE文件学习系列三-PE头详解

    合肥程序员群:49313181.    合肥实名程序员群:128131462 (不愿透露姓名和信息者勿加入) Q  Q:408365330     E-Mail:egojit@qq.com 最近比较忙 ...

  9. IE兼容问题,各类css hack代码(亲测有效)

    现在大部分企业对浏览器兼容要求是IE7+或者IE8+,要求IE6的很少,此处一并写出. IE6: _margin-top: 20px; IE6+IE7: *margin-top: 20px; +mar ...

  10. CentOS 7 配置静态IP

    1.查看MAC地址 2.修改/etc/sysconfig/network-scripts/ifcfg-[第一步中红框内的文字] 3.添加和修改内容如下: 4.修改/etc/resolv.conf 5. ...