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 development of Windows Forms.ProgramThe Web is the template directory of the web project file. 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 ){}}}
CodeThe characters between the "$" symbols in Are Template variables. For more information about the variables, see:
Time $ date $ year $ clrversion $ CLR version $ guid $ Replace the guid of the project 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.
My annotation example:
/*************************************** * ********************************** Project name: work log system * Project Description: * Class Name: userinfo * version number: v1.0.0.0 * Description: User information management class * Author: Ling Yu drifting * Creation Time: 13:19:28 * updated on: 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. **************************************** ********************************/
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 ){}}}
Generated file:
/*************************************** * ********************************** Project name: work log system * Project Description: * Class Name: default2 * version No.: v1.0.0.0 * Description: * OPERATOR: Ling Yu drifting * Creation Time: 14:26:49 * Update Time: 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 ){}}
Modify Other templates as described above.