Visual Studio中的新建类时的注释模板

来源:互联网 发布:linux dns原理 编辑:程序博客网 时间:2024/05/20 22:04

  在程序开发过程中,新建一个类的时候,我们往往需要给类添加注释,我们可以把注释块复制出来,放到文件中,然后在需要的时候,复制、粘贴。这样的重复劳动增加了程序员的体力劳动,而VS中给我们提供了项模版,我们只需要在其中修改一点点模版就能达到这样的效果。

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

 /* ============================================================================== * 类名称:$safeitemrootname$ * 类描述: * 创建人:$username$ * 创建时间:$time$ * 修改人: * 修改时间: * 修改备注: * @version 1.0 * ==============================================================================*/ using System; using System.Collections.Generic; $if$ ($targetframeworkversion$ >= 3.5)using System.Linq; $endif$using System.Text; $if$ ($targetframeworkversion$ >= 4.5)using System.Threading.Tasks; $endif$ namespace $rootnamespace$ {    /// <summary>    /// $safeitemrootname$    /// </summary>    public class $safeitemrootname$    {     } }

这里的$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 格式表示的当前年份。
保存之后,新建一个类,就会得到效果。

原创粉丝点击