• [转]让你的Visual Studio 2010自动添加头部注释信息


    本文转自:http://www.cnblogs.com/weisenz/archive/2012/03/29/2423326.html#2430065

    在日常的开发中我们经常需要为我们的类库添加注释和版权等信息,这样我们就需要每次去拷贝粘贴同样的文字,为了减少这种重复性的工作,我们可以把这些信息保存在Visual Studio 2010类库模版文件里。

    首先找到Visual Studio 2010的安装路径下\Common7\IDE\ItemTemplatesCache\CSharp\目录,如图:

    里面有好多目录,Windows Forms是开发Windows Forms程序的模版目录,Web是Web项目文件的模版目录,其他的同理。进入Web目录有选择2052目录(2052是中文地区的代号)下,会看到好多带有.zip的目录,比如我要修改web页面的模版,就修改\WebForm.zip\Default.aspx.cs,打开Default.aspx.cs会看到如下内容。

    复制代码
     1 using System;
    2 using System.Collections.Generic;
    3 $if$ ($targetframeworkversion$ >= 3.5)using System.Linq;$endif$
    4 using System.Web;
    5 using System.Web.UI;
    6 using System.Web.UI.WebControls;
    7
    8 namespace $rootnamespace$
    9 {
    10 public partial class $classname$ : System.Web.UI.Page
    11 {
    12 protected void Page_Load(object sender, EventArgs e)
    13 {
    14
    15 }
    16 }
    17 }
    复制代码

    代码中的"$"符号之间的字符是模版的变量,具体变量含义请参照:

    复制代码
    $time$     日期

    $year$ 年份

    $clrversion$ CLR版本

    $GUID$ 用于替换项目文件中的项目 GUID 的 GUID。最多可以指定 10 个唯一的 GUID(例如,guid1))。

    $itemname$ 用户在对话框中提供的名称。

    $machinename$ 当前的计算机名称(例如,Computer01)。

    $projectname$ 用户在对话框中提供的名称。

    $registeredorganization$ HKLM\Software\Microsoft\Windows NT\CurrentVersion\RegisteredOrganization 中的注册表项值。

    $rootnamespace$ 当前项目的根命名空间。此参数用于替换正向项目中添加的项中的命名空间。

    $safeitemname$ 用户在“添加新项”对话框中提供的名称,名称中移除了所有不安全的字符和空格。

    $safeprojectname$ 用户在“新建项目”对话框中提供的名称,名称中移除了所有不安全的字符和空格。

    $time$ 以 DD/MM/YYYY 00:00:00 格式表示的当前时间。

    $userdomain$ 当前的用户域。

    $username$ 当前的用户名。
    复制代码

    下面是我写注释的格式,那我们就按照这个格式做一个模版。

    复制代码
     1 // ===============================================================================
    2 // Project Name : Weisenz.Core
    3 // Project Description :
    4 // ===============================================================================
    5 // Class Name : HttpModule
    6 // Class Version : v1.0.0.0
    7 // Class Description :
    8 // Author : Charles
    9 // Create Time : 2012/3/29 13:19:28
    10 // Update Time : 2012/3/29 13:19:28
    11 // ===============================================================================
    12 // Copyright © Weisenz 2012 . All rights reserved.
    13 // ===============================================================================
    复制代码

    首先在对应的地方替换成自己需要使用的变量。

    复制代码
     1 // ===============================================================================
    2 // Project Name : $rootnamespace$
    3 // Project Description :
    4 // ===============================================================================
    5 // Class Name : $safeitemrootname$
    6 // Class Version : v1.0.0.0
    7 // Class Description :
    8 // Author : $username$
    9 // Create Time : $time$
    10 // Update Time : $time$
    11 // ===============================================================================
    12 // Copyright © $machinename$ $year$ . All rights reserved.
    13 // ===============================================================================
    复制代码

    最后把上面的文本添加到Default.aspx.cs的最前面就行了。

    看下我的最终成果:

    复制代码
     1 // ===============================================================================
    2 // Project Name : Weisenz.Web
    3 // Project Description :
    4 // ===============================================================================
    5 // Class Name : Services
    6 // Class Version : v1.0.0.0
    7 // Class Description :
    8 // Author : Charles
    9 // Create Time : 2012/3/29 13:38:53
    10 // Update Time : 2012/3/29 13:38:53
    11 // ===============================================================================
    12 // Copyright © Weisenz 2012 . All rights reserved.
    13 // ===============================================================================
    14 using System;
    15 using System.Collections.Generic;
    16
    17 using System.Web;
    18 using System.Web.UI;
    19 using System.Web.UI.WebControls;
    20
    21 namespace Weisenz.Web
    22 {
    23 public partial class Services : System.Web.UI.Page
    24 {
    25 protected void Page_Load(object sender, EventArgs e)
    26 {
    27
    28 }
    29 }
    30 }
    复制代码

    如需修改其他的就按照上面的步骤找到对应的文件夹就行了。

  • 相关阅读:
    googleMap JsAPI
    格式化Json代码
    baidu map JSAPI
    ajaxFileUpload与KindEditor
    Intent 意图
    初识Android
    Android环境搭建
    Android入门知识梳理
    网页版计算器
    使用socket实现简单的聊天功能
  • 原文地址:https://www.cnblogs.com/freeliver54/p/2703350.html
Copyright © 2020-2023  润新知