Visual Studio 2012中的为创建类时的添加注释模板

来源:互联网 发布:易云捷讯数据库 编辑:程序博客网 时间:2024/06/05 14:25
,我们往往需要给类添加注释,我们可以把注释块复制出来,放到文件中,然后在需要的时候,复制、粘贴。这样的重复劳动增加了程序员的体力劳动,而VS中给我们提供了项模版,我们只需要在其中修改一点点模版就能达到这样的效果。

首先,找到类模版的位置:C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplates\CSharp\Code\2052\Class,打开Class.cs,为其添加头注释:

 1  /* ============================================================================== 2   * 类名称:$safeitemrootname$ 3   * 类描述: 4   * 创建人:$username$ 5   * 创建时间:$time$ 6   * 修改人: 7   * 修改时间: 8   * 修改备注: 9   * @version 1.010   * ==============================================================================*/11 using System;12 using System.Collections.Generic;13 $if$ ($targetframeworkversion$ >= 3.5)using System.Linq;14 $endif$using System.Text;15 $if$ ($targetframeworkversion$ >= 4.5)using System.Threading.Tasks;16 $endif$17 namespace $rootnamespace$18 {19     /// <summary>20     /// $safeitemrootname$21     /// </summary>22     public class $safeitemrootname$23     {24     }25 }

这里的$safeitemrootname$和$username$是由系统提供给我们的,还有一些其他参数:

参数  说明 

clrversion 公共语言运行库 (CLR) 的当前版本。itemname 用户在添加新项对话框中提供的名称。machinename 当前的计算机名称(例如,Computer01)。projectname 用户在新建项目对话框中提供的名称。registeredorganization HKLM\Software\Microsoft\Windows NT\CurrentVersion\RegisteredOrganization 中的注册表项值。rootnamespace 当前项目的根命名空间。此参数用于替换正向项目中添加的项中的命名空间。safeitemname 用户在“添加新项”对话框中提供的名称,名称中移除了所有不安全的字符和空格。safeprojectname 用户在“新建项目”对话框中提供的名称,名称中移除了所有不安全的字符和空格。time 以 DD
/MM/YYYY 00:00:00 格式表示的当前时间。userdomain 当前的用户域。username 当前的用户名。year 以 YYYY 格式表示的当前年份。

保存之后,新建一个类,就会得到如下效果:

 1 /* ============================================================================== 2  * 类名称:TestClass 3  * 类描述: 4  * 创建人:better.chaner 5  * 创建时间:2013/2/17 17:57:03 6  * 修改人: 7  * 修改时间: 8  * 修改备注: 9  * @version 1.010  * ==============================================================================*/11 using System;12 using System.Collections.Generic;13 using System.Linq;14 using System.Text;15 using System.Threading.Tasks;16 17 namespace test.NewFolder118 {19     /// <summary>20     /// TestClass21     /// </summary>22     public class TestClass23     {24     }25 }

 


<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>