• 为类和函数代码自动添加版权注释信息


    以web项目为例:

    一:给类加注释

    1.在visual studio 的安装路径下

            如:[盘符]:/Program files/Microsoft Visual Studio 8/Common7/IDE/ItemTemplates/web/cshare/2052/class.zip ,将里面的class.cs改为:

    C#代码 复制代码
    1. /*----------------------------------------------------------------  
    2. // Copyright (C) 2010  杰赛通信规划设计院  
    3. // 版权所有。   
    4. //  
    5. // 文件名:  
    6. // 文件功能描述:  
    7. //  
    8. //   
    9. // 创建标识:  
    10. //  
    11. // 修改标识:  
    12. // 修改描述:  
    13. //  
    14. // 修改标识:  
    15. // 修改描述:  
    16. //----------------------------------------------------------------*/    
    17. using System;   
    18. using System.Data;   
    19. using System.Configuration;   
    20. using System.Web;   
    21. using System.Web.Security;   
    22. using System.Web.UI;   
    23. using System.Web.UI.WebControls;   
    24. using System.Web.UI.WebControls.WebParts;   
    25. using System.Web.UI.HtmlControls;   
    26.   
    27. /// <summary>   
    28. /// $safeitemrootname$ 的摘要说明   
    29. /// </summary>   
    30. public class $safeitemrootname$   
    31. {   
    32.     public $safeitemrootname$()   
    33.     {   
    34.         //   
    35.         // TODO: 在此处添加构造函数逻辑   
    36.         //   
    37.     }   
    38. }  
    [c#] view plaincopy
     
    1. /*---------------------------------------------------------------- 
    2. // Copyright (C) 2010  杰赛通信规划设计院 
    3. // 版权所有。  
    4. // 
    5. // 文件名: 
    6. // 文件功能描述: 
    7. // 
    8. //  
    9. // 创建标识: 
    10. // 
    11. // 修改标识: 
    12. // 修改描述: 
    13. // 
    14. // 修改标识: 
    15. // 修改描述: 
    16. //----------------------------------------------------------------*/   
    17. using System;  
    18. using System.Data;  
    19. using System.Configuration;  
    20. using System.Web;  
    21. using System.Web.Security;  
    22. using System.Web.UI;  
    23. using System.Web.UI.WebControls;  
    24. using System.Web.UI.WebControls.WebParts;  
    25. using System.Web.UI.HtmlControls;  
    26.   
    27. /// <summary>  
    28. /// $safeitemrootname$ 的摘要说明  
    29. /// </summary>  
    30. public class $safeitemrootname$  
    31. {  
    32.     public $safeitemrootname$()  
    33.     {  
    34.         //  
    35.         // TODO: 在此处添加构造函数逻辑  
    36.         //  
    37.     }  
    38. }  

    保存文件即可(先解压,在修改)

    二:VS宏脚本添加函数注释模板 现在的IDE越做越强大,为我等懒人省了不少。为了使用将来的代码自己或别人能看懂,注释这种东西必不可少。当为函数添加注释时,格式是固定的。每个函数写一遍,或从别的函数处拷贝过来,即麻烦又容易出错。这种重复劳动让人心烦都有不想写注释的欲望了,这时VS的宏可以干掉这些“脏、乱、累”的体力活。

    看了一下,vs2010的宏脚本就是VBScript,很容易上手。我写了一个生成函数注释模板的宏脚本,比较容易,看代码:

    1. Imports System   
    2. Imports EnvDTE   
    3. Imports EnvDTE80   
    4. Imports EnvDTE90   
    5. Imports System.Diagnostics   
    6.   
    7. Public Module Module1   
    8.     Sub AddFunComment()   
    9.         Dim DocSel As EnvDTE.TextSelection   
    10.         DocSel = DTE.ActiveDocument.Selection   
    11.         DocSel.NewLine()   
    12.         DocSel.Text = "/*******************************************************************"  
    13.         DocSel.NewLine()   
    14.         DocSel.Text = "* 函数名称: "  
    15.         DocSel.NewLine()   
    16.         DocSel.Text = "* 功    能: "  
    17.         DocSel.NewLine()   
    18.         DocSel.Text = "* 参    数: "  
    19.         DocSel.NewLine()   
    20.         DocSel.Text = "* 返 回 值: "  
    21.         DocSel.NewLine()   
    22.         DocSel.Text = "* 作    者: Lonkil"  
    23.         DocSel.NewLine()   
    24.         DocSel.Text = "* 电子邮箱: lonkil{AT}gmail.com ( {AT} -> @ )"  
    25.         DocSel.NewLine()   
    26.         DocSel.Text = "* 创建日期: " + System.DateTime.Now.ToLongDateString()   
    27.         DocSel.NewLine()   
    28.         DocSel.Text = "*******************************************************************/"  
    29.     End Sub   
    30. End Module  
    [java] view plaincopy
     
    1. Imports System  
    2. Imports EnvDTE  
    3. Imports EnvDTE80  
    4. Imports EnvDTE90  
    5. Imports System.Diagnostics  
    6.   
    7. Public Module Module1  
    8.     Sub AddFunComment()  
    9.         Dim DocSel As EnvDTE.TextSelection  
    10.         DocSel = DTE.ActiveDocument.Selection  
    11.         DocSel.NewLine()  
    12.         DocSel.Text = "/*******************************************************************"  
    13.         DocSel.NewLine()  
    14.         DocSel.Text = "* 函数名称: "  
    15.         DocSel.NewLine()  
    16.         DocSel.Text = "* 功    能: "  
    17.         DocSel.NewLine()  
    18.         DocSel.Text = "* 参    数: "  
    19.         DocSel.NewLine()  
    20.         DocSel.Text = "* 返 回 值: "  
    21.         DocSel.NewLine()  
    22.         DocSel.Text = "* 作    者: Lonkil"  
    23.         DocSel.NewLine()  
    24.         DocSel.Text = "* 电子邮箱: lonkil{AT}gmail.com ( {AT} -> @ )"  
    25.         DocSel.NewLine()  
    26.         DocSel.Text = "* 创建日期: " + System.DateTime.Now.ToLongDateString()  
    27.         DocSel.NewLine()  
    28.         DocSel.Text = "*******************************************************************/"  
    29.     End Sub  
    30. End Module  

    具体的创建步骤:vs2010 IDE -> 工具 -> 宏 -> 新建宏项目,选择要保存的位置。然后将要上面的脚本复制进去,保存即可。

    具体的使用:为你编写的宏绑定快捷键,vs2010 IDE -> 工具 -> 选项 -> 在左边列表中选择“键盘” -> 在右边的“显示命令包含”中,选择你创建宏-> 将光标定位到”按快捷键”处 -> 输入你想命名的快捷键,比如”Alt+C”,保存即可。

    有一点需要注意:Visual Studio 2005 Team Suite 需要打上SP1补丁,宏方能使用否则无效。

  • 相关阅读:
    王爽《汇编语言》第三版 第一章 基础知识
    JAVA拷贝视频文件无法播放的解决方法
    算法导论 第2章 算法基础
    今天来个爪哇去边框的小代码
    设计模式_Adapt
    qs面试记录
    zl面试记录
    pa_ns2面试记录
    pa_ns1面试总结
    sfjc面试记录
  • 原文地址:https://www.cnblogs.com/gc2013/p/3967689.html
Copyright © 2020-2023  润新知