Visual Studio 2012中的為創建類時的添加注釋模板


  在程序開發過程中,新建一個類的時候,我們往往需要給類添加注釋,我們可以把注釋塊復制出來,放到文件中,然后在需要的時候,復制、粘貼。這樣的重復勞動增加了程序員的體力勞動,而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.0
10   * ==============================================================================*/
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.0
10  * ==============================================================================*/
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.NewFolder1
18 {
19     /// <summary>
20     /// TestClass
21     /// </summary>
22     public class TestClass
23     {
24     }
25 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM