In the daily development process, we often need to add comments, copyrights, and other information to our class files. In the past, we copied and pasted the information text. If we added one or two pieces of information, it is very troublesome to add a lot. Is there a good solution to reduce this repetitive work? The answer is yes. In fact, each file we add is automatically generated according to the class library template, so you only need to modify the class library template of Visual Studio.
First, find the \ common7 \ ide \ itemtemplatescache \ CSHARP \ directory under the installation path of Visual Studio (2005, 2008, 2010). There are many directories on it, windows forms is the template directory for developing Windows Forms programs, and Web is the template directory for web project files. Go to the web directory and select "2052" ("2052" is the Chinese directory. Many directories with .zip are displayed. For example, to modify the template on the web page, modify "\ webform.zip \ default. aspx. cs" and open "default. aspx. cs.
- Using system;
- Using system. Collections. Generic;
- $ If $ ($ targetframeworkversion $ == 3.5) using system. LINQ;
- $ Endif $ using system. Web;
- Using system. Web. UI;
- Using system. Web. UI. webcontrols;
-
- Namespace $ rootnamespace $
- {
- Public partial class $ classname $: system. Web. UI. Page
- {
- Protected void page_load (Object sender, eventargs E)
- {
-
- }
- }
- }
The characters between the "$" symbols in the Code are template variables. For more information about the variables, see:
- <Strong> time $ date
-
- $ Year
-
- $ Clrversion $ CLR version
-
- $ Guid $ The GUID used to replace the project guid in the project file. You can specify up to 10 unique guid1 guids )).
-
- $ Itemname $ name provided by the user in the dialog box.
-
- $ Machinename $ name of the current computer (for example, computer01 ).
-
- $ Projectname $ name provided by the user in the dialog box.
-
- $ Registeredorganization $ registry key value in HKLM \ Software \ Microsoft \ Windows NT \ CurrentVersion \ registeredorganization.
-
- $ Rootnamespace $ root namespace of the current project. This parameter is used to replace the namespace in the items added to the forward project.
-
- $ Safeitemname $ name provided by the user in the "Add new item" dialog box, excluding all unsafe characters and spaces.
-
- $ Safeprojectname $ name provided by the user in the "New Project" dialog box, excluding all unsafe characters and spaces.
-
- $ Time $ the current time in the format of DD/MM/YYYY 00:00:00.
-
- $ Userdomain $ current user domain.
-
- $ Username $ current user name.
-
- </Strong>
My annotation example:
- /*************************************** *********************************
- * Project name: work log system
- * Project description:
- * Class Name: userinfo
- * Version number: v1.0.0.0
- * Description: User Information Management
- * Author: lingyu drifting
- * Creation Time: 13:19:28
- * Updated at: 13:19:28
- **************************************** ********************************
- * Copyright @ Ling Yu studio 2011. All rights reserved.
- **************************************** ********************************/
Follow the above instance design template:
- /*************************************** *********************************
- * Project name: $ rootnamespace $
- * Project description:
- * Class Name: $ safeitemrootname $
- * Version number: v1.0.0.0
- * Description:
- * OPERATOR: $ username $
- * Creation Time: $ time $
- * Update Time: $ time $
- **************************************** ********************************
- * Copyright @ Ling Yu studio $ year $. All rights reserved.
- **************************************** ********************************/
- <PRE class = "CSHARP" name = "code"> using system;
- Using system. Collections. Generic;
- $ If $ ($ targetframeworkversion $ == 3.5) using system. LINQ;
- $ Endif $ using system. Web;
- Using system. Web. UI;
- Using system. Web. UI. webcontrols;
-
- Namespace $ rootnamespace $
- {
- Public partial class $ classname $: system. Web. UI. Page
- {
- Protected void page_load (Object sender, eventargs E)
- {
-
- }
- }
- }
- </PRE>
- <PRE> </PRE>
- <P> <br>
- Generated file: <br>
- </P>
- <PRE class = "CSHARP" name = "code"> /************************** **************************************** ******
- * Project name: work log system
- * Project description:
- * Class Name: default2
- * Version number: v1.0.0.0
- * Description:
- * Author: lingyu drifting
- * Creation Time: 14:26:49
- * Updated on: 14:26:49
- **************************************** ********************************
- * Copyright @ Ling Yu studio 2012. All rights reserved.
- **************************************** ********************************/
- Using system;
- Using system. Collections. Generic;
- Using system. LINQ;
- Using system. Web;
- Using system. Web. UI;
- Using system. Web. UI. webcontrols;
-
- Public partial class default2: system. Web. UI. Page
- {
- Protected void page_load (Object sender, eventargs E)
- {
-
- }
- }
- </PRE>
- <P> </P>
- <P> modify other templates as described above. </P>
- <P> <br>
- </P>
Enable Visual Studio to automatically add header comments